MCPcopy Index your code
hub / github.com/python/cpython / test_invalid_indent

Method test_invalid_indent

Lib/test/test_reprlib.py:589–606  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

587 self.assertEqual(resulting_repr, expected_repr)
588
589 def test_invalid_indent(self):
590 test_object = [1, 'spam', {'eggs': True, 'ham': []}]
591 test_cases = [
592 (-1, (ValueError, '[Nn]egative|[Pp]ositive')),
593 (-4, (ValueError, '[Nn]egative|[Pp]ositive')),
594 ((), (TypeError, None)),
595 ([], (TypeError, None)),
596 ((4,), (TypeError, None)),
597 ([4,], (TypeError, None)),
598 (object(), (TypeError, None)),
599 ]
600 for indent, (expected_error, expected_msg) in test_cases:
601 with self.subTest(indent=indent):
602 r = Repr()
603 r.indent = indent
604 expected_msg = expected_msg or f'{type(indent)}'
605 with self.assertRaisesRegex(expected_error, expected_msg):
606 r.repr(test_object)
607
608 def test_shadowed_stdlib_array(self):
609 # Issue #113570: repr() should not be fooled by an array

Callers

nothing calls this directly

Calls 4

reprMethod · 0.95
ReprClass · 0.90
assertRaisesRegexMethod · 0.80
subTestMethod · 0.45

Tested by

no test coverage detected