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

Method test_formatter_parser

Lib/test/test_str.py:2744–2775  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

2742
2743class StringModuleTest(unittest.TestCase):
2744 def test_formatter_parser(self):
2745 def parse(format):
2746 return list(_string.formatter_parser(format))
2747
2748 formatter = parse("prefix {2!s}xxx{0:^+10.3f}{obj.attr!s} {z[0]!s:10}")
2749 self.assertEqual(formatter, [
2750 ('prefix ', '2', '', 's'),
2751 ('xxx', '0', '^+10.3f', None),
2752 ('', 'obj.attr', '', 's'),
2753 (' ', 'z[0]', '10', 's'),
2754 ])
2755
2756 formatter = parse("prefix {} suffix")
2757 self.assertEqual(formatter, [
2758 ('prefix ', '', '', None),
2759 (' suffix', None, None, None),
2760 ])
2761
2762 formatter = parse("str")
2763 self.assertEqual(formatter, [
2764 ('str', None, None, None),
2765 ])
2766
2767 formatter = parse("")
2768 self.assertEqual(formatter, [])
2769
2770 formatter = parse("{0}")
2771 self.assertEqual(formatter, [
2772 ('', '0', '', None),
2773 ])
2774
2775 self.assertRaises(TypeError, _string.formatter_parser, 1)
2776
2777 def test_formatter_field_name_split(self):
2778 def split(name):

Callers

nothing calls this directly

Calls 3

parseFunction · 0.50
assertEqualMethod · 0.45
assertRaisesMethod · 0.45

Tested by

no test coverage detected