Skip to content

Commit

Permalink
new test fixture match_many
Browse files Browse the repository at this point in the history
  • Loading branch information
Upabjojr committed Mar 23, 2019
1 parent a7821d1 commit 8cdfa44
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
13 changes: 13 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ def pytest_generate_tests(metafunc):
metafunc.parametrize('match', ['one-to-one', 'many-to-one', 'generated'], indirect=True)
if 'match_syntactic' in metafunc.fixturenames:
metafunc.parametrize('match_syntactic', ['one-to-one', 'many-to-one', 'syntactic', 'generated'], indirect=True)
if 'match_many' in metafunc.fixturenames:
metafunc.parametrize('match_many', ['many-to-one', 'generated'], indirect=True)


def match_many_to_one(expression, *patterns):
Expand Down Expand Up @@ -94,3 +96,14 @@ def match_syntactic(request):
return match_generated
else:
raise ValueError("Invalid internal test config")


@pytest.fixture
def match_many(request):
pytest.matcher = request.param
if request.param == 'many-to-one':
return match_many_to_one
elif request.param == 'generated':
return match_generated
else:
raise ValueError("Invalid internal test config")
10 changes: 3 additions & 7 deletions tests/test_matching.py
Original file line number Diff line number Diff line change
Expand Up @@ -815,24 +815,20 @@ def test_selective_constraint(self, match):
assert {'x': Symbol('aa')} in result
assert {'x': Symbol('bb')} in result

def test_double_custom_constraint(self, match):
def test_double_custom_constraint(self, match_many):
constraint1 = CustomConstraint(lambda x, y: (x > 0) and (y > 0))
constraint2 = CustomConstraint(lambda x, y: (x > 0) or (y > 0))

pattern1 = Pattern(f(x_, a, y_), constraint1)
pattern2 = Pattern(f(x_, b, y_), constraint2)

subject1 = f(3, a, 4)
try:
result = list(match(subject1, pattern1, pattern2))
except TypeError:
# Some tests do not support multiple patterns, skip:
return
result = list(match_many(subject1, pattern1, pattern2))
assert len(result) == 1
assert {'x': 3, 'y': 4} in result

subject2 = f(3, b, 4)
result = list(match(subject2, pattern1, pattern2))
result = list(match_many(subject2, pattern1, pattern2))
assert len(result) == 1
assert {'x': 3, 'y': 4} in result

Expand Down

0 comments on commit 8cdfa44

Please sign in to comment.