class ParseTestCase(TestCase):
def __init__(self):
super(ParseTestCase, self).__init__(methodName='_runTest')
+ self.expect_traceback = False
+ self.expect_warning = False
def _runTest(self):
print_("<<<< End of test",str(self))
print_()
+ output = buffered_stdout.getvalue()
+ if "Traceback" in output and not self.expect_traceback:
+ raise Exception("traceback in stdout")
+ if "Warning" in output and not self.expect_warning:
+ raise Exception("warning in stdout")
+
except Exception as exc:
if BUFFER_OUTPUT:
print_()
class CustomQuotesTest(ParseTestCase):
def runTest(self):
+ self.expect_warning = True
+
from pyparsing import QuotedString
testString = r"""
class ParseUsingRegex(ParseTestCase):
def runTest(self):
+ self.expect_warning = True
import re
class RegexSubTest(ParseTestCase):
def runTest(self):
+ self.expect_warning = True
import pyparsing as pp
print_("test sub with string")
for r, exp in zip(results, expected):
if exp is not None:
- self.assertEquals(r[1].mismatches, exp,
- "fail CloseMatch between %r and %r" % (searchseq.match_string, r[0]))
+ self.assertEqual(r[1].mismatches, exp,
+ "fail CloseMatch between %r and %r" % (searchseq.match_string, r[0]))
print_(r[0], 'exc: %s' % r[1] if exp is None and isinstance(r[1], Exception)
else ("no match", "match")[r[1].mismatches == exp])
class ParseActionExceptionTest(ParseTestCase):
def runTest(self):
+ self.expect_traceback = True
+
import pyparsing as pp
import traceback
with self.assertWarns(UserWarning, msg="failed to warn of And within alternation"):
expr = (expr_a | expr_b)('rexp')
else:
+ self.expect_warning = True
expr = (expr_a | expr_b)('rexp')
expr.runTests("""
not the bird
with self.assertWarns(UserWarning, msg="failed to warn of And within alternation"):
expr = (expr_a ^ expr_b)('rexp')
else:
+ self.expect_warning = True
expr = (expr_a ^ expr_b)('rexp')
expr.runTests("""\
not the bird
" ungrouped named expressions"):
path = coord[...].setResultsName('path')
+ pp.__diag__.warn_ungrouped_named_tokens_in_collection = False
+
class WarnNameSetOnEmptyForwardTest(ParseTestCase):
"""
""")
output = test_stdout.getvalue()
print_(output)
- self.assertEquals(output,
- expected_debug_output,
- "failed to auto-enable debug on named expressions "
- "using enable_debug_on_named_expressions")
+ self.assertEqual(output,
+ expected_debug_output,
+ "failed to auto-enable debug on named expressions "
+ "using enable_debug_on_named_expressions")
class UndesirableButCommonPracticesTest(ParseTestCase):
class MiscellaneousParserTests(ParseTestCase):
def runTest(self):
+ self.expect_warning = True
runtests = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
if IRON_PYTHON_ENV: