Skip to content

Commit

Permalink
Add tests and update the refs.
Browse files Browse the repository at this point in the history
  • Loading branch information
Thirumalai-Shaktivel committed Sep 5, 2022
1 parent 3aa78c6 commit f0205e8
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 9 deletions.
7 changes: 7 additions & 0 deletions tests/parser/async1.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()())
10 changes: 7 additions & 3 deletions tests/parser/statements2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down
4 changes: 2 additions & 2 deletions tests/reference/ast_new-async1-b3d07ed.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/reference/ast_new-async1-b3d07ed.stdout
Original file line number Diff line number Diff line change
@@ -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) [] []) [] []))))] [] () ())] [])
4 changes: 2 additions & 2 deletions tests/reference/ast_new-statements2-c4cdc5f.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/reference/ast_new-statements2-c4cdc5f.stdout
Original file line number Diff line number Diff line change
@@ -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))] [] () ())] [])

0 comments on commit f0205e8

Please sign in to comment.