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

Method test_ast

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

Source from the content-addressed store, hash-verified

64 self.assertEqual(type(y).__format__(y, ''), 'class')
65
66 def test_ast(self):
67 # Inspired by http://bugs.python.org/issue24975
68 class X:
69 def __init__(self):
70 self.called = False
71 def __call__(self):
72 self.called = True
73 return 4
74 x = X()
75 expr = """
76a = 10
77f'{a * x()}'"""
78 t = ast.parse(expr)
79 c = compile(t, '', 'exec')
80
81 # Make sure x was not called.
82 self.assertFalse(x.called)
83
84 # Actually run the code.
85 exec(c)
86
87 # Make sure x was called.
88 self.assertTrue(x.called)
89
90 def test_ast_line_numbers(self):
91 expr = """

Callers

nothing calls this directly

Calls 5

assertFalseMethod · 0.95
assertTrueMethod · 0.95
XClass · 0.70
compileFunction · 0.50
parseMethod · 0.45

Tested by

no test coverage detected