Skip to content

Commit f8493dc

Browse files
committed
Add some unit tests
1 parent 9b3b0d2 commit f8493dc

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

conda_forge_tick/migrators/recipe_v1.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ def is_negated_condition(a: str, b: str) -> bool:
4141
return True
4242

4343
# A == B <-> A != B
44-
if a == b.replace("==", "!=") or a == b.replace("!=", "=="):
44+
if "==" in b and a == b.replace("==", "!=", 1):
45+
return True
46+
if "!=" in b and a == b.replace("!=", "==", 1):
4547
return True
4648

4749
return False

tests/test_recipe_v1.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
from pathlib import Path
22

33
from flaky import flaky
4+
import pytest
45
from test_migrators import run_test_migration
56

67
from conda_forge_tick.migrators import (
78
CombineV1ConditionsMigrator,
89
Version,
910
)
11+
from conda_forge_tick.migrators.recipe_v1 import (
12+
is_single_expression,
13+
is_negated_condition,
14+
)
1015

1116
YAML_PATH = Path(__file__).parent / "test_v1_yaml"
1217

@@ -16,6 +21,49 @@
1621
)
1722

1823

24+
@pytest.mark.parametrize("x", [
25+
"win",
26+
"not unix",
27+
'cuda_compiler_version == "None"',
28+
"build_platform != target_platform",
29+
])
30+
def test_is_single_expression(x):
31+
assert is_single_expression(x)
32+
33+
34+
@pytest.mark.parametrize("x", [
35+
'cuda_compiler_version != "None" and linux"',
36+
'unix and blas_impl != "mkl"',
37+
"linux or osx",
38+
"foo if bar else baz",
39+
])
40+
def test_not_is_single_expression(x):
41+
assert not is_single_expression(x)
42+
43+
44+
@pytest.mark.parametrize("a,b", [
45+
("unix", "not unix"),
46+
('cuda_compiler_version == "None"', 'not cuda_compiler_version == "None"'),
47+
('cuda_compiler_version == "None"', 'cuda_compiler_version != "None"'),
48+
('not cuda_compiler_version == "None"', 'not cuda_compiler_version != "None"'),
49+
])
50+
def test_is_negated_condition(a, b):
51+
assert is_negated_condition(a, b)
52+
assert is_negated_condition(b, a)
53+
54+
55+
@pytest.mark.parametrize("a,b", [
56+
("not unix", "not unix"),
57+
('cuda_compiler_version == "None"', 'not cuda_compiler_version != "None"'),
58+
('cuda_compiler_version != "None"', 'not cuda_compiler_version == "None"'),
59+
("a or b", "not a or b"),
60+
("a and b", "not a and b"),
61+
])
62+
def test_not_is_negated_condition(a, b):
63+
assert not is_negated_condition(a, b)
64+
assert not is_negated_condition(b, a)
65+
66+
1967
@flaky
2068
def test_combine_v1_conditions(tmp_path):
2169
run_test_migration(

0 commit comments

Comments
 (0)