-
-
Notifications
You must be signed in to change notification settings - Fork 217
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert "yield" tests to parametrized tests
pytest does not support yield tests anymore because they do not work in a system where test collection is separate from test running.
- Loading branch information
Showing
28 changed files
with
934 additions
and
984 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
209 changes: 93 additions & 116 deletions
209
corehq/apps/case_search/tests/test_subcase_query_parser.py
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 |
---|---|---|
@@ -1,125 +1,102 @@ | ||
import pytest | ||
from eulxml.xpath import parse as parse_xpath | ||
from testil import eq, assert_raises | ||
|
||
from corehq.apps.case_search.exceptions import XPathFunctionException | ||
from corehq.apps.case_search.xpath_functions.subcase_functions import _parse_normalize_subcase_query | ||
|
||
|
||
def test_subcase_query_parsing(): | ||
def _check(query, expected): | ||
node = parse_xpath(query) | ||
result = _parse_normalize_subcase_query(node) | ||
eq(result.as_tuple(), expected) | ||
@pytest.mark.parametrize("query, expected", [ | ||
( | ||
"subcase-exists('parent', @case_type='bob')", | ||
("parent", "@case_type='bob'", ">", 0, False) | ||
), | ||
( | ||
"subcase-exists('p', @case_type='bob' and prop='value')", | ||
("p", "@case_type='bob' and prop='value'", ">", 0, False) | ||
), | ||
( | ||
"subcase-count('p', prop=1) > 3", | ||
("p", "prop=1", ">", 3, False) | ||
), | ||
( | ||
"subcase-count('p', prop=1) >= 3", | ||
("p", "prop=1", ">", 2, False) | ||
), | ||
( | ||
"subcase-count('p', prop=1) < 3", | ||
("p", "prop=1", ">", 2, True) | ||
), | ||
( | ||
"subcase-count('p', prop=1) <= 3", | ||
("p", "prop=1", ">", 3, True) | ||
), | ||
( | ||
"subcase-count('p', prop=1) = 3", | ||
("p", "prop=1", "=", 3, False) | ||
), | ||
( | ||
"subcase-count('p', prop=1) = 0", | ||
("p", "prop=1", ">", 0, True) | ||
), | ||
( | ||
"subcase-count('p', prop=1) != 2", | ||
("p", "prop=1", "=", 2, True) | ||
), | ||
( | ||
"subcase-count('p') = 2", | ||
("p", None, "=", 2, False) | ||
), | ||
( | ||
"subcase-exists('p')", | ||
("p", None, ">", 0, False) | ||
), | ||
]) | ||
def test_subcase_query_parsing(query, expected): | ||
node = parse_xpath(query) | ||
result = _parse_normalize_subcase_query(node) | ||
eq(result.as_tuple(), expected) | ||
|
||
yield from [ | ||
( | ||
_check, | ||
"subcase-exists('parent', @case_type='bob')", | ||
("parent", "@case_type='bob'", ">", 0, False) | ||
), | ||
( | ||
_check, | ||
"subcase-exists('p', @case_type='bob' and prop='value')", | ||
("p", "@case_type='bob' and prop='value'", ">", 0, False) | ||
), | ||
( | ||
_check, | ||
"subcase-count('p', prop=1) > 3", | ||
("p", "prop=1", ">", 3, False) | ||
), | ||
( | ||
_check, | ||
"subcase-count('p', prop=1) >= 3", | ||
("p", "prop=1", ">", 2, False) | ||
), | ||
( | ||
_check, | ||
"subcase-count('p', prop=1) < 3", | ||
("p", "prop=1", ">", 2, True) | ||
), | ||
( | ||
_check, | ||
"subcase-count('p', prop=1) <= 3", | ||
("p", "prop=1", ">", 3, True) | ||
), | ||
( | ||
_check, | ||
"subcase-count('p', prop=1) = 3", | ||
("p", "prop=1", "=", 3, False) | ||
), | ||
( | ||
_check, | ||
"subcase-count('p', prop=1) = 0", | ||
("p", "prop=1", ">", 0, True) | ||
), | ||
( | ||
_check, | ||
"subcase-count('p', prop=1) != 2", | ||
("p", "prop=1", "=", 2, True) | ||
), | ||
( | ||
_check, | ||
"subcase-count('p') = 2", | ||
("p", None, "=", 2, False) | ||
), | ||
( | ||
_check, | ||
"subcase-exists('p')", | ||
("p", None, ">", 0, False) | ||
), | ||
] | ||
|
||
|
||
def test_subcase_query_parsing_validations(): | ||
def _check(query, msg): | ||
node = parse_xpath(query) | ||
with assert_raises(XPathFunctionException, msg=msg): | ||
_parse_normalize_subcase_query(node) | ||
|
||
yield from [ | ||
( | ||
_check, | ||
"subcase-exists()", | ||
"'subcase-exists' expects one or two arguments" | ||
), | ||
( | ||
_check, | ||
"subcase-count() > 1", | ||
"'subcase-count' expects one or two arguments" | ||
), | ||
( | ||
_check, | ||
"subcase-count()", | ||
"XPath incorrectly formatted. Expected 'subcase-exists'" | ||
), | ||
( | ||
_check, | ||
"subcase-count('p', name = 'bob') > -1", | ||
"'subcase-count' must be compared to a positive integer" | ||
), | ||
( | ||
_check, | ||
"subcase-count('p', name = 'bob') + 1", | ||
"Unsupported operator for use with 'subcase-count': +" | ||
), | ||
( | ||
_check, | ||
"subcase-count('p', name = 'bob') > 'bob'", | ||
"'subcase-count' must be compared to a positive integer" | ||
), | ||
( | ||
_check, | ||
"subcase-count('p', name = 'bob') > date('2020-01-01')", | ||
"'subcase-count' must be compared to a positive integer" | ||
), | ||
( | ||
_check, | ||
"subcase-count(parent) = 1", | ||
"'subcase-count' error. Index identifier must be a string" | ||
), | ||
( | ||
_check, | ||
"subcase-exists(3)", | ||
"'subcase-exists' error. Index identifier must be a string" | ||
), | ||
] | ||
@pytest.mark.parametrize("query, msg", [ | ||
( | ||
"subcase-exists()", | ||
"'subcase-exists' expects one or two arguments" | ||
), | ||
( | ||
"subcase-count() > 1", | ||
"'subcase-count' expects one or two arguments" | ||
), | ||
( | ||
"subcase-count()", | ||
"XPath incorrectly formatted. Expected 'subcase-exists'" | ||
), | ||
( | ||
"subcase-count('p', name = 'bob') > -1", | ||
"'subcase-count' must be compared to a positive integer" | ||
), | ||
( | ||
"subcase-count('p', name = 'bob') + 1", | ||
"Unsupported operator for use with 'subcase-count': +" | ||
), | ||
( | ||
"subcase-count('p', name = 'bob') > 'bob'", | ||
"'subcase-count' must be compared to a positive integer" | ||
), | ||
( | ||
"subcase-count('p', name = 'bob') > date('2020-01-01')", | ||
"'subcase-count' must be compared to a positive integer" | ||
), | ||
( | ||
"subcase-count(parent) = 1", | ||
"'subcase-count' error. Index identifier must be a string" | ||
), | ||
( | ||
"subcase-exists(3)", | ||
"'subcase-exists' error. Index identifier must be a string" | ||
), | ||
]) | ||
def test_subcase_query_parsing_validations(query, msg): | ||
node = parse_xpath(query) | ||
with assert_raises(XPathFunctionException, msg=msg): | ||
_parse_normalize_subcase_query(node) |
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
Oops, something went wrong.