diff options
author | Carl Bordum Hansen <carl@bordum.dk> | 2019-06-26 23:13:18 (GMT) |
---|---|---|
committer | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2019-06-26 23:13:18 (GMT) |
commit | 06a8916cf465f139dca958685b0da899364b8a8c (patch) | |
tree | 9109f49858378392227318cb05ad9b0ea1a1052c /Lib/test/test_pprint.py | |
parent | d52a83a3d471ff3c7e9ebfa1731765e5334f7c24 (diff) | |
download | cpython-06a8916cf465f139dca958685b0da899364b8a8c.zip cpython-06a8916cf465f139dca958685b0da899364b8a8c.tar.gz cpython-06a8916cf465f139dca958685b0da899364b8a8c.tar.bz2 |
bpo-37376: pprint support for SimpleNamespace (GH-14318)
https://bugs.python.org/issue37376
Diffstat (limited to 'Lib/test/test_pprint.py')
-rw-r--r-- | Lib/test/test_pprint.py | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/Lib/test/test_pprint.py b/Lib/test/test_pprint.py index 269ac06..b3b8715 100644 --- a/Lib/test/test_pprint.py +++ b/Lib/test/test_pprint.py @@ -346,6 +346,65 @@ mappingproxy(OrderedDict([('the', 0), ('lazy', 7), ('dog', 8)]))""") + def test_empty_simple_namespace(self): + ns = types.SimpleNamespace() + formatted = pprint.pformat(ns) + self.assertEqual(formatted, "namespace()") + + def test_small_simple_namespace(self): + ns = types.SimpleNamespace(a=1, b=2) + formatted = pprint.pformat(ns) + self.assertEqual(formatted, "namespace(a=1, b=2)") + + def test_simple_namespace(self): + ns = types.SimpleNamespace( + the=0, + quick=1, + brown=2, + fox=3, + jumped=4, + over=5, + a=6, + lazy=7, + dog=8, + ) + formatted = pprint.pformat(ns, width=60) + self.assertEqual(formatted, """\ +namespace(the=0, + quick=1, + brown=2, + fox=3, + jumped=4, + over=5, + a=6, + lazy=7, + dog=8)""") + + def test_simple_namespace_subclass(self): + class AdvancedNamespace(types.SimpleNamespace): pass + ns = AdvancedNamespace( + the=0, + quick=1, + brown=2, + fox=3, + jumped=4, + over=5, + a=6, + lazy=7, + dog=8, + ) + formatted = pprint.pformat(ns, width=60) + self.assertEqual(formatted, """\ +AdvancedNamespace(the=0, + quick=1, + brown=2, + fox=3, + jumped=4, + over=5, + a=6, + lazy=7, + dog=8)""") + def test_subclassing(self): o = {'names with spaces': 'should be presented using repr()', 'others.should.not.be': 'like.this'} |