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

Method test_format_specifier_expressions

Lib/test/test_fstring.py:820–851  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

818
819 @unittest.expectedFailure # TODO: RUSTPYTHON
820 def test_format_specifier_expressions(self):
821 width = 10
822 precision = 4
823 value = decimal.Decimal('12.34567')
824 self.assertEqual(f'result: {value:{width}.{precision}}', 'result: 12.35')
825 self.assertEqual(f'result: {value:{width!r}.{precision}}', 'result: 12.35')
826 self.assertEqual(f'result: {value:{width:0}.{precision:1}}', 'result: 12.35')
827 self.assertEqual(f'result: {value:{1}{0:0}.{precision:1}}', 'result: 12.35')
828 self.assertEqual(f'result: {value:{ 1}{ 0:0}.{ precision:1}}', 'result: 12.35')
829 self.assertEqual(f'{10:#{1}0x}', ' 0xa')
830 self.assertEqual(f'{10:{"#"}1{0}{"x"}}', ' 0xa')
831 self.assertEqual(f'{-10:-{"#"}1{0}x}', ' -0xa')
832 self.assertEqual(f'{-10:{"-"}#{1}0{"x"}}', ' -0xa')
833 self.assertEqual(f'{10:#{3 != {4:5} and width}x}', ' 0xa')
834 self.assertEqual(f'result: {value:{width:{0}}.{precision:1}}', 'result: 12.35')
835
836 self.assertAllRaise(SyntaxError, "f-string: expecting ':' or '}'",
837 ["""f'{"s"!r{":10"}}'""",
838 # This looks like a nested format spec.
839 ])
840
841 self.assertAllRaise(SyntaxError,
842 "f-string: expecting a valid expression after '{'",
843 [# Invalid syntax inside a nested spec.
844 "f'{4:{/5}}'",
845 ])
846
847 self.assertAllRaise(SyntaxError, 'f-string: invalid conversion character',
848 [# No expansion inside conversion or for
849 # the : or ! itself.
850 """f'{"s"!{"r"}}'""",
851 ])
852
853 def test_custom_format_specifier(self):
854 class CustomFormat:

Callers

nothing calls this directly

Calls 2

assertEqualMethod · 0.95
assertAllRaiseMethod · 0.95

Tested by

no test coverage detected