Skip to content

Commit

Permalink
Move remaining tests to new framework (#10856)
Browse files Browse the repository at this point in the history
## Summary

This PR moves the remaining tests to the resources directory. The reason
this was remaining is because it's all mainly with item tests which I
was working on at that moment. I've removed duplicate test cases and
moved only the unique ones.
  • Loading branch information
dhruvmanila committed Apr 16, 2024
1 parent 75304d2 commit 5ed7d0e
Show file tree
Hide file tree
Showing 17 changed files with 2,480 additions and 3,598 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
a: type X = int
lambda: type X = int
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
with (item1, item2), as f: ...
with (item1, item2), item3,: ...
with (*item): ...
with (*item) as f: ...
with (item := 10 as f): ...
with (item1, item2 := 10 as f): ...
with (x for x in range(10), item): ...
Expand All @@ -16,8 +17,16 @@
with (*x for x in iter, item): ...
with (item1, *x for x in iter, item2): ...
with (x as f, *y): ...
with (*x, y as f): ...
with (x, yield y): ...
with (x, yield y, z): ...
with (x, yield from y): ...
with (x as f, y) as f: ...
with (x for x in iter as y): ...
with (x for x in iter as y): ...

# The inner `(...)` is parsed as parenthesized expression
with ((item as f)): ...

with (item as f), x: ...
with (item as f1) as f2: ...
with (item1 as f, item2 := 0): ...
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# For parenthesized with items test cases, refer to `./ambiguous_lpar_with_items.py`

with item,: pass
with item as x,: pass
with *item: pass
with *item as x: pass
with *item1, item2 as f: pass
with item1 as f, *item2: pass
with item := 0 as f: pass
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@
# parenthesize the with items or part of a parenthesized expression. It's not to test the
# with statement itself.

# Simple unparenthesized cases
with item: ...
with item as f: ...

# The following sections basically separates between which node does the
# start parenthesis belongs to.

Expand All @@ -17,16 +13,20 @@
# - The range of the first with item shouldn't include the parenthesis.
with (item): ...
with (item,): ... # with a trailing comma
with (((item))): ...
with (item1, item2): ...
with (item1, item2,): ... # with a trailing comma
with ((item1), (item2), item3 as f, (item4)): ...
with ((item1, item2), item3): ...
with ((x, y) as f): ...
with (item1 as f1, item2 as f2): ...
with (item1 as f1, item2 as f2,): ... # with a trailing comma
with (item == 10,): ...
with ((item := 10)): ...
with ((item := 10,)): ...
with ((*item,)): ...
with ((item1 := 10), item2): ...
with (item1 as f, (item2 := 10)): ...
with (foo()): ...
with (foo(),): ...
with (foo() as f): ...
Expand All @@ -46,6 +46,7 @@
# - The range of the first with item should include the parenthesis.
with (item) as f: ...
with (item := 10): ...
with (item := 10) as f: ...
with ( item := 1 ): ...
with (item1 := 42), item2: ...
with (root + filename).read(): ... # Postfix expression
Expand All @@ -57,7 +58,11 @@
with (1, 2, 3)[0]: ... # Postfix expression
with (1, 2, 3)[0] as f: ... # Postfix expression
with (item1), (item2): ...
with (open('a.py')), (open('b.py')): ...
with (yield x): ...
with ((yield x)): ...
with (yield from x): ...
with ((yield from x)): ...
with (yield x) as f: ...
with (yield x,) as f: ...

Expand All @@ -77,6 +82,7 @@
with (item1, item2 := 2, item3) as f: ...
with (item,) as f: ...
with (*item,): ...
with (*item,) as f: ...
with (item1, item2) as f: ...
with (item1, item2,) as f: ...
with (item1, item2), item3: ...
Expand Down
16 changes: 14 additions & 2 deletions crates/ruff_python_parser/resources/valid/statement/with.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,14 @@
with 1 as x:
pass
# This file only contains unparenthesized with items. Refer to ./ambiguous_lpar_with_items.py
# for parenthesized with items test cases

with item: ...
with item as f: ...
with item1, item2: ...
with item1 as f1, item2 as f2: ...

with x if True else y: ...
with x if True else y as f: ...

# Postfix expressions
with open() as f: ...
with open() as f.attr: ...
4 changes: 4 additions & 0 deletions crates/ruff_python_parser/src/parser/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -931,6 +931,10 @@ impl<'src> Parser<'src> {
// x: yield a = 1
// x: yield from b = 1
// x: y := int = 1

// test_err ann_assign_stmt_type_alias_annotation
// a: type X = int
// lambda: type X = int
let annotation = self.parse_conditional_expression_or_higher(AllowStarredExpression::No);

let value = if self.eat(TokenKind::Equal) {
Expand Down
3 changes: 0 additions & 3 deletions crates/ruff_python_parser/src/parser/tests.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
mod parser;
mod suite;

use crate::{lex, parse, parse_suite, parse_tokens, Mode};

#[test]
Expand Down
57 changes: 0 additions & 57 deletions crates/ruff_python_parser/src/parser/tests/parser.rs

This file was deleted.

Loading

0 comments on commit 5ed7d0e

Please sign in to comment.