How to use invalid_syntax method in autotest

Best Python code snippet using autotest_python Github


Full Screen

...21 self.assertEqual(t.children[1].children[0].type, 'print_stmt')22 s = """1\n\x0C\x0C2\n"""23 t = parse(s, '2.7')24class GrammarTest(TestCase):25 def invalid_syntax(self, code, **kwargs):26 try:27 parse(code, **kwargs)28 except ParseError:29 pass30 else:31 raise AssertionError("Syntax shouldn't have been valid")32class TestMatrixMultiplication(GrammarTest):33 @pytest.mark.skipif('sys.version_info[:2] < (3, 5)')34 def test_matrix_multiplication_operator(self):35 parse("a @ b", "3.5")36 parse("a @= b", "3.5")37class TestYieldFrom(GrammarTest):38 def test_yield_from(self):39 parse("yield from x")40 parse("(yield from x) + y")41 self.invalid_syntax("yield from")42class TestAsyncAwait(GrammarTest):43 @pytest.mark.skipif('sys.version_info[:2] < (3, 5)')44 def test_await_expr(self):45 parse("""async def foo():46 await x47 """, "3.5")48 parse("""async def foo():49 def foo(): pass50 def foo(): pass51 await x52 """, "3.5")53 parse("""async def foo(): return await a""", "3.5")54 parse("""def foo():55 def foo(): pass56 async def foo(): await x57 """, "3.5")58 @pytest.mark.skipif('sys.version_info[:2] < (3, 5)')59 @pytest.mark.xfail(reason="acting like python 3.7")60 def test_await_expr_invalid(self):61 self.invalid_syntax("await x", version="3.5")62 self.invalid_syntax("""def foo():63 await x""", version="3.5")64 self.invalid_syntax("""def foo():65 def foo(): pass66 async def foo(): pass67 await x68 """, version="3.5")69 @pytest.mark.skipif('sys.version_info[:2] < (3, 5)')70 @pytest.mark.xfail(reason="acting like python 3.7")71 def test_async_var(self):72 parse("""async = 1""", "3.5")73 parse("""await = 1""", "3.5")74 parse("""def async(): pass""", "3.5")75 @pytest.mark.skipif('sys.version_info[:2] < (3, 5)')76 def test_async_for(self):77 parse("""async def foo():78 async for a in b: pass""", "3.5")79 @pytest.mark.skipif('sys.version_info[:2] < (3, 5)')80 @pytest.mark.xfail(reason="acting like python 3.7")81 def test_async_for_invalid(self):82 self.invalid_syntax("""def foo():83 async for a in b: pass""", version="3.5")84 @pytest.mark.skipif('sys.version_info[:2] < (3, 5)')85 def test_async_with(self):86 parse("""async def foo():87 async with a: pass""", "3.5")88 @pytest.mark.skipif('sys.version_info[:2] < (3, 5)')89 @pytest.mark.xfail(reason="acting like python 3.7")90 def test_async_with_invalid(self):91 self.invalid_syntax("""def foo():92 async with a: pass""", version="3.5")93class TestRaiseChanges(GrammarTest):94 def test_2x_style_1(self):95 parse("raise")96 def test_2x_style_2(self):97 parse("raise E, V", version='2.7')98 def test_2x_style_3(self):99 parse("raise E, V, T", version='2.7')100 def test_2x_style_invalid_1(self):101 self.invalid_syntax("raise E, V, T, Z", version='2.7')102 def test_3x_style(self):103 parse("raise E1 from E2")104 def test_3x_style_invalid_1(self):105 self.invalid_syntax("raise E, V from E1")106 def test_3x_style_invalid_2(self):107 self.invalid_syntax("raise E from E1, E2")108 def test_3x_style_invalid_3(self):109 self.invalid_syntax("raise from E1, E2")110 def test_3x_style_invalid_4(self):111 self.invalid_syntax("raise E from")112# Adapted from Python 3's Lib/test/ TestFunctionAnnotations(GrammarTest):114 def test_1(self):115 parse("""def f(x) -> list: pass""")116 def test_2(self):117 parse("""def f(x:int): pass""")118 def test_3(self):119 parse("""def f(*x:str): pass""")120 def test_4(self):121 parse("""def f(**x:float): pass""")122 def test_5(self):123 parse("""def f(x, y:1+2): pass""")124 def test_6(self):125 self.invalid_syntax("""def f(a, (b:1, c:2, d)): pass""")126 def test_7(self):127 self.invalid_syntax("""def f(a, (b:1, c:2, d), e:3=4, f=5, *g:6): pass""")128 def test_8(self):129 s = """def f(a, (b:1, c:2, d), e:3=4, f=5,130 *g:6, h:7, i=8, j:9=10, **k:11) -> 12: pass"""131 self.invalid_syntax(s)132class TestExcept(GrammarTest):133 def test_new(self):134 s = """135 try:136 x137 except E as N:138 y"""139 parse(s)140 def test_old(self):141 s = """142 try:143 x144 except E, N:145 y"""146 parse(s, version='2.7')147# Adapted from Python 3's Lib/test/ TestSetLiteral(GrammarTest):149 def test_1(self):150 parse("""x = {'one'}""")151 def test_2(self):152 parse("""x = {'one', 1,}""")153 def test_3(self):154 parse("""x = {'one', 'two', 'three'}""")155 def test_4(self):156 parse("""x = {2, 3, 4,}""")157class TestNumericLiterals(GrammarTest):158 def test_new_octal_notation(self):159 code = """0o7777777777777"""160 if is_py3:161 parse(code)162 else:163 self.invalid_syntax(code)164 self.invalid_syntax("""0o7324528887""")165 def test_new_binary_notation(self):166 parse("""0b101010""")167 self.invalid_syntax("""0b0101021""")168class TestClassDef(GrammarTest):169 def test_new_syntax(self):170 parse("class B(t=7): pass")171 parse("class B(t, *args): pass")172 parse("class B(t, **kwargs): pass")173 parse("class B(t, *args, **kwargs): pass")174 parse("class B(t, y=9, *args, **kwargs): pass")175class TestParserIdempotency(TestCase):176 """A cut-down version of"""177 def test_extended_unpacking(self):178 parse("a, *b, c = x\n")179 parse("[*a, b] = x\n")180 parse("(z, *y, w) = m\n")181 parse("for *z, m in d: pass\n")...

