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

Method test_literal_concatenation

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

Source from the content-addressed store, hash-verified

231 eval("t'Hello, {name}'")
232
233 def test_literal_concatenation(self):
234 # Test concatenation of t-string literals
235 t = t"Hello, " t"world"
236 self.assertTStringEqual(t, ("Hello, world",), ())
237 self.assertEqual(fstring(t), "Hello, world")
238
239 # Test concatenation with interpolation
240 name = "Python"
241 t = t"Hello, " t"{name}"
242 self.assertTStringEqual(t, ("Hello, ", ""), [(name, "name")])
243 self.assertEqual(fstring(t), "Hello, Python")
244
245 # Test disallowed mix of t-string and string/f-string (incl. bytes)
246 what = 't'
247 expected_msg = 'cannot mix t-string literals with string or bytes literals'
248 for case in (
249 "t'{what}-string literal' 'str literal'",
250 "t'{what}-string literal' u'unicode literal'",
251 "t'{what}-string literal' f'f-string literal'",
252 "t'{what}-string literal' r'raw string literal'",
253 "t'{what}-string literal' rf'raw f-string literal'",
254 "t'{what}-string literal' b'bytes literal'",
255 "t'{what}-string literal' br'raw bytes literal'",
256 "'str literal' t'{what}-string literal'",
257 "u'unicode literal' t'{what}-string literal'",
258 "f'f-string literal' t'{what}-string literal'",
259 "r'raw string literal' t'{what}-string literal'",
260 "rf'raw f-string literal' t'{what}-string literal'",
261 "b'bytes literal' t'{what}-string literal'",
262 "br'raw bytes literal' t'{what}-string literal'",
263 ):
264 with self.subTest(case):
265 with self.assertRaisesRegex(SyntaxError, expected_msg):
266 eval(case)
267
268 def test_triple_quoted(self):
269 # Test triple-quoted t-strings

Callers

nothing calls this directly

Calls 5

fstringFunction · 0.90
assertTStringEqualMethod · 0.80
assertRaisesRegexMethod · 0.80
assertEqualMethod · 0.45
subTestMethod · 0.45

Tested by

no test coverage detected