mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-03 18:28:24 +00:00
fix: assertTrue()/assertFalse() fixer should not test for identity (#2476)
This commit is contained in:
parent
668860cba3
commit
8e53a4d1d3
2 changed files with 15 additions and 12 deletions
|
@ -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))
|
||||
Ok(if matches!(self, UnittestAssert::False) {
|
||||
let unary_expr = create_expr(ExprKind::UnaryOp {
|
||||
op: Unaryop::Not,
|
||||
operand: Box::new(create_expr(expr.node.clone())),
|
||||
});
|
||||
assert(&unary_expr, msg)
|
||||
} else {
|
||||
assert(expr, msg)
|
||||
})
|
||||
}
|
||||
UnittestAssert::Equal
|
||||
| UnittestAssert::Equals
|
||||
|
|
|
@ -13,7 +13,7 @@ expression: diagnostics
|
|||
column: 23
|
||||
fix:
|
||||
content:
|
||||
- assert expr is True
|
||||
- assert expr
|
||||
location:
|
||||
row: 11
|
||||
column: 8
|
||||
|
@ -32,7 +32,7 @@ expression: diagnostics
|
|||
column: 23
|
||||
fix:
|
||||
content:
|
||||
- assert expr is True
|
||||
- assert expr
|
||||
location:
|
||||
row: 12
|
||||
column: 8
|
||||
|
@ -51,7 +51,7 @@ expression: diagnostics
|
|||
column: 23
|
||||
fix:
|
||||
content:
|
||||
- assert expr is True
|
||||
- assert expr
|
||||
location:
|
||||
row: 13
|
||||
column: 8
|
||||
|
@ -70,7 +70,7 @@ expression: diagnostics
|
|||
column: 23
|
||||
fix:
|
||||
content:
|
||||
- "assert expr is True, msg"
|
||||
- "assert expr, msg"
|
||||
location:
|
||||
row: 14
|
||||
column: 8
|
||||
|
@ -89,7 +89,7 @@ expression: diagnostics
|
|||
column: 23
|
||||
fix:
|
||||
content:
|
||||
- "assert expr is True, msg"
|
||||
- "assert expr, msg"
|
||||
location:
|
||||
row: 15
|
||||
column: 8
|
||||
|
@ -152,7 +152,7 @@ expression: diagnostics
|
|||
column: 24
|
||||
fix:
|
||||
content:
|
||||
- assert True is False
|
||||
- assert not True
|
||||
location:
|
||||
row: 22
|
||||
column: 8
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue