Skip to content

Commit

Permalink
add: refactor dynamic default tests to use xpath, extra test cases
Browse files Browse the repository at this point in the history
- deleted tests where covered by case in TestDynamicDefaultSimpleInput
- updated tests using string matchers to use xpath instead
- added pyxform_test_case ability to escape literal pipe in values
- clarified existing translation performance test description
- added util function for coalesce
- added tests suggested by @lognaturel and performance tests
- updated test strategy for cases that initially or after rendering
  contain single quotes, namely to use xpath_exact to compare outside
  of xpath, instead of xpath_match.
  • Loading branch information
lindsay-stevens committed Apr 14, 2022
1 parent 72b1880 commit ba7b196
Show file tree
Hide file tree
Showing 5 changed files with 683 additions and 371 deletions.
5 changes: 5 additions & 0 deletions pyxform/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,7 @@ def get_expression_lexer() -> re.Scanner: # noqa
"CLOSE_PAREN": r"\)",
"BRACKET": r"\[\]\{\}",
"PARENT_REF": r"\.\.",
"SELF_REF": r"\.",
"PATH_SEP": r"\/", # javarosa.xpath says "//" is an "unsupported construct".
"SYSTEM_LITERAL": r""""[^"]*"|'[^']*'""",
"COMMA": r",",
Expand Down Expand Up @@ -428,3 +429,7 @@ def parse_expression(text: str) -> Tuple[List[ExpLexerToken], str]:
"""
tokens, remainder = EXPRESSION_LEXER.scan(text)
return tokens, remainder


def coalesce(*args):
return next((a for a in args if a is not None), None)
3 changes: 2 additions & 1 deletion tests/pyxform_test_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ def assertPyxformXform(self, **kwargs):
one of these possible survey input types
* md: (str) a markdown formatted xlsform (easy to read in code)
[consider a plugin to help with formatting md tables,
e.g. https://github.com/vkocubinsky/SublimeTableEditor]
e.g. https://github.com/vkocubinsky/SublimeTableEditor].
Escape a literal pipe value with a single back-slash.
* ss_structure: (dict) a python dictionary with sheets and their
contents. best used in cases where testing whitespace and
cells' type is important
Expand Down
Loading

0 comments on commit ba7b196

Please sign in to comment.