MCPcopy Create free account
hub / github.com/simplejson/simplejson / test_bad_str_encoder

Method test_bad_str_encoder

simplejson/tests/test_speedups.py:45–66  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

43
44 @skip_if_speedups_missing
45 def test_bad_str_encoder(self):
46 # Issue #31505: There shouldn't be an assertion failure in case
47 # c_make_encoder() receives a bad encoder() argument.
48 import decimal
49 def bad_encoder1(*args):
50 return None
51 enc = encoder.c_make_encoder(
52 None, lambda obj: str(obj),
53 bad_encoder1, None, ': ', ', ',
54 False, False, False, {}, False, False, False,
55 None, None, 'utf-8', False, False, decimal.Decimal, False)
56 self.assertRaises(TypeError, enc, 'spam', 4)
57 self.assertRaises(TypeError, enc, {'spam': 42}, 4)
58
59 def bad_encoder2(*args):
60 1/0
61 enc = encoder.c_make_encoder(
62 None, lambda obj: str(obj),
63 bad_encoder2, None, ': ', ', ',
64 False, False, False, {}, False, False, False,
65 None, None, 'utf-8', False, False, decimal.Decimal, False)
66 self.assertRaises(ZeroDivisionError, enc, 'spam', 4)
67
68 @skip_if_speedups_missing
69 def test_bad_bool_args(self):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected