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

Method test_ast_fstring_format_spec

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

Source from the content-addressed store, hash-verified

517 self.assertEqual(len(format_spec.values), 0)
518
519 def test_ast_fstring_format_spec(self):
520 expr = "f'{1:{name}}'"
521
522 mod = ast.parse(expr)
523 self.assertEqual(type(mod), ast.Module)
524 self.assertEqual(len(mod.body), 1)
525
526 fstring = mod.body[0].value
527 self.assertEqual(type(fstring), ast.JoinedStr)
528 self.assertEqual(len(fstring.values), 1)
529
530 fv = fstring.values[0]
531 self.assertEqual(type(fv), ast.FormattedValue)
532
533 format_spec = fv.format_spec
534 self.assertEqual(type(format_spec), ast.JoinedStr)
535 self.assertEqual(len(format_spec.values), 1)
536
537 format_spec_value = format_spec.values[0]
538 self.assertEqual(type(format_spec_value), ast.FormattedValue)
539 self.assertEqual(format_spec_value.value.id, 'name')
540
541 expr = "f'{1:{name1}{name2}}'"
542
543 mod = ast.parse(expr)
544 self.assertEqual(type(mod), ast.Module)
545 self.assertEqual(len(mod.body), 1)
546
547 fstring = mod.body[0].value
548 self.assertEqual(type(fstring), ast.JoinedStr)
549 self.assertEqual(len(fstring.values), 1)
550
551 fv = fstring.values[0]
552 self.assertEqual(type(fv), ast.FormattedValue)
553
554 format_spec = fv.format_spec
555 self.assertEqual(type(format_spec), ast.JoinedStr)
556 self.assertEqual(len(format_spec.values), 2)
557
558 format_spec_value = format_spec.values[0]
559 self.assertEqual(type(format_spec_value), ast.FormattedValue)
560 self.assertEqual(format_spec_value.value.id, 'name1')
561
562 format_spec_value = format_spec.values[1]
563 self.assertEqual(type(format_spec_value), ast.FormattedValue)
564 self.assertEqual(format_spec_value.value.id, 'name2')
565
566
567 def test_docstring(self):

Callers

nothing calls this directly

Calls 2

assertEqualMethod · 0.95
parseMethod · 0.45

Tested by

no test coverage detected