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

Method test_ast_fstring_format_spec

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

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 3

assertEqualMethod · 0.95
lenFunction · 0.85
parseMethod · 0.45

Tested by

no test coverage detected