diff options
author | Paul McGuire <ptmcg@austin.rr.com> | 2016-01-18 03:57:38 +0000 |
---|---|---|
committer | Paul McGuire <ptmcg@austin.rr.com> | 2016-01-18 03:57:38 +0000 |
commit | 07e75554e0228bf872e194e633c4cb0508edfd4c (patch) | |
tree | 80c5e4c12cc3159cda56ee990bb801bdb981596a /src/unitTests.py | |
parent | ffe44eedb91ca1fd98e491e99566210a46818b8e (diff) | |
download | pyparsing-git-07e75554e0228bf872e194e633c4cb0508edfd4c.tar.gz |
Fix _trim_arity to distinguish between TypeErrors raised in parse actions and those raised during internal arity testing
Diffstat (limited to 'src/unitTests.py')
-rw-r--r-- | src/unitTests.py | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/src/unitTests.py b/src/unitTests.py index ab40888..cf840eb 100644 --- a/src/unitTests.py +++ b/src/unitTests.py @@ -2363,6 +2363,19 @@ class SetNameTest(ParseTestCase): tname = str(t)
assert tname==e, "expression name mismatch, expected {} got {}".format(e, tname)
+class TrimArityExceptionMaskingTest(ParseTestCase):
+ def runTest(self):
+ from pyparsing import Word
+
+ invalid_message = [
+ "<lambda>() takes exactly 1 argument (0 given)",
+ "<lambda>() missing 1 required positional argument: 't'"
+ ][PY_3]
+ try:
+ Word('a').setParseAction(lambda t: t[0]+1).parseString('aaa')
+ except Exception as e:
+ exc_msg = str(e)
+ assert exc_msg != invalid_message, "failed to catch TypeError thrown in _trim_arity"
class MiscellaneousParserTests(ParseTestCase):
def runTest(self):
@@ -2577,6 +2590,7 @@ def makeTestSuite(): suite.addTest( EachWithOptionalWithResultsNameTest() )
suite.addTest( UnicodeExpressionTest() )
suite.addTest( SetNameTest() )
+ suite.addTest( TrimArityExceptionMaskingTest() )
suite.addTest( MiscellaneousParserTests() )
if TEST_USING_PACKRAT:
# retest using packrat parsing (disable those tests that aren't compatible)
@@ -2613,7 +2627,7 @@ if console: testRunner = TextTestRunner()
testRunner.run( makeTestSuite() )
- #~ testclass = SetNameTest
+ #~ testclass = TrimArityExceptionMaskingTest
#~ if lp is None:
#~ testRunner.run( makeTestSuiteTemp(testclass) )
#~ else:
|