MCPcopy Index your code
hub / github.com/RustPython/RustPython / test_format_combinations

Method test_format_combinations

Lib/test/test_peepholer.py:697–718  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

695
696 @support.requires_resource('cpu')
697 def test_format_combinations(self):
698 flags = '-+ #0'
699 testcases = [
700 *product(('', '1234', 'абвг'), 'sra'),
701 *product((1234, -1234), 'duioxX'),
702 *product((1234.5678901, -1234.5678901), 'duifegFEG'),
703 *product((float('inf'), -float('inf')), 'fegFEG'),
704 ]
705 width_precs = [
706 *product(('', '1', '30'), ('', '.', '.0', '.2')),
707 ('', '.40'),
708 ('30', '.40'),
709 ]
710 for value, suffix in testcases:
711 for width, prec in width_precs:
712 for r in range(len(flags) + 1):
713 for spec in combinations(flags, r):
714 fmt = '%' + ''.join(spec) + width + prec + suffix
715 with self.subTest(fmt=fmt, value=value):
716 s1 = fmt % value
717 s2 = eval(f'{fmt!r} % (x,)', {'x': value})
718 self.assertEqual(s2, s1, f'{fmt = }')
719
720 def test_format_misc(self):
721 def format(fmt, *values):

Callers

nothing calls this directly

Calls 5

lenFunction · 0.85
subTestMethod · 0.80
evalFunction · 0.50
joinMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected