Lines Matching refs:self

35     def test_formfeed(self):
38 self.assertEqual(t.children[0].children[0].type, syms.print_stmt)
39 self.assertEqual(t.children[1].children[0].type, syms.print_stmt)
43 def test_load_grammar_from_txt_file(self):
46 def test_load_grammar_from_pickle(self):
57 self.assertTrue(os.path.exists(pickle_name))
68 def test_load_grammar_from_subprocess(self):
81 self.assertNotEqual(pickle_name, pickle_sub_name)
85 self.assertTrue(os.path.exists(pickle_name))
99 self.assertTrue(os.path.exists(pickle_sub_name))
103 self.assertEqual(
110 def test_load_packaged_grammar(self):
113 def get_data(self, where):
119 self.addCleanup(operator.delitem, sys.modules, modname)
121 self.assertEqual(g.elephant, 19)
125 def validate(self, code):
128 def invalid_syntax(self, code):
130 self.validate(code)
138 def test_matrix_multiplication_operator(self):
139 self.validate("a @ b")
140 self.validate("a @= b")
144 def test_yield_from(self):
145 self.validate("yield from x")
146 self.validate("(yield from x) + y")
147 self.invalid_syntax("yield from")
151 def test_await_expr(self):
152 self.validate("""async def foo():
156 self.validate("""async def foo():
160 self.validate("""async def foo():
166 self.validate("""async def foo():
170 self.validate("""async def foo():
174 self.validate("""async def foo():
183 self.validate("""async def foo(): return await a""")
185 self.validate("""def foo():
190 self.invalid_syntax("await x")
191 self.invalid_syntax("""def foo():
194 self.invalid_syntax("""def foo():
200 def test_async_var(self):
201 self.validate("""async = 1""")
202 self.validate("""await = 1""")
203 self.validate("""def async(): pass""")
205 def test_async_for(self):
206 self.validate("""async def foo():
209 def test_async_with(self):
210 self.validate("""async def foo():
213 self.invalid_syntax("""def foo():
216 def test_async_generator(self):
217 self.validate(
221 self.validate(
228 def test_2x_style_1(self):
229 self.validate("raise")
231 def test_2x_style_2(self):
232 self.validate("raise E, V")
234 def test_2x_style_3(self):
235 self.validate("raise E, V, T")
237 def test_2x_style_invalid_1(self):
238 self.invalid_syntax("raise E, V, T, Z")
240 def test_3x_style(self):
241 self.validate("raise E1 from E2")
243 def test_3x_style_invalid_1(self):
244 self.invalid_syntax("raise E, V from E1")
246 def test_3x_style_invalid_2(self):
247 self.invalid_syntax("raise E from E1, E2")
249 def test_3x_style_invalid_3(self):
250 self.invalid_syntax("raise from E1, E2")
252 def test_3x_style_invalid_4(self):
253 self.invalid_syntax("raise E from")
260 def test_mid_positional_star(self):
261 self.validate("""func(1, *(2, 3), 4)""")
263 def test_double_star_dict_literal(self):
264 self.validate("""func(**{'eggs':'scrambled', 'spam':'fried'})""")
266 def test_double_star_dict_literal_after_keywords(self):
267 self.validate("""func(spam='fried', **{'eggs':'scrambled'})""")
269 def test_double_star_expression(self):
270 self.validate("""func(**{'a':2} or {})""")
271 self.validate("""func(**() or {})""")
273 def test_star_expression(self):
274 self.validate("""func(*[] or [2])""")
276 def test_list_display(self):
277 self.validate("""[*{2}, 3, *[4]]""")
279 def test_set_display(self):
280 self.validate("""{*{2}, 3, *[4]}""")
282 def test_dict_display_1(self):
283 self.validate("""{**{}}""")
285 def test_dict_display_2(self):
286 self.validate("""{**{}, 3:4, **{5:6, 7:8}}""")
288 def test_complex_star_expression(self):
289 self.validate("func(* [] or [1])")
291 def test_complex_double_star_expression(self):
292 self.validate("func(**{1: 3} if False else {x: x for x in range(3)})")
294 def test_argument_unpacking_1(self):
295 self.validate("""f(a, *b, *c, d)""")
297 def test_argument_unpacking_2(self):
298 self.validate("""f(**a, **b)""")
300 def test_argument_unpacking_3(self):
301 self.validate("""f(2, *a, *b, **b, **c, **d)""")
303 def test_trailing_commas_1(self):
304 self.validate("def f(a, b): call(a, b)")
305 self.validate("def f(a, b,): call(a, b,)")
307 def test_trailing_commas_2(self):
308 self.validate("def f(a, *b): call(a, *b)")
309 self.validate("def f(a, *b,): call(a, *b,)")
311 def test_trailing_commas_3(self):
312 self.validate("def f(a, b=1): call(a, b=1)")
313 self.validate("def f(a, b=1,): call(a, b=1,)")
315 def test_trailing_commas_4(self):
316 self.validate("def f(a, **b): call(a, **b)")
317 self.validate("def f(a, **b,): call(a, **b,)")
319 def test_trailing_commas_5(self):
320 self.validate("def f(*a, b=1): call(*a, b=1)")
321 self.validate("def f(*a, b=1,): call(*a, b=1,)")
323 def test_trailing_commas_6(self):
324 self.validate("def f(*a, **b): call(*a, **b)")
325 self.validate("def f(*a, **b,): call(*a, **b,)")
327 def test_trailing_commas_7(self):
328 self.validate("def f(*, b=1): call(*b)")
329 self.validate("def f(*, b=1,): call(*b,)")
331 def test_trailing_commas_8(self):
332 self.validate("def f(a=1, b=2): call(a=1, b=2)")
333 self.validate("def f(a=1, b=2,): call(a=1, b=2,)")
335 def test_trailing_commas_9(self):
336 self.validate("def f(a=1, **b): call(a=1, **b)")
337 self.validate("def f(a=1, **b,): call(a=1, **b,)")
339 def test_trailing_commas_lambda_1(self):
340 self.validate("f = lambda a, b: call(a, b)")
341 self.validate("f = lambda a, b,: call(a, b,)")
343 def test_trailing_commas_lambda_2(self):
344 self.validate("f = lambda a, *b: call(a, *b)")
345 self.validate("f = lambda a, *b,: call(a, *b,)")
347 def test_trailing_commas_lambda_3(self):
348 self.validate("f = lambda a, b=1: call(a, b=1)")
349 self.validate("f = lambda a, b=1,: call(a, b=1,)")
351 def test_trailing_commas_lambda_4(self):
352 self.validate("f = lambda a, **b: call(a, **b)")
353 self.validate("f = lambda a, **b,: call(a, **b,)")
355 def test_trailing_commas_lambda_5(self):
356 self.validate("f = lambda *a, b=1: call(*a, b=1)")
357 self.validate("f = lambda *a, b=1,: call(*a, b=1,)")
359 def test_trailing_commas_lambda_6(self):
360 self.validate("f = lambda *a, **b: call(*a, **b)")
361 self.validate("f = lambda *a, **b,: call(*a, **b,)")
363 def test_trailing_commas_lambda_7(self):
364 self.validate("f = lambda *, b=1: call(*b)")
365 self.validate("f = lambda *, b=1,: call(*b,)")
367 def test_trailing_commas_lambda_8(self):
368 self.validate("f = lambda a=1, b=2: call(a=1, b=2)")
369 self.validate("f = lambda a=1, b=2,: call(a=1, b=2,)")
371 def test_trailing_commas_lambda_9(self):
372 self.validate("f = lambda a=1, **b: call(a=1, **b)")
373 self.validate("f = lambda a=1, **b,: call(a=1, **b,)")
378 def test_1(self):
379 self.validate("""def f(x) -> list: pass""")
381 def test_2(self):
382 self.validate("""def f(x:int): pass""")
384 def test_3(self):
385 self.validate("""def f(*x:str): pass""")
387 def test_4(self):
388 self.validate("""def f(**x:float): pass""")
390 def test_5(self):
391 self.validate("""def f(x, y:1+2): pass""")
393 def test_6(self):
394 self.validate("""def f(a, (b:1, c:2, d)): pass""")
396 def test_7(self):
397 self.validate("""def f(a, (b:1, c:2, d), e:3=4, f=5, *g:6): pass""")
399 def test_8(self):
402 self.validate(s)
404 def test_9(self):
413 self.validate(s)
415 def test_10(self):
420 self.validate(s)
422 def test_11(self):
427 self.validate(s)
429 def test_12(self):
434 self.validate(s)
436 def test_13(self):
437 self.validate("def f(a: str, b: int) -> None: call(a, b)")
438 self.validate("def f(a: str, b: int,) -> None: call(a, b,)")
440 def test_14(self):
441 self.validate("def f(a: str, *b: int) -> None: call(a, *b)")
442 self.validate("def f(a: str, *b: int,) -> None: call(a, *b,)")
444 def test_15(self):
445 self.validate("def f(a: str, b: int=1) -> None: call(a, b=1)")
446 self.validate("def f(a: str, b: int=1,) -> None: call(a, b=1,)")
448 def test_16(self):
449 self.validate("def f(a: str, **b: int) -> None: call(a, **b)")
450 self.validate("def f(a: str, **b: int,) -> None: call(a, **b,)")
452 def test_17(self):
453 self.validate("def f(*a: str, b: int=1) -> None: call(*a, b=1)")
454 self.validate("def f(*a: str, b: int=1,) -> None: call(*a, b=1,)")
456 def test_18(self):
457 self.validate("def f(*a: str, **b: int) -> None: call(*a, **b)")
458 self.validate("def f(*a: str, **b: int,) -> None: call(*a, **b,)")
460 def test_19(self):
461 self.validate("def f(*, b: int=1) -> None: call(*b)")
462 self.validate("def f(*, b: int=1,) -> None: call(*b,)")
464 def test_20(self):
465 self.validate("def f(a: str='', b: int=2) -> None: call(a=a, b=2)")
466 self.validate("def f(a: str='', b: int=2,) -> None: call(a=a, b=2,)")
468 def test_21(self):
469 self.validate("def f(a: str='', **b: int) -> None: call(a=a, **b)")
470 self.validate("def f(a: str='', **b: int,) -> None: call(a=a, **b,)")
475 def test_1(self):
476 self.validate("var1: int = 5")
478 def test_2(self):
479 self.validate("var2: [int, str]")
481 def test_3(self):
482 self.validate("def f():\n"
487 def test_4(self):
488 self.validate("def fbad():\n"
492 def test_5(self):
493 self.validate("class C:\n"
497 " def __init__(self, x):\n"
498 " self.x: int = x\n")
500 def test_6(self):
501 self.validate("lst: List[int] = []")
505 def test_new(self):
511 self.validate(s)
513 def test_old(self):
519 self.validate(s)
535 def test_lit(self):
536 for pre in self.prefixes:
538 self.validate(single)
540 self.validate(triple)
545 def test_1(self):
546 self.validate("""x = {'one'}""")
548 def test_2(self):
549 self.validate("""x = {'one', 1,}""")
551 def test_3(self):
552 self.validate("""x = {'one', 'two', 'three'}""")
554 def test_4(self):
555 self.validate("""x = {2, 3, 4,}""")
561 def test_non_ascii_identifiers(self):
562 self.validate("Örter = 'places'\ngrün = 'green'")
563 self.validate("蟒 = a蟒 = 锦蛇 = 1")
564 self.validate("µ = aµ = µµ = 1")
565 self.validate("??????? = a_??????? = 1")
569 def test_new_octal_notation(self):
570 self.validate("""0o7777777777777""")
571 self.invalid_syntax("""0o7324528887""")
573 def test_new_binary_notation(self):
574 self.validate("""0b101010""")
575 self.invalid_syntax("""0b0101021""")
579 def test_new_syntax(self):
580 self.validate("class B(t=7): pass")
581 self.validate("class B(t, *args): pass")
582 self.validate("class B(t, **kwargs): pass")
583 self.validate("class B(t, *args, **kwargs): pass")
584 self.validate("class B(t, y=9, *args, **kwargs,): pass")
591 def parse_file(self, filepath):
596 self.assertIsNotNone(encoding,
606 self.fail('ParseError on file %s (%s)' % (filepath, err))
610 self.fail("Idempotency failed: %s" % filepath)
612 def test_all_project_files(self):
614 with self.subTest(filepath=filepath):
615 self.parse_file(filepath)
617 def test_extended_unpacking(self):
626 def validate(self, s):
629 def test_multiline_bytes_literals(self):
636 self.validate(s)
638 def test_multiline_bytes_tripquote_literals(self):
645 self.validate(s)
647 def test_multiline_str_literals(self):
654 self.validate(s)
660 def test_named_assignment_if(self):
663 def test_named_assignment_while(self):
666 def test_named_assignment_generator(self):
669 def test_named_assignment_listcomp(self):
675 def test_one_pos_only_arg(self):
678 def test_all_markers(self):
682 def test_all_with_args_and_kwargs(self):
689 def test_lambda_soup(self):
693 def test_only_positional_or_keyword(self):
698 def test_ParseError(self):
702 self.assertEqual(err.args, err2.args)
703 self.assertEqual(err.msg, err2.msg)
704 self.assertEqual(err.type, err2.type)
705 self.assertEqual(err.value, err2.value)
706 self.assertEqual(err.context, err2.context)