tests: Add tests for gdbus-codegen generated RST

Those tests check if methods, signals and properties documentation are
properly generated.
This commit is contained in:
tytan652 2023-12-11 13:45:39 +01:00
parent 9a4e54e1b7
commit 605be9a1e9

View File

@ -520,6 +520,123 @@ G_END_DECLS
rst = f.readlines()
self.assertTrue(len(rst) != 0)
def test_generate_rst_method(self):
"""Test generating a method documentation with the rst generator."""
xml_contents = """
<node>
<interface name="org.project.Bar.Frobnicator">
<!-- RandomMethod:
A random test method.
-->
<method name="RandomMethod"/>
</interface>
</node>
"""
res = self.runCodegenWithInterface(
xml_contents,
"--generate-rst",
"test",
)
self.assertEqual("", res.err)
self.assertEqual("", res.out)
with open("test-org.project.Bar.Frobnicator.rst", "r") as f:
rst = f.read()
self.assertIn("""
-------
Methods
-------
.. _org.project.Bar.Frobnicator.RandomMethod:
org.project.Bar.Frobnicator.RandomMethod
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
::
RandomMethod ()
A random test method.""", rst)
def test_generate_rst_signal(self):
"""Test generating a signal documentation with the rst generator."""
xml_contents = """
<node>
<interface name="org.project.Bar.Frobnicator">
<!-- RandomSignal:
A random test signal.
-->
<signal name="RandomSignal"/>
</interface>
</node>
"""
res = self.runCodegenWithInterface(
xml_contents,
"--generate-rst",
"test",
)
self.assertEqual("", res.err)
self.assertEqual("", res.out)
with open("test-org.project.Bar.Frobnicator.rst", "r") as f:
rst = f.read()
self.assertIn("""
-------
Signals
-------
.. _org.project.Bar.Frobnicator::RandomSignal:
org.project.Bar.Frobnicator::RandomSignal
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
::
RandomSignal ()
A random test signal.""", rst)
def test_generate_rst_property(self):
"""Test generating a property documentation with the rst generator."""
xml_contents = """
<node>
<interface name="org.project.Bar.Frobnicator">
<!-- RandomProperty:
A random test property.
-->
<property type="s" name="RandomProperty" access="read"/>
</interface>
</node>
"""
res = self.runCodegenWithInterface(
xml_contents,
"--generate-rst",
"test",
)
self.assertEqual("", res.err)
self.assertEqual("", res.out)
with open("test-org.project.Bar.Frobnicator.rst", "r") as f:
rst = f.read()
self.assertIn("""
----------
Properties
----------
.. _org.project.Bar.Frobnicator:RandomProperty:
org.project.Bar.Frobnicator:RandomProperty
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
::
RandomProperty readable s
A random test property.""", rst)
@unittest.skipIf(on_win32(), "requires /dev/stdout")
def test_glib_min_required_invalid(self):
"""Test running with an invalid --glib-min-required."""