summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul McGuire <ptmcg@austin.rr.com>2019-01-05 22:47:45 -0600
committerPaul McGuire <ptmcg@austin.rr.com>2019-01-05 22:47:45 -0600
commitfe13dce382ce888455d8f946faf1caa23a0363a5 (patch)
tree677309ddf1b8242c552e496a988d0cffccadd0f4
parent1c573befa15f61cadbb285a3b3f8d7a6c199fe93 (diff)
downloadpyparsing-git-fe13dce382ce888455d8f946faf1caa23a0363a5.tar.gz
Convert exception logging to use ParseException.explain()
-rw-r--r--simple_unit_tests.py12
1 files changed, 7 insertions, 5 deletions
diff --git a/simple_unit_tests.py b/simple_unit_tests.py
index 875ded7..f13ff07 100644
--- a/simple_unit_tests.py
+++ b/simple_unit_tests.py
@@ -29,6 +29,7 @@ class PyparsingExpressionTestCase(unittest.TestCase):
given text strings. Subclasses must define a class attribute 'tests' which
is a list of PpTestSpec instances.
"""
+ tests = []
def runTest(self):
if self.__class__ is PyparsingExpressionTestCase:
return
@@ -71,12 +72,13 @@ class PyparsingExpressionTestCase(unittest.TestCase):
else:
# expect fail
- with self.assertRaises(pp.ParseException) as ar:
+ try:
parsefn(test_spec.text)
- print(' ', test_spec.text or "''")
- print(' ', ' '*ar.exception.loc+'^')
- print(' ', ar.exception.msg)
- self.assertEqual(ar.exception.loc, test_spec.expected_fail_locn)
+ except Exception as exc:
+ print(pp.ParseException.explain(exc))
+ self.assertEqual(exc.loc, test_spec.expected_fail_locn)
+ else:
+ self.assertTrue(False, "failed to raise expected exception")
#=========== TEST DEFINITIONS START HERE ==============