diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2021-10-30 11:25:40 -0400 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2021-10-30 11:25:40 -0400 |
commit | 19438b7b811ccb4f6c3259f627bfcc0d852e5003 (patch) | |
tree | 620171a0137fa58d59586f92bbb593c6b9419601 | |
parent | 3d962a30a3f659978b96ef59811e8062867b358b (diff) | |
download | python-coveragepy-git-19438b7b811ccb4f6c3259f627bfcc0d852e5003.tar.gz |
test: fix the trailing-space test, and suppress warnings about \<space>
-rw-r--r-- | tests/test_parser.py | 7 | ||||
-rw-r--r-- | tests/test_phystokens.py | 23 |
2 files changed, 18 insertions, 12 deletions
diff --git a/tests/test_parser.py b/tests/test_parser.py index 48963358..d5f43197 100644 --- a/tests/test_parser.py +++ b/tests/test_parser.py @@ -5,6 +5,7 @@ import os.path import textwrap +import warnings import pytest @@ -492,8 +493,10 @@ def test_ast_dump(): with open(fname) as f: source = f.read() num_lines = len(source.splitlines()) - print(f"file {fname} has {num_lines} lines") - ast_root = ast_parse(source) + with warnings.catch_warnings(): + # stress_phystoken.tok has deprecation warnings, suppress them. + warnings.filterwarnings("ignore", message=r".*invalid escape sequence",) + ast_root = ast_parse(source) result = [] ast_dump(ast_root, print=result.append) if num_lines < 100: diff --git a/tests/test_phystokens.py b/tests/test_phystokens.py index f3985437..9950e655 100644 --- a/tests/test_phystokens.py +++ b/tests/test_phystokens.py @@ -6,6 +6,7 @@ import os.path import re import textwrap +import warnings import pytest @@ -95,18 +96,20 @@ class PhysTokensTest(CoverageTest): real_file = os.path.join(TESTS_DIR, "test_coverage.py") self.check_file_tokenization(real_file) - def test_stress(self): - # Check the tokenization of a stress-test file. + @pytest.mark.parametrize("fname", [ + "stress_phystoken.tok", + "stress_phystoken_dos.tok", + ]) + def test_stress(self, fname): + # Check the tokenization of the stress-test files. # And check that those files haven't been incorrectly "fixed". - stress = os.path.join(TESTS_DIR, "stress_phystoken.tok") - self.check_file_tokenization(stress) - with open(stress) as fstress: - assert re.search(r"\s$", fstress.read()), f"{stress} needs a trailing space." - stress = os.path.join(TESTS_DIR, "stress_phystoken_dos.tok") - self.check_file_tokenization(stress) - with open(stress) as fstress: - assert re.search(r"\s$", fstress.read()), f"{stress} needs a trailing space." + with warnings.catch_warnings(): + warnings.filterwarnings("ignore", message=r".*invalid escape sequence",) + stress = os.path.join(TESTS_DIR, fname) + self.check_file_tokenization(stress) + with open(stress) as fstress: + assert re.search(r"(?m) $", fstress.read()), f"{stress} needs a trailing space." @pytest.mark.skipif(not env.PYBEHAVIOR.soft_keywords, reason="Soft keywords are new in Python 3.10") class SoftKeywordTest(CoverageTest): |