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

Method test_yield

Lib/test/test_grammar.py:1168–1205  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1166 True)
1167
1168 def test_yield(self):
1169 # Allowed as standalone statement
1170 def g(): yield 1
1171 def g(): yield from ()
1172 # Allowed as RHS of assignment
1173 def g(): x = yield 1
1174 def g(): x = yield from ()
1175 # Ordinary yield accepts implicit tuples
1176 def g(): yield 1, 1
1177 def g(): x = yield 1, 1
1178 # 'yield from' does not
1179 check_syntax_error(self, "def g(): yield from (), 1")
1180 check_syntax_error(self, "def g(): x = yield from (), 1")
1181 # Requires parentheses as subexpression
1182 def g(): 1, (yield 1)
1183 def g(): 1, (yield from ())
1184 check_syntax_error(self, "def g(): 1, yield 1")
1185 check_syntax_error(self, "def g(): 1, yield from ()")
1186 # Requires parentheses as call argument
1187 def g(): f((yield 1))
1188 def g(): f((yield 1), 1)
1189 def g(): f((yield from ()))
1190 def g(): f((yield from ()), 1)
1191 # Do not require parenthesis for tuple unpacking
1192 def g(): rest = 4, 5, 6; yield 1, 2, 3, *rest
1193 self.assertEqual(list(g()), [(1, 2, 3, 4, 5, 6)])
1194 check_syntax_error(self, "def g(): f(yield 1)")
1195 check_syntax_error(self, "def g(): f(yield 1, 1)")
1196 check_syntax_error(self, "def g(): f(yield from ())")
1197 check_syntax_error(self, "def g(): f(yield from (), 1)")
1198 # Not allowed at top level
1199 check_syntax_error(self, "yield")
1200 check_syntax_error(self, "yield from")
1201 # Not allowed at class scope
1202 check_syntax_error(self, "class foo:yield 1")
1203 check_syntax_error(self, "class foo:yield from ()")
1204 # Check annotation refleak on SyntaxError
1205 check_syntax_error(self, "def g(a:(yield)): pass")
1206
1207 def test_yield_in_comprehensions(self):
1208 # Check yield in comprehensions

Callers

nothing calls this directly

Calls 4

check_syntax_errorFunction · 0.90
listClass · 0.85
gFunction · 0.70
assertEqualMethod · 0.45

Tested by

no test coverage detected