Skip to content

Commit

Permalink
Add applicability to flake8_pytest_style (#5389)
Browse files Browse the repository at this point in the history
  • Loading branch information
evanrittenhouse authored Jun 27, 2023
1 parent 1ed227a commit 0585e14
Show file tree
Hide file tree
Showing 14 changed files with 48 additions and 64 deletions.
3 changes: 1 addition & 2 deletions crates/ruff/src/rules/flake8_pytest_style/rules/assertion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,7 @@ pub(crate) fn unittest_assertion(
&& !has_comments_in(expr.range(), checker.locator)
{
if let Ok(stmt) = unittest_assert.generate_assert(args, keywords) {
#[allow(deprecated)]
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
diagnostic.set_fix(Fix::suggested(Edit::range_replacement(
checker.generator().stmt(&stmt),
expr.range(),
)));
Expand Down
15 changes: 5 additions & 10 deletions crates/ruff/src/rules/flake8_pytest_style/rules/fixture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,7 @@ fn check_fixture_decorator(checker: &mut Checker, func_name: &str, decorator: &D
&& args.is_empty()
&& keywords.is_empty()
{
#[allow(deprecated)]
let fix = Fix::unspecified(Edit::deletion(func.end(), decorator.end()));
let fix = Fix::automatic(Edit::deletion(func.end(), decorator.end()));
pytest_fixture_parentheses(
checker,
decorator,
Expand Down Expand Up @@ -346,8 +345,7 @@ fn check_fixture_decorator(checker: &mut Checker, func_name: &str, decorator: &D
if checker.enabled(Rule::PytestFixtureIncorrectParenthesesStyle)
&& checker.settings.flake8_pytest_style.fixture_parentheses
{
#[allow(deprecated)]
let fix = Fix::unspecified(Edit::insertion(
let fix = Fix::automatic(Edit::insertion(
Parentheses::Empty.to_string(),
decorator.end(),
));
Expand Down Expand Up @@ -406,8 +404,7 @@ fn check_fixture_returns(checker: &mut Checker, stmt: &Stmt, name: &str, body: &
stmt.range(),
);
if checker.patch(diagnostic.kind.rule()) {
#[allow(deprecated)]
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
diagnostic.set_fix(Fix::automatic(Edit::range_replacement(
"return".to_string(),
TextRange::at(stmt.start(), "yield".text_len()),
)));
Expand Down Expand Up @@ -486,8 +483,7 @@ fn check_fixture_marks(checker: &mut Checker, decorators: &[Decorator]) {
Diagnostic::new(PytestUnnecessaryAsyncioMarkOnFixture, expr.range());
if checker.patch(diagnostic.kind.rule()) {
let range = checker.locator.full_lines_range(expr.range());
#[allow(deprecated)]
diagnostic.set_fix(Fix::unspecified(Edit::range_deletion(range)));
diagnostic.set_fix(Fix::automatic(Edit::range_deletion(range)));
}
checker.diagnostics.push(diagnostic);
}
Expand All @@ -499,8 +495,7 @@ fn check_fixture_marks(checker: &mut Checker, decorators: &[Decorator]) {
Diagnostic::new(PytestErroneousUseFixturesOnFixture, expr.range());
if checker.patch(diagnostic.kind.rule()) {
let line_range = checker.locator.full_lines_range(expr.range());
#[allow(deprecated)]
diagnostic.set_fix(Fix::unspecified(Edit::range_deletion(line_range)));
diagnostic.set_fix(Fix::automatic(Edit::range_deletion(line_range)));
}
checker.diagnostics.push(diagnostic);
}
Expand Down
9 changes: 3 additions & 6 deletions crates/ruff/src/rules/flake8_pytest_style/rules/marks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,13 @@ fn check_mark_parentheses(checker: &mut Checker, decorator: &Decorator, call_pat
&& args.is_empty()
&& keywords.is_empty()
{
#[allow(deprecated)]
let fix = Fix::unspecified(Edit::deletion(func.end(), decorator.end()));
let fix = Fix::automatic(Edit::deletion(func.end(), decorator.end()));
pytest_mark_parentheses(checker, decorator, call_path, fix, "", "()");
}
}
_ => {
if checker.settings.flake8_pytest_style.mark_parentheses {
#[allow(deprecated)]
let fix = Fix::unspecified(Edit::insertion("()".to_string(), decorator.end()));
let fix = Fix::automatic(Edit::insertion("()".to_string(), decorator.end()));
pytest_mark_parentheses(checker, decorator, call_path, fix, "()", "");
}
}
Expand All @@ -114,8 +112,7 @@ fn check_useless_usefixtures(checker: &mut Checker, decorator: &Decorator, call_
if !has_parameters {
let mut diagnostic = Diagnostic::new(PytestUseFixturesWithoutParameters, decorator.range());
if checker.patch(diagnostic.kind.rule()) {
#[allow(deprecated)]
diagnostic.set_fix(Fix::unspecified(Edit::range_deletion(decorator.range())));
diagnostic.set_fix(Fix::suggested(Edit::range_deletion(decorator.range())));
}
checker.diagnostics.push(diagnostic);
}
Expand Down
21 changes: 7 additions & 14 deletions crates/ruff/src/rules/flake8_pytest_style/rules/parametrize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,7 @@ fn check_names(checker: &mut Checker, decorator: &Decorator, expr: &Expr) {
ctx: ExprContext::Load,
range: TextRange::default(),
});
#[allow(deprecated)]
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
diagnostic.set_fix(Fix::suggested(Edit::range_replacement(
format!("({})", checker.generator().expr(&node)),
name_range,
)));
Expand Down Expand Up @@ -195,8 +194,7 @@ fn check_names(checker: &mut Checker, decorator: &Decorator, expr: &Expr) {
ctx: ExprContext::Load,
range: TextRange::default(),
});
#[allow(deprecated)]
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
diagnostic.set_fix(Fix::suggested(Edit::range_replacement(
checker.generator().expr(&node),
name_range,
)));
Expand Down Expand Up @@ -228,8 +226,7 @@ fn check_names(checker: &mut Checker, decorator: &Decorator, expr: &Expr) {
ctx: ExprContext::Load,
range: TextRange::default(),
});
#[allow(deprecated)]
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
diagnostic.set_fix(Fix::suggested(Edit::range_replacement(
checker.generator().expr(&node),
expr.range(),
)));
Expand All @@ -245,8 +242,7 @@ fn check_names(checker: &mut Checker, decorator: &Decorator, expr: &Expr) {
);
if checker.patch(diagnostic.kind.rule()) {
if let Some(content) = elts_to_csv(elts, checker.generator()) {
#[allow(deprecated)]
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
diagnostic.set_fix(Fix::suggested(Edit::range_replacement(
content,
expr.range(),
)));
Expand Down Expand Up @@ -278,8 +274,7 @@ fn check_names(checker: &mut Checker, decorator: &Decorator, expr: &Expr) {
ctx: ExprContext::Load,
range: TextRange::default(),
});
#[allow(deprecated)]
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
diagnostic.set_fix(Fix::suggested(Edit::range_replacement(
format!("({})", checker.generator().expr(&node)),
expr.range(),
)));
Expand All @@ -295,8 +290,7 @@ fn check_names(checker: &mut Checker, decorator: &Decorator, expr: &Expr) {
);
if checker.patch(diagnostic.kind.rule()) {
if let Some(content) = elts_to_csv(elts, checker.generator()) {
#[allow(deprecated)]
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
diagnostic.set_fix(Fix::suggested(Edit::range_replacement(
content,
expr.range(),
)));
Expand Down Expand Up @@ -373,8 +367,7 @@ fn handle_single_name(checker: &mut Checker, expr: &Expr, value: &Expr) {

if checker.patch(diagnostic.kind.rule()) {
let node = value.clone();
#[allow(deprecated)]
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
diagnostic.set_fix(Fix::automatic(Edit::range_replacement(
checker.generator().expr(&node),
expr.range(),
)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ PT001.py:9:1: PT001 [*] Use `@pytest.fixture()` over `@pytest.fixture`
|
= help: Add parentheses

Suggested fix
Fix
6 6 | # `import pytest`
7 7 |
8 8 |
Expand All @@ -29,7 +29,7 @@ PT001.py:34:1: PT001 [*] Use `@pytest.fixture()` over `@pytest.fixture`
|
= help: Add parentheses

Suggested fix
Fix
31 31 | # `from pytest import fixture`
32 32 |
33 33 |
Expand All @@ -48,7 +48,7 @@ PT001.py:59:1: PT001 [*] Use `@pytest.fixture()` over `@pytest.fixture`
|
= help: Add parentheses

Suggested fix
Fix
56 56 | # `from pytest import fixture as aliased`
57 57 |
58 58 |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ PT001.py:14:1: PT001 [*] Use `@pytest.fixture` over `@pytest.fixture()`
|
= help: Remove parentheses

Suggested fix
Fix
11 11 | return 42
12 12 |
13 13 |
Expand All @@ -31,7 +31,7 @@ PT001.py:24:1: PT001 [*] Use `@pytest.fixture` over `@pytest.fixture()`
|
= help: Remove parentheses

Suggested fix
Fix
21 21 | return 42
22 22 |
23 23 |
Expand All @@ -52,7 +52,7 @@ PT001.py:39:1: PT001 [*] Use `@pytest.fixture` over `@pytest.fixture()`
|
= help: Remove parentheses

Suggested fix
Fix
36 36 | return 42
37 37 |
38 38 |
Expand All @@ -73,7 +73,7 @@ PT001.py:49:1: PT001 [*] Use `@pytest.fixture` over `@pytest.fixture()`
|
= help: Remove parentheses

Suggested fix
Fix
46 46 | return 42
47 47 |
48 48 |
Expand All @@ -94,7 +94,7 @@ PT001.py:64:1: PT001 [*] Use `@pytest.fixture` over `@pytest.fixture()`
|
= help: Remove parentheses

Suggested fix
Fix
61 61 | return 42
62 62 |
63 63 |
Expand All @@ -115,7 +115,7 @@ PT001.py:74:1: PT001 [*] Use `@pytest.fixture` over `@pytest.fixture()`
|
= help: Remove parentheses

Suggested fix
Fix
71 71 | return 42
72 72 |
73 73 |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ PT006.py:29:26: PT006 [*] Wrong name(s) type in `@pytest.mark.parametrize`, expe
|
= help: Use a `csv` for parameter names

Suggested fix
Fix
26 26 | ...
27 27 |
28 28 |
Expand Down Expand Up @@ -67,7 +67,7 @@ PT006.py:39:26: PT006 [*] Wrong name(s) type in `@pytest.mark.parametrize`, expe
|
= help: Use a `csv` for parameter names

Suggested fix
Fix
36 36 | ...
37 37 |
38 38 |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ PT006.py:29:26: PT006 [*] Wrong name(s) type in `@pytest.mark.parametrize`, expe
|
= help: Use a `csv` for parameter names

Suggested fix
Fix
26 26 | ...
27 27 |
28 28 |
Expand Down Expand Up @@ -105,7 +105,7 @@ PT006.py:39:26: PT006 [*] Wrong name(s) type in `@pytest.mark.parametrize`, expe
|
= help: Use a `csv` for parameter names

Suggested fix
Fix
36 36 | ...
37 37 |
38 38 |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ PT006.py:29:26: PT006 [*] Wrong name(s) type in `@pytest.mark.parametrize`, expe
|
= help: Use a `csv` for parameter names

Suggested fix
Fix
26 26 | ...
27 27 |
28 28 |
Expand All @@ -105,7 +105,7 @@ PT006.py:39:26: PT006 [*] Wrong name(s) type in `@pytest.mark.parametrize`, expe
|
= help: Use a `csv` for parameter names

Suggested fix
Fix
36 36 | ...
37 37 |
38 38 |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ PT022.py:17:5: PT022 [*] No teardown in fixture `error`, use `return` instead of
|
= help: Replace `yield` with `return`

Suggested fix
Fix
14 14 | @pytest.fixture()
15 15 | def error():
16 16 | resource = acquire_resource()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ PT023.py:12:1: PT023 [*] Use `@pytest.mark.foo()` over `@pytest.mark.foo`
|
= help: Add/remove parentheses

Suggested fix
Fix
9 9 | # Without parentheses
10 10 |
11 11 |
Expand All @@ -29,7 +29,7 @@ PT023.py:17:1: PT023 [*] Use `@pytest.mark.foo()` over `@pytest.mark.foo`
|
= help: Add/remove parentheses

Suggested fix
Fix
14 14 | pass
15 15 |
16 16 |
Expand All @@ -49,7 +49,7 @@ PT023.py:24:5: PT023 [*] Use `@pytest.mark.foo()` over `@pytest.mark.foo`
|
= help: Add/remove parentheses

Suggested fix
Fix
21 21 |
22 22 |
23 23 | class TestClass:
Expand All @@ -69,7 +69,7 @@ PT023.py:30:5: PT023 [*] Use `@pytest.mark.foo()` over `@pytest.mark.foo`
|
= help: Add/remove parentheses

Suggested fix
Fix
27 27 |
28 28 |
29 29 | class TestClass:
Expand All @@ -90,7 +90,7 @@ PT023.py:38:9: PT023 [*] Use `@pytest.mark.foo()` over `@pytest.mark.foo`
|
= help: Add/remove parentheses

Suggested fix
Fix
35 35 |
36 36 | class TestClass:
37 37 | class TestNestedClass:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ PT023.py:46:1: PT023 [*] Use `@pytest.mark.foo` over `@pytest.mark.foo()`
|
= help: Add/remove parentheses

Suggested fix
Fix
43 43 | # With parentheses
44 44 |
45 45 |
Expand All @@ -29,7 +29,7 @@ PT023.py:51:1: PT023 [*] Use `@pytest.mark.foo` over `@pytest.mark.foo()`
|
= help: Add/remove parentheses

Suggested fix
Fix
48 48 | pass
49 49 |
50 50 |
Expand All @@ -49,7 +49,7 @@ PT023.py:58:5: PT023 [*] Use `@pytest.mark.foo` over `@pytest.mark.foo()`
|
= help: Add/remove parentheses

Suggested fix
Fix
55 55 |
56 56 |
57 57 | class TestClass:
Expand All @@ -69,7 +69,7 @@ PT023.py:64:5: PT023 [*] Use `@pytest.mark.foo` over `@pytest.mark.foo()`
|
= help: Add/remove parentheses

Suggested fix
Fix
61 61 |
62 62 |
63 63 | class TestClass:
Expand All @@ -90,7 +90,7 @@ PT023.py:72:9: PT023 [*] Use `@pytest.mark.foo` over `@pytest.mark.foo()`
|
= help: Add/remove parentheses

Suggested fix
Fix
69 69 |
70 70 | class TestClass:
71 71 | class TestNestedClass:
Expand Down
Loading

0 comments on commit 0585e14

Please sign in to comment.