MCPcopy Create free account
hub / github.com/RustPython/RustPython / test_formatter_parser

Method test_formatter_parser

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

Source from the content-addressed store, hash-verified

2727
2728class StringModuleTest(unittest.TestCase):
2729 def test_formatter_parser(self):
2730 def parse(format):
2731 return list(_string.formatter_parser(format))
2732
2733 formatter = parse("prefix {2!s}xxx{0:^+10.3f}{obj.attr!s} {z[0]!s:10}")
2734 self.assertEqual(formatter, [
2735 ('prefix ', '2', '', 's'),
2736 ('xxx', '0', '^+10.3f', None),
2737 ('', 'obj.attr', '', 's'),
2738 (' ', 'z[0]', '10', 's'),
2739 ])
2740
2741 formatter = parse("prefix {} suffix")
2742 self.assertEqual(formatter, [
2743 ('prefix ', '', '', None),
2744 (' suffix', None, None, None),
2745 ])
2746
2747 formatter = parse("str")
2748 self.assertEqual(formatter, [
2749 ('str', None, None, None),
2750 ])
2751
2752 formatter = parse("")
2753 self.assertEqual(formatter, [])
2754
2755 formatter = parse("{0}")
2756 self.assertEqual(formatter, [
2757 ('', '0', '', None),
2758 ])
2759
2760 self.assertRaises(TypeError, _string.formatter_parser, 1)
2761
2762 def test_formatter_field_name_split(self):
2763 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