-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
239 additions
and
210 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,179 @@ | ||
# ruff: noqa | ||
# ruff must not change the AST of the test functions, even if they are semantically equivalent. | ||
|
||
|
||
def signum(x): | ||
s = 0 | ||
if x > 0: | ||
s = 1 | ||
elif x < 0: | ||
s = -1 | ||
return s | ||
|
||
|
||
def signum_no_default(x): | ||
if x > 0: | ||
return 1 | ||
elif x < 0: | ||
return -1 | ||
return 0 | ||
|
||
|
||
def early_return(x): | ||
if x > 0: | ||
return 1 | ||
return 0 | ||
|
||
|
||
def assign_both_branches(x): | ||
if x > 0: | ||
s = 1 | ||
else: | ||
s = -1 | ||
return s | ||
|
||
|
||
def unary_expr(x): | ||
s = -x | ||
return s | ||
|
||
|
||
def call_target_identity(x): | ||
return x | ||
|
||
|
||
def call_expr(x): | ||
k = x * 2 | ||
s = call_target_identity(k + 3) | ||
return s | ||
|
||
|
||
def if_expr(x): | ||
s = 1 if x > 0 else -1 | ||
return s | ||
|
||
|
||
def if_expr2(x): | ||
s = 1 + (x if x > 0 else -1) | ||
return s | ||
|
||
|
||
def if_expr3(x): | ||
s = 1 + ((3 if x < 10 else 5) if x > 0 else -1) | ||
return s | ||
|
||
|
||
def compare_expr(x): | ||
if (0 < x) & (x < 10): | ||
s = 1 | ||
else: | ||
s = 2 | ||
return s | ||
|
||
|
||
def chained_compare_expr(x): | ||
if 0 < x < 10: | ||
s = 1 | ||
else: | ||
s = 2 | ||
return s | ||
|
||
|
||
def walrus_expr(x): | ||
if (y := x + 1) > 0: | ||
s = 1 | ||
else: | ||
s = -1 | ||
return s * y | ||
|
||
|
||
def multiple_if_else(x): | ||
if x > 0: | ||
s = 1 | ||
elif x < 0: | ||
s = -1 | ||
else: | ||
s = 0 | ||
return s | ||
|
||
|
||
def nested_if_else(x): | ||
if x > 0: | ||
if x > 1: | ||
s = 2 | ||
else: | ||
s = 1 | ||
elif x < 0: | ||
s = -1 | ||
else: | ||
s = 0 | ||
return s | ||
|
||
|
||
def nested_if_else_expr(x): | ||
if x > 0: | ||
s = 2 if x > 1 else 1 | ||
elif x < 0: | ||
s = -1 | ||
else: | ||
s = 0 | ||
return s | ||
|
||
|
||
def assignments_inside_branch(x): | ||
if x > 0: | ||
s = 1 | ||
s = s + 1 | ||
s = x * s | ||
elif x < 0: | ||
s = -1 | ||
s = s - 1 | ||
s = x | ||
else: | ||
s = 0 | ||
return s | ||
|
||
|
||
def override_default(x): | ||
s = 0 | ||
if x > 0: | ||
s = 10 | ||
return x * s | ||
|
||
|
||
def no_if_else(x): | ||
s = x * 10 | ||
k = x - 3 | ||
k = k * 2 | ||
return s * k | ||
|
||
|
||
def two_if_expr(x): | ||
a = 1 if x > 0 else 5 | ||
b = 2 if x < 0 else 2 | ||
return a + b | ||
|
||
|
||
functions = [ | ||
signum, | ||
early_return, | ||
assign_both_branches, | ||
unary_expr, | ||
call_expr, | ||
if_expr, | ||
if_expr2, | ||
if_expr3, | ||
compare_expr, | ||
multiple_if_else, | ||
nested_if_else, | ||
nested_if_else_expr, | ||
assignments_inside_branch, | ||
override_default, | ||
no_if_else, | ||
two_if_expr, | ||
] | ||
|
||
xfail_functions = [ | ||
walrus_expr, | ||
signum_no_default, | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import pytest | ||
|
||
from polarify import polarify | ||
|
||
from .functions import chained_compare_expr | ||
|
||
|
||
def test_chained_compare_fail(): | ||
with pytest.raises(ValueError): | ||
polarify(chained_compare_expr) |
Oops, something went wrong.