diff options
author | Jon Dufresne <jon.dufresne@gmail.com> | 2019-11-02 18:15:57 -0700 |
---|---|---|
committer | Paul McGuire <ptmcg@users.noreply.github.com> | 2019-11-02 20:15:57 -0500 |
commit | 094ffc815863fa9aaad48de5ce89477019e1e26c (patch) | |
tree | d0bebc8affab4e3dd6cabe9d30c1de8f8b84da48 | |
parent | 4899103af26ec992ab04d8d222cfb8efe4740e2d (diff) | |
download | pyparsing-git-094ffc815863fa9aaad48de5ce89477019e1e26c.tar.gz |
Use assertRaises for tests that raise exceptions (#160)
-rw-r--r-- | tests/test_unit.py | 51 |
1 files changed, 10 insertions, 41 deletions
diff --git a/tests/test_unit.py b/tests/test_unit.py index d107e9d..070a9d1 100644 --- a/tests/test_unit.py +++ b/tests/test_unit.py @@ -1714,14 +1714,8 @@ class Test2_WithoutPackrat(TestParseResultsAsserts): r"""==sdf\:j=lz::--djf: sl=^^=kfsjf sdlfjs ==sdf\:j=ls::--djf: sl==kfsjf""", ) - try: - bad1 = QuotedString("", "\\") - except SyntaxError as se: - pass - else: - self.assertTrue( - False, "failed to raise SyntaxError with empty quote string" - ) + with self.assertRaises(SyntaxError): + QuotedString("", "\\") def testRepeater(self): from pyparsing import ( @@ -2590,34 +2584,14 @@ class Test2_WithoutPackrat(TestParseResultsAsserts): "incorrect Regex.sub result with callable", ) - try: - expr = pp.Regex(r"<(.*?)>", asMatch=True).sub(lambda m: m.group(1).upper()) - except SyntaxError: - pass - else: - self.assertTrue( - False, "failed to warn using a Regex.sub(callable) with asMatch=True" - ) + with self.assertRaises(SyntaxError): + pp.Regex(r"<(.*?)>", asMatch=True).sub(lambda m: m.group(1).upper()) - try: - expr = pp.Regex(r"<(.*?)>", asGroupList=True).sub( - lambda m: m.group(1).upper() - ) - except SyntaxError: - pass - else: - self.assertTrue( - False, "failed to warn using a Regex.sub() with asGroupList=True" - ) + with self.assertRaises(SyntaxError): + pp.Regex(r"<(.*?)>", asGroupList=True).sub(lambda m: m.group(1).upper()) - try: - expr = pp.Regex(r"<(.*?)>", asGroupList=True).sub("") - except SyntaxError: - pass - else: - self.assertTrue( - False, "failed to warn using a Regex.sub() with asGroupList=True" - ) + with self.assertRaises(SyntaxError): + pp.Regex(r"<(.*?)>", asGroupList=True).sub("") def testPrecededBy(self): import pyparsing as pp @@ -3760,13 +3734,8 @@ class Test2_WithoutPackrat(TestParseResultsAsserts): ) print(result.dump()) - try: - result = exp.parseString("{bar}") - self.assertTrue( - False, "failed to raise exception when required element is missing" - ) - except ParseException as pe: - pass + with self.assertRaises(ParseException): + exp.parseString("{bar}") def testOptionalEachTest4(self): from pyparsing import pyparsing_common, Group |