summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorptmcg <ptmcg@9bf210a0-9d2d-494c-87cf-cfb32e7dff7b>2016-05-13 08:52:57 +0000
committerptmcg <ptmcg@9bf210a0-9d2d-494c-87cf-cfb32e7dff7b>2016-05-13 08:52:57 +0000
commit597291361e0c5d4657cca6362ce5b98dccc40cae (patch)
treeff79b7749d1dc1f71fa6d2dd3713d9144225c3ad
parentd1020860cb9b383679fb11dce35e4086825dc8b5 (diff)
downloadpyparsing-597291361e0c5d4657cca6362ce5b98dccc40cae.tar.gz
Minor enhancement to traceParseAction decorator, to retain the parse action's name for the trace output
Some rework of unitTests.py, to simplify test suite building git-svn-id: svn://svn.code.sf.net/p/pyparsing/code/trunk@346 9bf210a0-9d2d-494c-87cf-cfb32e7dff7b
-rw-r--r--src/CHANGES5
-rw-r--r--src/pyparsing.py12
-rw-r--r--src/unitTests.py90
3 files changed, 42 insertions, 65 deletions
diff --git a/src/CHANGES b/src/CHANGES
index 4be9e1c..1a50a73 100644
--- a/src/CHANGES
+++ b/src/CHANGES
@@ -11,7 +11,7 @@ Version 2.1.4 -
- Expanded capabilities of runTests(). Will now accept embedded
comments (default is Python style, leading '#' character, but
customizable). Comments will be emitted along with the tests and
- test output. Useful test development, to create a test string
+ test output. Useful during test development, to create a test string
consisting only of test case description comments separated by
blank lines, and then fill in the test cases.
@@ -20,6 +20,9 @@ Version 2.1.4 -
class as a sort of embedded namespace, to contain these helpers
without further adding to pyparsing's namespace bloat.
+- Minor enhancement to traceParseAction decorator, to retain the
+ parse action's name for the trace output.
+
Version 2.1.3 - May, 2016
------------------------------
diff --git a/src/pyparsing.py b/src/pyparsing.py
index 18f788a..3c0e13f 100644
--- a/src/pyparsing.py
+++ b/src/pyparsing.py
@@ -58,7 +58,7 @@ The pyparsing module handles some of the problems that are typically vexing when
"""
__version__ = "2.1.4"
-__versionTime__ = "12 May 2016 18:38 UTC"
+__versionTime__ = "13 May 2016 08:50 UTC"
__author__ = "Paul McGuire <ptmcg@users.sourceforge.net>"
import string
@@ -835,6 +835,16 @@ def _trim_arity(func, maxargs=2):
limit[0] += 1
continue
raise
+
+ # copy func name to wrapper for sensible debug output
+ func_name = "<parse action>"
+ try:
+ func_name = getattr(func, '__name__',
+ getattr(func, '__class__').__name__)
+ except Exception:
+ func_name = str(func)
+ wrapper.__name__ = func_name
+
return wrapper
class ParserElement(object):
diff --git a/src/unitTests.py b/src/unitTests.py
index 7edbe8b..9e3bcd2 100644
--- a/src/unitTests.py
+++ b/src/unitTests.py
@@ -2553,6 +2553,23 @@ class NestedAsDictTest(ParseTestCase):
assert result_dict['username'] == 'goat', "failed to process string in ParseResults correctly"
assert result_dict['errors']['username'] == ['already taken', 'too short'], "failed to process nested ParseResults correctly"
+class TraceParseActionDecoratorTest(ParseTestCase):
+ def runTest(self):
+ from pyparsing import traceParseAction, Word, nums
+
+ @traceParseAction
+ def convert_to_int(t):
+ return int(t[0])
+
+ class Z(object):
+ def __call__(self, other):
+ return other[0] * 1000
+
+ integer = Word(nums).addParseAction(convert_to_int)
+ integer.addParseAction(traceParseAction(lambda t: t[0]*10))
+ integer.addParseAction(traceParseAction(Z()))
+ integer.parseString("132")
+
class MiscellaneousParserTests(ParseTestCase):
def runTest(self):
import pyparsing
@@ -2710,69 +2727,16 @@ class MiscellaneousParserTests(ParseTestCase):
def makeTestSuite():
suite = TestSuite()
suite.addTest( PyparsingTestInit() )
- suite.addTest( ParseIDLTest() )
- #suite.addTest( ParseASMLTest() )
- suite.addTest( ParseFourFnTest() )
- suite.addTest( ParseSQLTest() )
- suite.addTest( ParseConfigFileTest() )
- suite.addTest( ParseJSONDataTest() )
- suite.addTest( ParseCommaSeparatedValuesTest() )
- suite.addTest( ParseEBNFTest() )
- suite.addTest( ScanStringTest() )
- suite.addTest( QuotedStringsTest() )
- suite.addTest( CustomQuotesTest() )
- suite.addTest( CaselessOneOfTest() )
- suite.addTest( AsXMLTest() )
- suite.addTest( CommentParserTest() )
- suite.addTest( ParseExpressionResultsTest() )
- suite.addTest( ParseExpressionResultsAccumulateTest() )
- suite.addTest( ReStringRangeTest() )
- suite.addTest( ParseKeywordTest() )
- suite.addTest( ParseHTMLTagsTest() )
- suite.addTest( ParseUsingRegex() )
- suite.addTest( SkipToParserTests() )
- suite.addTest( CountedArrayTest() )
- suite.addTest( CountedArrayTest2() )
- suite.addTest( CountedArrayTest3() )
- suite.addTest( LineAndStringEndTest() )
- suite.addTest( VariableParseActionArgsTest() )
- suite.addTest( RepeaterTest() )
- suite.addTest( RecursiveCombineTest() )
- suite.addTest( InfixNotationGrammarTest1() )
- suite.addTest( InfixNotationGrammarTest2() )
- suite.addTest( InfixNotationGrammarTest3() )
- suite.addTest( InfixNotationGrammarTest4() )
- suite.addTest( ParseResultsPickleTest() )
- suite.addTest( ParseResultsWithNamedTupleTest() )
- suite.addTest( ParseResultsDelTest() )
- suite.addTest( SingleArgExceptionTest() )
- suite.addTest( UpcaseDowncaseUnicode() )
- if not IRON_PYTHON_ENV:
- suite.addTest( OriginalTextForTest() )
- suite.addTest( PackratParsingCacheCopyTest() )
- suite.addTest( PackratParsingCacheCopyTest2() )
- suite.addTest( WithAttributeParseActionTest() )
- suite.addTest( NestedExpressionsTest() )
- suite.addTest( WordBoundaryExpressionsTest() )
- suite.addTest( ParseAllTest() )
- suite.addTest( GreedyQuotedStringsTest() )
- suite.addTest( RequiredEachTest() )
- suite.addTest( OptionalEachTest() )
- suite.addTest( SumParseResultsTest() )
- suite.addTest( WordExcludeTest() )
- suite.addTest( MarkInputLineTest() )
- suite.addTest( LocatedExprTest() )
- suite.addTest( PopTest() )
- suite.addTest( AddConditionTest() )
- suite.addTest( PatientOrTest() )
- suite.addTest( EachWithOptionalWithResultsNameTest() )
- suite.addTest( UnicodeExpressionTest() )
- suite.addTest( SetNameTest() )
- suite.addTest( TrimArityExceptionMaskingTest() )
- suite.addTest( OneOrMoreStopTest() )
- suite.addTest( ZeroOrMoreStopTest() )
- suite.addTest( NestedAsDictTest() )
- suite.addTest( MiscellaneousParserTests() )
+
+ test_case_classes = ParseTestCase.__subclasses__()
+ test_case_classes.remove(PyparsingTestInit)
+ test_case_classes.remove(ParseASMLTest)
+ test_case_classes.remove(EnablePackratParsing)
+ if IRON_PYTHON_ENV:
+ test_case_classes.remove(OriginalTextForTest)
+
+ suite.addTests(T() for T in test_case_classes)
+
if TEST_USING_PACKRAT:
# retest using packrat parsing (disable those tests that aren't compatible)
suite.addTest( EnablePackratParsing() )