diff options
author | Bob Ippolito <bob@redivi.com> | 2022-11-14 09:59:31 -0800 |
---|---|---|
committer | Bob Ippolito <bob@redivi.com> | 2022-11-14 09:59:31 -0800 |
commit | ef43c2dff7ec41a58945600027e2150629fd8c48 (patch) | |
tree | 8f86f9741772d036b80f4b0160e7008883970506 /simplejson/tests/test_namedtuple.py | |
parent | 43645252224d4e529c22cb78ac42f241d6426073 (diff) | |
download | simplejson-ef43c2dff7ec41a58945600027e2150629fd8c48.tar.gz |
Implement tests and fallback implementation of #301
Diffstat (limited to 'simplejson/tests/test_namedtuple.py')
-rw-r--r-- | simplejson/tests/test_namedtuple.py | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/simplejson/tests/test_namedtuple.py b/simplejson/tests/test_namedtuple.py index 8035a5f..cc0f8aa 100644 --- a/simplejson/tests/test_namedtuple.py +++ b/simplejson/tests/test_namedtuple.py @@ -110,22 +110,47 @@ class TestNamedTuple(unittest.TestCase): def test_asdict_not_callable_dump(self): for f in CONSTRUCTORS: - self.assertRaises(TypeError, - json.dump, f(DeadDuck()), StringIO(), namedtuple_as_object=True) + self.assertRaises( + TypeError, + json.dump, + f(DeadDuck()), + StringIO(), + namedtuple_as_object=True + ) sio = StringIO() json.dump(f(DeadDict()), sio, namedtuple_as_object=True) self.assertEqual( json.dumps(f({})), sio.getvalue()) + self.assertRaises( + TypeError, + json.dump, + f(Value), + StringIO(), + namedtuple_as_object=True + ) def test_asdict_not_callable_dumps(self): for f in CONSTRUCTORS: self.assertRaises(TypeError, json.dumps, f(DeadDuck()), namedtuple_as_object=True) + self.assertRaises( + TypeError, + json.dumps, + f(Value), + namedtuple_as_object=True + ) self.assertEqual( json.dumps(f({})), json.dumps(f(DeadDict()), namedtuple_as_object=True)) + def test_asdict_unbound_method_dumps(self): + for f in CONSTRUCTORS: + self.assertEqual( + json.dumps(f(Value), default=lambda v: v.__name__), + json.dumps(f(Value.__name__)) + ) + def test_asdict_does_not_return_dict(self): if not mock: if hasattr(unittest, "SkipTest"): |