Full Screen

Full Screen Github


Full Screen

...23 self.assertEqual(t.children[1].children[0].type, syms.print_stmt)24class GrammarTest(support.TestCase):25 def validate(self, code):26 support.parse_string(code)27 def invalid_syntax(self, code):28 try:29 self.validate(code)30 except ParseError:31 pass32 else:33 raise AssertionError("Syntax shouldn't have been valid")34class TestMatrixMultiplication(GrammarTest):35 def test_matrix_multiplication_operator(self):36 self.validate("a @ b")37 self.validate("a @= b")38class TestYieldFrom(GrammarTest):39 def test_matrix_multiplication_operator(self):40 self.validate("yield from x")41 self.validate("(yield from x) + y")42 self.invalid_syntax("yield from")43class TestRaiseChanges(GrammarTest):44 def test_2x_style_1(self):45 self.validate("raise")46 def test_2x_style_2(self):47 self.validate("raise E, V")48 def test_2x_style_3(self):49 self.validate("raise E, V, T")50 def test_2x_style_invalid_1(self):51 self.invalid_syntax("raise E, V, T, Z")52 def test_3x_style(self):53 self.validate("raise E1 from E2")54 def test_3x_style_invalid_1(self):55 self.invalid_syntax("raise E, V from E1")56 def test_3x_style_invalid_2(self):57 self.invalid_syntax("raise E from E1, E2")58 def test_3x_style_invalid_3(self):59 self.invalid_syntax("raise from E1, E2")60 def test_3x_style_invalid_4(self):61 self.invalid_syntax("raise E from")62# Adaptated from Python 3's Lib/test/ TestFunctionAnnotations(GrammarTest):64 def test_1(self):65 self.validate("""def f(x) -> list: pass""")66 def test_2(self):67 self.validate("""def f(x:int): pass""")68 def test_3(self):69 self.validate("""def f(*x:str): pass""")70 def test_4(self):71 self.validate("""def f(**x:float): pass""")72 def test_5(self):73 self.validate("""def f(x, y:1+2): pass""")74 def test_6(self):75 self.validate("""def f(a, (b:1, c:2, d)): pass""")76 def test_7(self):77 self.validate("""def f(a, (b:1, c:2, d), e:3=4, f=5, *g:6): pass""")78 def test_8(self):79 s = """def f(a, (b:1, c:2, d), e:3=4, f=5,80 *g:6, h:7, i=8, j:9=10, **k:11) -> 12: pass"""81 self.validate(s)82class TestExcept(GrammarTest):83 def test_new(self):84 s = """85 try:86 x87 except E as N:88 y"""89 self.validate(s)90 def test_old(self):91 s = """92 try:93 x94 except E, N:95 y"""96 self.validate(s)97# Adapted from Python 3's Lib/test/ TestSetLiteral(GrammarTest):99 def test_1(self):100 self.validate("""x = {'one'}""")101 def test_2(self):102 self.validate("""x = {'one', 1,}""")103 def test_3(self):104 self.validate("""x = {'one', 'two', 'three'}""")105 def test_4(self):106 self.validate("""x = {2, 3, 4,}""")107class TestNumericLiterals(GrammarTest):108 def test_new_octal_notation(self):109 self.validate("""0o7777777777777""")110 self.invalid_syntax("""0o7324528887""")111 def test_new_binary_notation(self):112 self.validate("""0b101010""")113 self.invalid_syntax("""0b0101021""")114class TestClassDef(GrammarTest):115 def test_new_syntax(self):116 self.validate("class B(t=7): pass")117 self.validate("class B(t, *args): pass")118 self.validate("class B(t, **kwargs): pass")119 self.validate("class B(t, *args, **kwargs): pass")120 self.validate("class B(t, y=9, *args, **kwargs): pass")121class TestParserIdempotency(support.TestCase):122 """A cut-down version of"""123 def test_all_project_files(self):124 if sys.platform.startswith("win"):125 # XXX something with newlines goes wrong on Windows.126 return127 for filepath in support.all_project_files():...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:


You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run autotest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?