Merge branch 'fix-py-formatting' into 'main'

tests: Use textwrap.dedent to indent expected strings pleasingly

See merge request GNOME/glib!3755
This commit is contained in:
Michael Catanzaro 2023-12-11 18:30:22 +00:00
commit 1375967813

View File

@ -28,6 +28,7 @@ import shutil
import subprocess import subprocess
import sys import sys
import tempfile import tempfile
import textwrap
import unittest import unittest
import xml.etree.ElementTree as ET import xml.etree.ElementTree as ET
@ -520,7 +521,7 @@ G_END_DECLS
rst = f.readlines() rst = f.readlines()
self.assertTrue(len(rst) != 0) 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.""" """Test generating a method documentation with the rst generator."""
xml_contents = """ xml_contents = """
<node> <node>
@ -542,24 +543,29 @@ G_END_DECLS
self.assertEqual("", res.out) self.assertEqual("", res.out)
with open("test-org.project.Bar.Frobnicator.rst", "r") as f: with open("test-org.project.Bar.Frobnicator.rst", "r") as f:
rst = f.read() rst = f.read()
self.assertIn(""" self.assertIn(
------- textwrap.dedent(
Methods """
------- -------
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.""" """Test generating a signal documentation with the rst generator."""
xml_contents = """ xml_contents = """
<node> <node>
@ -581,24 +587,29 @@ A random test method.""", rst)
self.assertEqual("", res.out) self.assertEqual("", res.out)
with open("test-org.project.Bar.Frobnicator.rst", "r") as f: with open("test-org.project.Bar.Frobnicator.rst", "r") as f:
rst = f.read() rst = f.read()
self.assertIn(""" self.assertIn(
------- textwrap.dedent(
Signals """
------- -------
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.""" """Test generating a property documentation with the rst generator."""
xml_contents = """ xml_contents = """
<node> <node>
@ -620,22 +631,27 @@ A random test signal.""", rst)
self.assertEqual("", res.out) self.assertEqual("", res.out)
with open("test-org.project.Bar.Frobnicator.rst", "r") as f: with open("test-org.project.Bar.Frobnicator.rst", "r") as f:
rst = f.read() rst = f.read()
self.assertIn(""" self.assertIn(
---------- textwrap.dedent(
Properties """
---------- ----------
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") @unittest.skipIf(on_win32(), "requires /dev/stdout")
def test_glib_min_required_invalid(self): def test_glib_min_required_invalid(self):