diff options
author | Paul McGuire <ptmcg@austin.rr.com> | 2018-12-30 09:32:30 -0600 |
---|---|---|
committer | Paul McGuire <ptmcg@austin.rr.com> | 2018-12-30 09:32:30 -0600 |
commit | 3d1ada6a3379e48f8da34971da8be22be39324e5 (patch) | |
tree | ba46c1aa082574ee8b198389db76dce1c3afdec6 /examples | |
parent | c3bb1856f94fe393d209d3dd95af718526497a04 (diff) | |
download | pyparsing-git-3d1ada6a3379e48f8da34971da8be22be39324e5.tar.gz |
Update Travis-CI scripts to include examples; fix bug in runTests if postParse function returns None (or any non-str value)
Diffstat (limited to 'examples')
-rw-r--r-- | examples/lucene_grammar.py | 3 | ||||
-rw-r--r-- | examples/romanNumerals.py | 27 | ||||
-rw-r--r-- | examples/sexpParser.py | 17 |
3 files changed, 25 insertions, 22 deletions
diff --git a/examples/lucene_grammar.py b/examples/lucene_grammar.py index 0cd7e0d..2791b7c 100644 --- a/examples/lucene_grammar.py +++ b/examples/lucene_grammar.py @@ -317,3 +317,6 @@ success1, _ = expression.runTests(tests) success2, _ = expression.runTests(failtests, failureTests=True)
print(("FAIL", "OK")[success1 and success2])
+
+if not (success1 and success2):
+ raise Exception("failure in lucene grammar parser, check output")
diff --git a/examples/romanNumerals.py b/examples/romanNumerals.py index 536fbb0..0f15ac8 100644 --- a/examples/romanNumerals.py +++ b/examples/romanNumerals.py @@ -52,17 +52,26 @@ def makeRomanNumeral(n): return ret
tests = " ".join(makeRomanNumeral(i) for i in range(1,5000+1))
+roman_int_map = {}
expected = 1
for t,s,e in romanNumeral.scanString(tests):
+ orig = tests[s:e]
if t[0] != expected:
- print("{} {} {}".format("==>", t, tests[s:e]))
+ print("{} {} {}".format("==>", t, orig))
+ roman_int_map[orig] = t[0]
expected += 1
-def test(rn):
- print("{} -> {}".format(rn, romanNumeral.parseString(rn)[0]))
-test("XVI")
-test("XXXIX")
-test("XIV")
-test("XIX")
-test("MCMLXXX")
-test("MMVI")
+def verify_value(s, tokens):
+ expected = roman_int_map[s]
+ if tokens[0] != expected:
+ raise Exception("incorrect value for {} ({}), expected {}".format(s, tokens[0], expected ))
+
+romanNumeral.runTests("""\
+ XVI
+ XXXIX
+ XIV
+ XIX
+ MCMLXXX
+ MMVI
+ """, fullDump=False,
+ postParse=verify_value)
\ No newline at end of file diff --git a/examples/sexpParser.py b/examples/sexpParser.py index 86fb089..123b401 100644 --- a/examples/sexpParser.py +++ b/examples/sexpParser.py @@ -139,8 +139,8 @@ test07 = """(defun factorial (x) (if (zerop x) 1
(* x (factorial (- x 1)))))
"""
-test51 = """(2:XX "abc" (#30# |YWJj|))"""
-test51error = """(3:XX "abc" (#30# |YWJj|))"""
+test51 = """(2:XX "abc" (#03# |YWJj|))"""
+test51error = """(3:XX "abc" (#03# |YWJj|))"""
test52 = """
(and
@@ -153,15 +153,6 @@ test52 = """ # Run tests
t = None
-alltests = [ locals()[t] for t in sorted(locals()) if t.startswith("test") ]
+alltests = [ globals()[t] for t in sorted(locals()) if t.startswith("test") ]
-for t in alltests:
- print('-'*50)
- print(t)
- try:
- sexpr = sexp.parseString(t, parseAll=True)
- pprint.pprint(sexpr.asList())
- except ParseFatalException as pfe:
- print("Error:", pfe.msg)
- print(pfe.markInputline('^'))
- print()
+sexp.runTests(alltests, fullDump=False)
|