From f75feff314812f3821f408cd7134524e2e56293f Mon Sep 17 00:00:00 2001 From: Paul McGuire Date: Thu, 26 Sep 2019 23:16:59 -0500 Subject: Add convenience assert methods (to parse and check list or dict contents in one go) --- pyparsing.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'pyparsing.py') 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 -- cgit v1.2.1