Merge branch 'fix_new_rst_anchors' into 'main'

Fix generated RST anchors for methods, signals and properties

See merge request GNOME/glib!3751
This commit is contained in:
Philip Withnall 2023-12-11 14:19:44 +00:00
commit b014d622ee
2 changed files with 120 additions and 3 deletions

View File

@ -142,7 +142,7 @@ class RstCodeGenerator:
else:
access = "readable"
res += [
".. _{title}:",
f".. _{title}:",
"",
title,
"^" * len(title),
@ -218,7 +218,7 @@ class RstCodeGenerator:
for m in iface.methods:
title = f"{iface.name}.{m.name}"
res += [
".. _{title}:",
f".. _{title}:",
"",
title,
"^" * len(title),
@ -296,7 +296,7 @@ class RstCodeGenerator:
for s in iface.signals:
title = f"{iface.name}::{s.name}"
res += [
".. _{title}:",
f".. _{title}:",
"",
title,
"^" * len(title),

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."""