From a3189ec5c8740a8d0a60c0a5e3e0d7a0f52ab471 Mon Sep 17 00:00:00 2001 From: tytan652 Date: Sat, 9 Dec 2023 15:37:37 +0100 Subject: [PATCH 1/4] Fix generated RST anchors for methods, signals and properties --- gio/gdbus-2.0/codegen/codegen_rst.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gio/gdbus-2.0/codegen/codegen_rst.py b/gio/gdbus-2.0/codegen/codegen_rst.py index 026ad675d..303e547cf 100644 --- a/gio/gdbus-2.0/codegen/codegen_rst.py +++ b/gio/gdbus-2.0/codegen/codegen_rst.py @@ -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), From 4e4471663c56ac795b27face7aca8587f03f24c0 Mon Sep 17 00:00:00 2001 From: tytan652 Date: Mon, 11 Dec 2023 13:45:39 +0100 Subject: [PATCH 2/4] tests: Add tests for gdbus-codegen generated RST Those tests check if methods, signals and properties documentation are properly generated. --- gio/tests/codegen.py | 117 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) diff --git a/gio/tests/codegen.py b/gio/tests/codegen.py index 9fd4321f3..fde551855 100644 --- a/gio/tests/codegen.py +++ b/gio/tests/codegen.py @@ -519,6 +519,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 = """ + + + + + + + """ + 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 = """ + + + + + + + """ + 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 = """ + + + + + + + """ + 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.""" From 737b08e96fb782f6a4fa5ca523d4d23fa9db1d2c Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Mon, 11 Dec 2023 16:52:07 +0000 Subject: [PATCH 3/4] tests: Use textwrap.dedent to indent expected strings pleasingly This introduces no functional changes. Signed-off-by: Philip Withnall --- gio/tests/codegen.py | 61 ++++++++++++++++++++++---------------------- 1 file changed, 31 insertions(+), 30 deletions(-) diff --git a/gio/tests/codegen.py b/gio/tests/codegen.py index fde551855..8c9132ef3 100644 --- a/gio/tests/codegen.py +++ b/gio/tests/codegen.py @@ -28,6 +28,7 @@ import shutil import subprocess import sys import tempfile +import textwrap import unittest import xml.etree.ElementTree as ET @@ -541,22 +542,22 @@ G_END_DECLS self.assertEqual("", res.out) with open("test-org.project.Bar.Frobnicator.rst", "r") as f: rst = f.read() - self.assertIn(""" -------- -Methods -------- + self.assertIn(textwrap.dedent(""" + ------- + Methods + ------- -.. _org.project.Bar.Frobnicator.RandomMethod: + .. _org.project.Bar.Frobnicator.RandomMethod: -org.project.Bar.Frobnicator.RandomMethod -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + org.project.Bar.Frobnicator.RandomMethod + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -:: + :: - RandomMethod () + RandomMethod () -A random test method.""", rst) + A random test method."""), rst) def test_generate_rst_signal(self): """Test generating a signal documentation with the rst generator.""" @@ -580,22 +581,22 @@ A random test method.""", rst) self.assertEqual("", res.out) with open("test-org.project.Bar.Frobnicator.rst", "r") as f: rst = f.read() - self.assertIn(""" -------- -Signals -------- + self.assertIn(textwrap.dedent(""" + ------- + Signals + ------- -.. _org.project.Bar.Frobnicator::RandomSignal: + .. _org.project.Bar.Frobnicator::RandomSignal: -org.project.Bar.Frobnicator::RandomSignal -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + org.project.Bar.Frobnicator::RandomSignal + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -:: + :: - RandomSignal () + RandomSignal () -A random test signal.""", rst) + A random test signal."""), rst) def test_generate_rst_property(self): """Test generating a property documentation with the rst generator.""" @@ -619,22 +620,22 @@ A random test signal.""", rst) self.assertEqual("", res.out) with open("test-org.project.Bar.Frobnicator.rst", "r") as f: rst = f.read() - self.assertIn(""" ----------- -Properties ----------- + self.assertIn(textwrap.dedent(""" + ---------- + Properties + ---------- -.. _org.project.Bar.Frobnicator:RandomProperty: + .. _org.project.Bar.Frobnicator:RandomProperty: -org.project.Bar.Frobnicator:RandomProperty -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + org.project.Bar.Frobnicator:RandomProperty + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -:: + :: - RandomProperty readable s + RandomProperty readable s -A random test property.""", rst) + A random test property."""), rst) @unittest.skipIf(on_win32(), "requires /dev/stdout") def test_glib_min_required_invalid(self): From a714556b3ec060f63b0fbe678f8767a27fbecb02 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Mon, 11 Dec 2023 16:53:44 +0000 Subject: [PATCH 4/4] tests: Re-format codegen.py with black MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is just the result of running `black $(git ls-files '*.py')`. For some reason, the `sh-and-py-check` CI job didn’t run on merge request !3751, so this non-standard formatting slipped through onto `main`. See https://gitlab.gnome.org/GNOME/glib/-/merge_requests/3754#note_1939914 Signed-off-by: Philip Withnall --- gio/tests/codegen.py | 81 ++++++++++++++++++++++++++------------------ 1 file changed, 48 insertions(+), 33 deletions(-) diff --git a/gio/tests/codegen.py b/gio/tests/codegen.py index 8c9132ef3..bb570f170 100644 --- a/gio/tests/codegen.py +++ b/gio/tests/codegen.py @@ -520,7 +520,7 @@ G_END_DECLS rst = f.readlines() self.assertTrue(len(rst) != 0) - def test_generate_rst_method(self): + def test_generate_rst_method(self): """Test generating a method documentation with the rst generator.""" xml_contents = """ @@ -542,24 +542,29 @@ G_END_DECLS self.assertEqual("", res.out) with open("test-org.project.Bar.Frobnicator.rst", "r") as f: rst = f.read() - self.assertIn(textwrap.dedent(""" - ------- - Methods - ------- + self.assertIn( + textwrap.dedent( + """ + ------- + Methods + ------- - .. _org.project.Bar.Frobnicator.RandomMethod: + .. _org.project.Bar.Frobnicator.RandomMethod: - org.project.Bar.Frobnicator.RandomMethod - ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + org.project.Bar.Frobnicator.RandomMethod + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - :: + :: - RandomMethod () + RandomMethod () - A random test method."""), rst) + A random test method.""" + ), + rst, + ) - def test_generate_rst_signal(self): + def test_generate_rst_signal(self): """Test generating a signal documentation with the rst generator.""" xml_contents = """ @@ -581,24 +586,29 @@ G_END_DECLS self.assertEqual("", res.out) with open("test-org.project.Bar.Frobnicator.rst", "r") as f: rst = f.read() - self.assertIn(textwrap.dedent(""" - ------- - Signals - ------- + self.assertIn( + textwrap.dedent( + """ + ------- + Signals + ------- - .. _org.project.Bar.Frobnicator::RandomSignal: + .. _org.project.Bar.Frobnicator::RandomSignal: - org.project.Bar.Frobnicator::RandomSignal - ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + org.project.Bar.Frobnicator::RandomSignal + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - :: + :: - RandomSignal () + RandomSignal () - A random test signal."""), rst) + A random test signal.""" + ), + rst, + ) - def test_generate_rst_property(self): + def test_generate_rst_property(self): """Test generating a property documentation with the rst generator.""" xml_contents = """ @@ -620,22 +630,27 @@ G_END_DECLS self.assertEqual("", res.out) with open("test-org.project.Bar.Frobnicator.rst", "r") as f: rst = f.read() - self.assertIn(textwrap.dedent(""" - ---------- - Properties - ---------- + self.assertIn( + textwrap.dedent( + """ + ---------- + Properties + ---------- - .. _org.project.Bar.Frobnicator:RandomProperty: + .. _org.project.Bar.Frobnicator:RandomProperty: - org.project.Bar.Frobnicator:RandomProperty - ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + org.project.Bar.Frobnicator:RandomProperty + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - :: + :: - RandomProperty readable s + RandomProperty readable s - A random test property."""), rst) + A random test property.""" + ), + rst, + ) @unittest.skipIf(on_win32(), "requires /dev/stdout") def test_glib_min_required_invalid(self):