Skip to content

Commit

Permalink
test: Add test for interface generator from D-Bus connection
Browse files Browse the repository at this point in the history
  • Loading branch information
igo95862 committed Oct 28, 2023
1 parent bd2a259 commit d60ba5f
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions test/test_interface_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,17 @@

from importlib.util import find_spec
from unittest import SkipTest, TestCase, main
from unittest.mock import MagicMock, patch

from sdbus.__main__ import generator_main
from sdbus.interface_generator import (
DbusSigToTyping,
camel_case_to_snake_case,
generate_async_py_file,
interface_name_to_class,
interfaces_from_str,
)
from sdbus.unittest import IsolatedDbusTestCase

test_xml = """
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
Expand Down Expand Up @@ -198,5 +201,34 @@ def test_parsing(self) -> None:
self.assertIn('flags=DbusPropertyConstFlag', generated)


class TestGeneratorAgainstDbus(IsolatedDbusTestCase):
def test_generate_from_connection(self) -> None:
if find_spec('jinja2') is None:
raise SkipTest('Jinja2 not installed')

with patch("sdbus.__main__.stdout") as stdout_mock:
generator_main(
[
"gen-from-connection",
"org.freedesktop.DBus",
"/org/freedesktop/DBus",
]
)

write_mock: MagicMock = stdout_mock.write
write_mock.assert_called_once()

generated_interface = write_mock.call_args.args[0]

self.assertIn(
"OrgFreedesktopDBusDebugStatsInterface",
generated_interface,
)
self.assertIn(
"get_connection_unix_process_id",
generated_interface,
)


if __name__ == "__main__":
main()

0 comments on commit d60ba5f

Please sign in to comment.