Add string representation for python namespace objects

This commit is contained in:
2026-04-08 14:13:12 +02:00
parent 66f06960a9
commit 54e3a30ef0
5 changed files with 37 additions and 4 deletions
@@ -22,4 +22,12 @@ def test_PythonModuleNamespace_name_attribute(namespace, expected_name):
])
def test_PythonModuleNamespace___eq__(namespace1, namespace2, expected):
assert (namespace1 == namespace2) == expected
assert (namespace2 == namespace1) == expected
assert (namespace2 == namespace1) == expected
@pytest.mark.parametrize('namespace,expected', [
(PythonModuleNamespace('a'), 'PythonModuleNamespace(\'a\')'),
(PythonModuleNamespace('1'), 'PythonModuleNamespace(\'1\')'),
(PythonModuleNamespace(StrSubclass('a')), 'PythonModuleNamespace(\'a\')'),
])
def test_PythonModuleNamespace_string_representation(namespace, expected):
assert repr(namespace) == expected
@@ -9,4 +9,12 @@ class StrSubclass(str): ...
(PythonNamespace(StrSubclass('a')), StrSubclass('a')),
])
def test_PythonNamespace_name_attribute(namespace, expected_name):
assert namespace.name == expected_name
assert namespace.name == expected_name
@pytest.mark.parametrize('namespace,expected', [
(PythonNamespace('a'), 'PythonNamespace(\'a\')'),
(PythonNamespace('1'), 'PythonNamespace(\'1\')'),
(PythonNamespace(StrSubclass('a')), 'PythonNamespace(\'a\')'),
])
def test_PythonNamespace_string_representation(namespace, expected):
assert repr(namespace) == expected
@@ -75,4 +75,14 @@ def test_PythonPackageNamespace_sub_namespace_names(namespace, expected):
])
def test_PythonPackageNamespace___eq__(namespace1, namespace2, expected):
assert (namespace1 == namespace2) == expected
assert (namespace2 == namespace1) == expected
assert (namespace2 == namespace1) == expected
@pytest.mark.parametrize('namespace,expected', [
(PythonPackageNamespace('a', {}), 'PythonPackageNamespace(\'a\', {})'),
(PythonPackageNamespace('1', {}), 'PythonPackageNamespace(\'1\', {})'),
(PythonPackageNamespace(StrSubclass('a'), {}), 'PythonPackageNamespace(\'a\', {})'),
(namespace_a, 'PythonPackageNamespace(\'a\', {\'b\': PythonModuleNamespace(\'b\')})'),
(namespace_d, 'PythonPackageNamespace(\'d\', {\'e\': PythonPackageNamespace(\'e\', {\'f\': PythonPackageNamespace(\'f\', {\'g\': PythonPackageNamespace(\'g\', {\'h\': PythonPackageNamespace(\'h\', {\'i\': PythonPackageNamespace(\'i\', {\'j\': PythonPackageNamespace(\'j\', {\'k\': PythonModuleNamespace(\'k\')})})})})})})})')
])
def test_PythonPackageNamespace_string_representation(namespace, expected):
assert repr(namespace) == expected