diff options
author | ptmcg <ptmcg@austin.rr.com> | 2018-10-27 03:56:15 -0500 |
---|---|---|
committer | ptmcg <ptmcg@austin.rr.com> | 2018-10-27 03:56:15 -0500 |
commit | ddd2ee7e9fcf5e5b7de6f1672d32ce8e5f94348d (patch) | |
tree | c2c5ff83f5f4a8b5b73198a0791fcc091ea5bbb7 | |
parent | 2fe1bb0be12e9c603bc82d3990b9305c248d99e1 (diff) | |
download | pyparsing-git-ddd2ee7e9fcf5e5b7de6f1672d32ce8e5f94348d.tar.gz |
Add unit test for ParserElement.setBreak()
-rw-r--r-- | unitTests.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/unitTests.py b/unitTests.py index 9a78bf5..0780801 100644 --- a/unitTests.py +++ b/unitTests.py @@ -3596,6 +3596,30 @@ class FollowedByTest(ParseTestCase): assert 'qty' in result, "failed to capture results name in FollowedBy"
assert result.asDict() == {'item': 'balloon', 'qty': 99}, "invalid results name structure from FollowedBy"
+class SetBreakTest(ParseTestCase):
+ """
+ Test behavior of ParserElement.setBreak(), to invoke the debugger before parsing that element is attempted.
+
+ Temporarily monkeypatches pdb.set_trace.
+ """
+ def runTest(self):
+ was_called = []
+ def mock_set_trace():
+ was_called.append(True)
+
+ import pyparsing as pp
+ wd = pp.Word(pp.alphas)
+ wd.setBreak()
+
+ print_("Before parsing with setBreak:", was_called)
+ import pdb
+ with AutoReset(pdb, "set_trace"):
+ pdb.set_trace = mock_set_trace
+ wd.parseString("ABC")
+
+ print_("After parsing with setBreak:", was_called)
+ self.assertTrue(bool(was_called), "set_trace wasn't called by setBreak")
+
class MiscellaneousParserTests(ParseTestCase):
def runTest(self):
|