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

Method test_better_error_message_format

Lib/test/test_format.py:687–706  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

685 '{:._,f}'.format(1.1)
686
687 def test_better_error_message_format(self):
688 # https://bugs.python.org/issue20524
689 for value in [12j, 12, 12.0, "12"]:
690 with self.subTest(value=value):
691 # The format spec must be invalid for all types we're testing.
692 # '%M' will suffice.
693 bad_format_spec = '%M'
694 err = re.escape("Invalid format specifier "
695 f"'{bad_format_spec}' for object of type "
696 f"'{type(value).__name__}'")
697 with self.assertRaisesRegex(ValueError, err):
698 f"xx{{value:{bad_format_spec}}}yy".format(value=value)
699
700 # Also test the builtin format() function.
701 with self.assertRaisesRegex(ValueError, err):
702 format(value, bad_format_spec)
703
704 # Also test f-strings.
705 with self.assertRaisesRegex(ValueError, err):
706 eval("f'xx{value:{bad_format_spec}}yy'")
707
708 def test_unicode_in_error_message(self):
709 str_err = re.escape(

Callers

nothing calls this directly

Calls 5

formatFunction · 0.85
escapeMethod · 0.80
assertRaisesRegexMethod · 0.80
subTestMethod · 0.45
formatMethod · 0.45

Tested by

no test coverage detected