summaryrefslogtreecommitdiff
path: root/pyparsing.py
diff options
context:
space:
mode:
authorPaul McGuire <ptmcg@austin.rr.com>2019-09-26 23:16:59 -0500
committerPaul McGuire <ptmcg@austin.rr.com>2019-09-26 23:16:59 -0500
commitf75feff314812f3821f408cd7134524e2e56293f (patch)
tree47bbe3786207a81adae4fe9de84d138fe83b04cf /pyparsing.py
parent30a41524ed347662e7e050cc4fd0a873932c4feb (diff)
downloadpyparsing-git-unittest_integration.tar.gz
Add convenience assert methods (to parse and check list or dict contents in one go)unittest_integration
Diffstat (limited to 'pyparsing.py')
-rw-r--r--pyparsing.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/pyparsing.py b/pyparsing.py
index 4f0c829..47d50d6 100644
--- a/pyparsing.py
+++ b/pyparsing.py
@@ -6727,6 +6727,26 @@ class pyparsing_test:
if expected_dict is not None:
self.assertEqual(expected_dict, result.asDict(), msg=msg)
+ def assertParseAndCheckList(self, expr, test_string, expected_list, msg=None, verbose=True):
+ """
+ Convenience wrapper assert to test a parser element and input string, and assert that
+ the resulting ParseResults.asList() is equal to the expected_list.
+ """
+ result = expr.parseString(test_string, parseAll=True)
+ if verbose:
+ print(result.dump())
+ self.assertParseResultsEquals(result, expected_list=expected_list, msg=msg)
+
+ def assertParseAndCheckDict(self, expr, test_string, expected_dict, msg=None, verbose=True):
+ """
+ Convenience wrapper assert to test a parser element and input string, and assert that
+ the resulting ParseResults.asDict() is equal to the expected_dict.
+ """
+ result = expr.parseString(test_string, parseAll=True)
+ if verbose:
+ print(result.dump())
+ self.assertParseResultsEquals(result, expected_dict=expected_dict, msg=msg)
+
def assertRunTestResults(self, run_tests_report, expected_parse_results=None, msg=None):
"""
Unit test assertion to evaluate output of ParserElement.runTests(). If a list of