Skip to content

Commit

Permalink
fix: assertTrue()/assertFalse() fixer should not test for identity
Browse files Browse the repository at this point in the history
Issue #2456
  • Loading branch information
spaceone committed Feb 2, 2023
1 parent 668860c commit 2a98164
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
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))
}
}
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

0 comments on commit 2a98164

Please sign in to comment.