From f0205e8c77e94e05170ecea823a7d64ef4bb1b84 Mon Sep 17 00:00:00 2001 From: Thirumalai-Shaktivel Date: Mon, 5 Sep 2022 15:44:21 +0530 Subject: [PATCH] Add tests and update the refs. --- tests/parser/async1.py | 7 +++++++ tests/parser/statements2.py | 10 +++++++--- tests/reference/ast_new-async1-b3d07ed.json | 4 ++-- tests/reference/ast_new-async1-b3d07ed.stdout | 2 +- tests/reference/ast_new-statements2-c4cdc5f.json | 4 ++-- tests/reference/ast_new-statements2-c4cdc5f.stdout | 2 +- 6 files changed, 20 insertions(+), 9 deletions(-) diff --git a/tests/parser/async1.py b/tests/parser/async1.py index 7e49d95e59..28a64ebc8d 100644 --- a/tests/parser/async1.py +++ b/tests/parser/async1.py @@ -24,3 +24,10 @@ async def test_02(): [s for c in [f(''), f('abc'), f(''), f(['de', 'fg'])] for s in await c] return (i * 2 for i in range(n) if await wrap(i)) + +async def t(): + results.append(await anext(g)) + self.assertIn('...', repr(await asyncio.wait_for(func(), timeout=10))) + x = -await bar() + return (await bar() + await wrap()() + await db['b']()()() + + await bar() * 1000 + await DB.b()()) diff --git a/tests/parser/statements2.py b/tests/parser/statements2.py index 489d382064..dfc9e908b3 100644 --- a/tests/parser/statements2.py +++ b/tests/parser/statements2.py @@ -20,14 +20,18 @@ [x for x in G if self.ring.is_unit(x[0])][0] if x not in\ - z: ... + z: ... if (x not in\ - z): ... + z): ... if x not\ in\ - z: ... + z: ... + +if (x not in + z): ... + def imatmul(a, b): "Same as a @= b." diff --git a/tests/reference/ast_new-async1-b3d07ed.json b/tests/reference/ast_new-async1-b3d07ed.json index 0bc7083951..db04b2aed7 100644 --- a/tests/reference/ast_new-async1-b3d07ed.json +++ b/tests/reference/ast_new-async1-b3d07ed.json @@ -2,11 +2,11 @@ "basename": "ast_new-async1-b3d07ed", "cmd": "lpython --show-ast --new-parser --no-color {infile} -o {outfile}", "infile": "tests/parser/async1.py", - "infile_hash": "d089cff932e221cd4faac8d2802e18e16833322a746eea933291caf7", + "infile_hash": "7c5dba5bb5fe728a9452de16f8164730885146b2d93e49be8642d96a", "outfile": null, "outfile_hash": null, "stdout": "ast_new-async1-b3d07ed.stdout", - "stdout_hash": "4447a9366a389765da43bf8ae8cef7ec165c2cf8e8925ced842bbc66", + "stdout_hash": "1580c6f5bca7b5bd74f5cca0f2dc7f165fe454d2a19f12897ea133bd", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/ast_new-async1-b3d07ed.stdout b/tests/reference/ast_new-async1-b3d07ed.stdout index 15e0d93c46..3896a13631 100644 --- a/tests/reference/ast_new-async1-b3d07ed.stdout +++ b/tests/reference/ast_new-async1-b3d07ed.stdout @@ -1 +1 @@ -(Module [(AsyncFunctionDef func ([] [(param1 () ()) (param2 () ())] [] [] [] [] []) [(Expr (Await (Call (Attribute (Name asyncio Load) sleep Load) [(ConstantInt 1 ())] []))) (Expr (Call (Name do_something Load) [] [])) (AsyncFor (Name x Store) (Name y Load) [(Expr (Call (Name do_something Load) [(Name x Load)] []))] [] ()) (AsyncWith [((Call (Name open Load) [(ConstantStr "examples/expr2.py" ()) (ConstantStr "r" ())] []) (Name file Store))] [(Assign [(Name x Store)] (Call (Attribute (Name file Load) read Load) [] []) ())] ())] [] () ()) (AsyncFunctionDef test_01 ([] [] [] [] [] [] []) [(Assign [(Name results Store)] (Await (Call (Attribute (Name tasks Load) gather Load) [(Starred (ListComp (Call (Attribute (Name ag Load) aclose Load) [] []) [((Name ag Store) (Name closing_agens Load) [] 0)]) Load)] [(return_exceptions (ConstantBool .true. ()))])) ()) (With [((Await (Name lock Load)) ())] [(Pass)] ()) (AugAssign (Name data Store) Add (Await (Call (Attribute (Attribute (Name self Load) loop Load) sock_recv Load) [(Name sock Load) (Name DATA_SIZE Load)] []))) (Return (Await (Call (Attribute (Name self Load) run_in_executor Load) [(ConstantNone ()) (Name getaddr_func Load) (Name host Load) (Name port Load) (Name family Load) (Name type Load) (Name proto Load) (Name flags Load)] [])))] [] () ()) (AsyncFunctionDef test_02 ([] [] [] [] [] [] []) [(Assign [(Name items Store)] (ListComp (Await (Call (Attribute (Name q Load) get Load) [] [])) [((Name _ Store) (Call (Name range Load) [(ConstantInt 3 ())] []) [] 0)]) ()) (Expr (SetComp (Await (Name c Load)) [((Name c Store) (List [(Call (Name f Load) [(ConstantInt 1 ())] []) (Call (Name f Load) [(ConstantInt 41 ())] [])] Load) [] 0)])) (Expr (DictComp (Name i Load) (Await (Name c Load)) [((Tuple [(Name i Store) (Name c Store)] Store) (Call (Name enumerate Load) [(List [(Call (Name f Load) [(ConstantInt 1 ())] []) (Call (Name f Load) [(ConstantInt 41 ())] [])] Load)] []) [] 0)])) (Expr (ListComp (Name s Load) [((Name c Store) (List [(Call (Name f Load) [(ConstantStr "" ())] []) (Call (Name f Load) [(ConstantStr "abc" ())] []) (Call (Name f Load) [(ConstantStr "" ())] []) (Call (Name f Load) [(List [(ConstantStr "de" ()) (ConstantStr "fg" ())] Load)] [])] Load) [] 0) ((Name s Store) (Await (Name c Load)) [] 0)])) (Return (GeneratorExp (BinOp (Name i Load) Mult (ConstantInt 2 ())) [((Name i Store) (Call (Name range Load) [(Name n Load)] []) [(Await (Call (Name wrap Load) [(Name i Load)] []))] 0)]))] [] () ())] []) +(Module [(AsyncFunctionDef func ([] [(param1 () ()) (param2 () ())] [] [] [] [] []) [(Expr (Await (Call (Attribute (Name asyncio Load) sleep Load) [(ConstantInt 1 ())] []))) (Expr (Call (Name do_something Load) [] [])) (AsyncFor (Name x Store) (Name y Load) [(Expr (Call (Name do_something Load) [(Name x Load)] []))] [] ()) (AsyncWith [((Call (Name open Load) [(ConstantStr "examples/expr2.py" ()) (ConstantStr "r" ())] []) (Name file Store))] [(Assign [(Name x Store)] (Call (Attribute (Name file Load) read Load) [] []) ())] ())] [] () ()) (AsyncFunctionDef test_01 ([] [] [] [] [] [] []) [(Assign [(Name results Store)] (Await (Call (Attribute (Name tasks Load) gather Load) [(Starred (ListComp (Call (Attribute (Name ag Load) aclose Load) [] []) [((Name ag Store) (Name closing_agens Load) [] 0)]) Load)] [(return_exceptions (ConstantBool .true. ()))])) ()) (With [((Await (Name lock Load)) ())] [(Pass)] ()) (AugAssign (Name data Store) Add (Await (Call (Attribute (Attribute (Name self Load) loop Load) sock_recv Load) [(Name sock Load) (Name DATA_SIZE Load)] []))) (Return (Await (Call (Attribute (Name self Load) run_in_executor Load) [(ConstantNone ()) (Name getaddr_func Load) (Name host Load) (Name port Load) (Name family Load) (Name type Load) (Name proto Load) (Name flags Load)] [])))] [] () ()) (AsyncFunctionDef test_02 ([] [] [] [] [] [] []) [(Assign [(Name items Store)] (ListComp (Await (Call (Attribute (Name q Load) get Load) [] [])) [((Name _ Store) (Call (Name range Load) [(ConstantInt 3 ())] []) [] 0)]) ()) (Expr (SetComp (Await (Name c Load)) [((Name c Store) (List [(Call (Name f Load) [(ConstantInt 1 ())] []) (Call (Name f Load) [(ConstantInt 41 ())] [])] Load) [] 0)])) (Expr (DictComp (Name i Load) (Await (Name c Load)) [((Tuple [(Name i Store) (Name c Store)] Store) (Call (Name enumerate Load) [(List [(Call (Name f Load) [(ConstantInt 1 ())] []) (Call (Name f Load) [(ConstantInt 41 ())] [])] Load)] []) [] 0)])) (Expr (ListComp (Name s Load) [((Name c Store) (List [(Call (Name f Load) [(ConstantStr "" ())] []) (Call (Name f Load) [(ConstantStr "abc" ())] []) (Call (Name f Load) [(ConstantStr "" ())] []) (Call (Name f Load) [(List [(ConstantStr "de" ()) (ConstantStr "fg" ())] Load)] [])] Load) [] 0) ((Name s Store) (Await (Name c Load)) [] 0)])) (Return (GeneratorExp (BinOp (Name i Load) Mult (ConstantInt 2 ())) [((Name i Store) (Call (Name range Load) [(Name n Load)] []) [(Await (Call (Name wrap Load) [(Name i Load)] []))] 0)]))] [] () ()) (AsyncFunctionDef t ([] [] [] [] [] [] []) [(Expr (Call (Attribute (Name results Load) append Load) [(Await (Call (Name anext Load) [(Name g Load)] []))] [])) (Expr (Call (Attribute (Name self Load) assertIn Load) [(ConstantStr "..." ()) (Call (Name repr Load) [(Await (Call (Attribute (Name asyncio Load) wait_for Load) [(Call (Name func Load) [] [])] [(timeout (ConstantInt 10 ()))]))] [])] [])) (Assign [(Name x Store)] (UnaryOp USub (Await (Call (Name bar Load) [] []))) ()) (Return (BinOp (BinOp (BinOp (BinOp (Await (Call (Name bar Load) [] [])) Add (Await (Call (Call (Name wrap Load) [] []) [] []))) Add (Await (Call (Call (Call (Subscript (Name db Load) (ConstantStr "b" ()) Load) [] []) [] []) [] []))) Add (BinOp (Await (Call (Name bar Load) [] [])) Mult (ConstantInt 1000 ()))) Add (Await (Call (Call (Attribute (Name DB Load) b Load) [] []) [] []))))] [] () ())] []) diff --git a/tests/reference/ast_new-statements2-c4cdc5f.json b/tests/reference/ast_new-statements2-c4cdc5f.json index 16125edd77..138050e88f 100644 --- a/tests/reference/ast_new-statements2-c4cdc5f.json +++ b/tests/reference/ast_new-statements2-c4cdc5f.json @@ -2,11 +2,11 @@ "basename": "ast_new-statements2-c4cdc5f", "cmd": "lpython --show-ast --new-parser --no-color {infile} -o {outfile}", "infile": "tests/parser/statements2.py", - "infile_hash": "3be5c5c199bae9d20d51a30cb785a08faa69aa7cb13f18aae44ffe01", + "infile_hash": "8c96f6788e951a113e775f497394a372018d04b4f7f910d304471017", "outfile": null, "outfile_hash": null, "stdout": "ast_new-statements2-c4cdc5f.stdout", - "stdout_hash": "b740926cb114f97c24252d42bc2a0a1b374c3c3d6f286c9d869f1512", + "stdout_hash": "24a915b924b34f39fd72c541e9132c6e887faee540d6a9f5f63b0b4e", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/ast_new-statements2-c4cdc5f.stdout b/tests/reference/ast_new-statements2-c4cdc5f.stdout index a12aba9dab..80fafe2e2c 100644 --- a/tests/reference/ast_new-statements2-c4cdc5f.stdout +++ b/tests/reference/ast_new-statements2-c4cdc5f.stdout @@ -1 +1 @@ -(Module [(Expr (Call (Call (Call (Name getattr Load) [(Name x Load) (Name y Load)] []) [(Name a Load) (Name b Load)] []) [(ConstantInt 5 ())] [(a (Name a Load)) (b (ConstantInt 0 ()))])) (Expr (Call (Call (Name func Load) [(Name a Load) (Name _op Load)] []) [(Name s Load)] [])) (Expr (Call (Call (Name test Load) [] []) [] [])) (Assign [(Name a Store)] (Subscript (List [(ConstantInt 1 ()) (ConstantInt 2 ())] Load) (ConstantInt 0 ()) Load) ()) (Assign [(Tuple [(Name a Store) (Name b Store)] Store)] (Subscript (BinOp (List [(ConstantInt 1 ()) (ConstantInt 2 ())] Load) Add (List [(ConstantInt 0 ()) (ConstantInt 0 ())] Load)) (Slice () (ConstantInt 2 ()) ()) Load) ()) (Assign [(Tuple [(Name a Store) (Name b Store)] Store)] (Subscript (BinOp (Call (Attribute (Name c Load) d Load) [] []) Add (List [(ConstantInt 1 ()) (ConstantInt 0 ())] Load)) (Slice () () ()) Load) ()) (Expr (Subscript (Dict [(ConstantStr "a" ()) (ConstantStr "b" ())] [(Name a Load) (Name b Load)]) (Name val Load) Load)) (If (Compare (Subscript (Subscript (Name args Load) (Name i Load) Load) (Slice () (ConstantInt 1 ()) ()) Load) In [(List [(ConstantStr "" ()) (ConstantStr "." ())] Load)]) [(Pass)] []) (Assign [(Name x Store)] (List [(Subscript (ListComp (BinOp (UnaryOp USub (Name c Load)) Mod (Name self Load)) [((Name c Store) (Call (Name reversed Load) [(Attribute (Attribute (Name T Load) rep Load) rep Load)] []) [] 0)]) (Slice () (UnaryOp USub (ConstantInt 1 ())) ()) Load)] Load) ()) (Expr (Subscript (ListComp (Name x Load) [((Name x Store) (Name G Load) [(Call (Attribute (Attribute (Name self Load) ring Load) is_unit Load) [(Subscript (Name x Load) (ConstantInt 0 ()) Load)] [])] 0)]) (ConstantInt 0 ()) Load)) (If (Compare (Name x Load) NotIn [(Name z Load)]) [(Expr (ConstantEllipsis ()))] []) (If (Compare (Name x Load) NotIn [(Name z Load)]) [(Expr (ConstantEllipsis ()))] []) (If (Compare (Name x Load) NotIn [(Name z Load)]) [(Expr (ConstantEllipsis ()))] []) (FunctionDef imatmul ([] [(a () ()) (b () ())] [] [] [] [] []) [(Expr (ConstantStr "Same as a @= b." ())) (AugAssign (Name a Store) MatMult (Name b Load)) (Return (Name a Load))] [] () ())] []) +(Module [(Expr (Call (Call (Call (Name getattr Load) [(Name x Load) (Name y Load)] []) [(Name a Load) (Name b Load)] []) [(ConstantInt 5 ())] [(a (Name a Load)) (b (ConstantInt 0 ()))])) (Expr (Call (Call (Name func Load) [(Name a Load) (Name _op Load)] []) [(Name s Load)] [])) (Expr (Call (Call (Name test Load) [] []) [] [])) (Assign [(Name a Store)] (Subscript (List [(ConstantInt 1 ()) (ConstantInt 2 ())] Load) (ConstantInt 0 ()) Load) ()) (Assign [(Tuple [(Name a Store) (Name b Store)] Store)] (Subscript (BinOp (List [(ConstantInt 1 ()) (ConstantInt 2 ())] Load) Add (List [(ConstantInt 0 ()) (ConstantInt 0 ())] Load)) (Slice () (ConstantInt 2 ()) ()) Load) ()) (Assign [(Tuple [(Name a Store) (Name b Store)] Store)] (Subscript (BinOp (Call (Attribute (Name c Load) d Load) [] []) Add (List [(ConstantInt 1 ()) (ConstantInt 0 ())] Load)) (Slice () () ()) Load) ()) (Expr (Subscript (Dict [(ConstantStr "a" ()) (ConstantStr "b" ())] [(Name a Load) (Name b Load)]) (Name val Load) Load)) (If (Compare (Subscript (Subscript (Name args Load) (Name i Load) Load) (Slice () (ConstantInt 1 ()) ()) Load) In [(List [(ConstantStr "" ()) (ConstantStr "." ())] Load)]) [(Pass)] []) (Assign [(Name x Store)] (List [(Subscript (ListComp (BinOp (UnaryOp USub (Name c Load)) Mod (Name self Load)) [((Name c Store) (Call (Name reversed Load) [(Attribute (Attribute (Name T Load) rep Load) rep Load)] []) [] 0)]) (Slice () (UnaryOp USub (ConstantInt 1 ())) ()) Load)] Load) ()) (Expr (Subscript (ListComp (Name x Load) [((Name x Store) (Name G Load) [(Call (Attribute (Attribute (Name self Load) ring Load) is_unit Load) [(Subscript (Name x Load) (ConstantInt 0 ()) Load)] [])] 0)]) (ConstantInt 0 ()) Load)) (If (Compare (Name x Load) NotIn [(Name z Load)]) [(Expr (ConstantEllipsis ()))] []) (If (Compare (Name x Load) NotIn [(Name z Load)]) [(Expr (ConstantEllipsis ()))] []) (If (Compare (Name x Load) NotIn [(Name z Load)]) [(Expr (ConstantEllipsis ()))] []) (If (Compare (Name x Load) NotIn [(Name z Load)]) [(Expr (ConstantEllipsis ()))] []) (FunctionDef imatmul ([] [(a () ()) (b () ())] [] [] [] [] []) [(Expr (ConstantStr "Same as a @= b." ())) (AugAssign (Name a Store) MatMult (Name b Load)) (Return (Name a Load))] [] () ())] [])