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

Method test_conversions

Lib/test/test_tstring.py:91–112  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

89 self.assertEqual(fstring(t), "Pi: 3.14")
90
91 def test_conversions(self):
92 # Test !s conversion (str)
93 obj = object()
94 t = t"Object: {obj!s}"
95 self.assertTStringEqual(t, ("Object: ", ""), [(obj, "obj", "s")])
96 self.assertEqual(fstring(t), f"Object: {str(obj)}")
97
98 # Test !r conversion (repr)
99 t = t"Data: {obj!r}"
100 self.assertTStringEqual(t, ("Data: ", ""), [(obj, "obj", "r")])
101 self.assertEqual(fstring(t), f"Data: {repr(obj)}")
102
103 # Test !a conversion (ascii)
104 text = "Café"
105 t = t"ASCII: {text!a}"
106 self.assertTStringEqual(t, ("ASCII: ", ""), [(text, "text", "a")])
107 self.assertEqual(fstring(t), f"ASCII: {ascii(text)}")
108
109 # Test !z conversion (error)
110 num = 1
111 with self.assertRaises(SyntaxError):
112 eval("t'{num!z}'")
113
114 def test_debug_specifier(self):
115 # Test debug specifier

Callers

nothing calls this directly

Calls 6

fstringFunction · 0.90
strFunction · 0.85
asciiFunction · 0.85
assertTStringEqualMethod · 0.80
assertEqualMethod · 0.45
assertRaisesMethod · 0.45

Tested by

no test coverage detected