Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: assertTrue()/assertFalse() fixer should not test for identity #2476

Merged
merged 2 commits into from
Feb 2, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix: assertTrue()/assertFalse() fixer should not test for identity
Issue #2456
  • Loading branch information
spaceone committed Feb 2, 2023
commit 2a98164623a89d254022cf83d09d3fbed0878071
15 changes: 9 additions & 6 deletions src/rules/flake8_pytest_style/rules/unittest_assert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,12 +265,15 @@ impl UnittestAssert {
.get("expr")
.ok_or_else(|| anyhow!("Missing argument `expr`"))?;
let msg = args.get("msg").copied();
let bool = create_expr(ExprKind::Constant {
value: Constant::Bool(matches!(self, UnittestAssert::True)),
kind: None,
});
let expr = compare(expr, Cmpop::Is, &bool);
Ok(assert(&expr, msg))
if matches!(self, UnittestAssert::False) {
let unary_expr = create_expr(ExprKind::UnaryOp {
op: Unaryop::Not,
operand: Box::new(create_expr(expr.node.clone())),
});
Ok(assert(&unary_expr, msg))
} else {
Ok(assert(expr, msg))
spaceone marked this conversation as resolved.
Show resolved Hide resolved
}
}
UnittestAssert::Equal
| UnittestAssert::Equals
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ expression: diagnostics
column: 23
fix:
content:
- assert expr is True
- assert expr
location:
row: 11
column: 8
Expand All @@ -32,7 +32,7 @@ expression: diagnostics
column: 23
fix:
content:
- assert expr is True
- assert expr
location:
row: 12
column: 8
Expand All @@ -51,7 +51,7 @@ expression: diagnostics
column: 23
fix:
content:
- assert expr is True
- assert expr
location:
row: 13
column: 8
Expand All @@ -70,7 +70,7 @@ expression: diagnostics
column: 23
fix:
content:
- "assert expr is True, msg"
- "assert expr, msg"
location:
row: 14
column: 8
Expand All @@ -89,7 +89,7 @@ expression: diagnostics
column: 23
fix:
content:
- "assert expr is True, msg"
- "assert expr, msg"
location:
row: 15
column: 8
Expand Down Expand Up @@ -152,7 +152,7 @@ expression: diagnostics
column: 24
fix:
content:
- assert True is False
- assert not True
location:
row: 22
column: 8
Expand Down