Skip to content

Commit 19438b7

Browse files
committed
test: fix the trailing-space test, and suppress warnings about \<space>
1 parent 3d962a3 commit 19438b7

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

tests/test_parser.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import os.path
77
import textwrap
8+
import warnings
89

910
import pytest
1011

@@ -492,8 +493,10 @@ def test_ast_dump():
492493
with open(fname) as f:
493494
source = f.read()
494495
num_lines = len(source.splitlines())
495-
print(f"file {fname} has {num_lines} lines")
496-
ast_root = ast_parse(source)
496+
with warnings.catch_warnings():
497+
# stress_phystoken.tok has deprecation warnings, suppress them.
498+
warnings.filterwarnings("ignore", message=r".*invalid escape sequence",)
499+
ast_root = ast_parse(source)
497500
result = []
498501
ast_dump(ast_root, print=result.append)
499502
if num_lines < 100:

tests/test_phystokens.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import os.path
77
import re
88
import textwrap
9+
import warnings
910

1011
import pytest
1112

@@ -95,18 +96,20 @@ def test_tokenize_real_file(self):
9596
real_file = os.path.join(TESTS_DIR, "test_coverage.py")
9697
self.check_file_tokenization(real_file)
9798

98-
def test_stress(self):
99-
# Check the tokenization of a stress-test file.
99+
@pytest.mark.parametrize("fname", [
100+
"stress_phystoken.tok",
101+
"stress_phystoken_dos.tok",
102+
])
103+
def test_stress(self, fname):
104+
# Check the tokenization of the stress-test files.
100105
# And check that those files haven't been incorrectly "fixed".
101-
stress = os.path.join(TESTS_DIR, "stress_phystoken.tok")
102-
self.check_file_tokenization(stress)
103-
with open(stress) as fstress:
104-
assert re.search(r"\s$", fstress.read()), f"{stress} needs a trailing space."
105-
stress = os.path.join(TESTS_DIR, "stress_phystoken_dos.tok")
106-
self.check_file_tokenization(stress)
107-
with open(stress) as fstress:
108-
assert re.search(r"\s$", fstress.read()), f"{stress} needs a trailing space."
106+
with warnings.catch_warnings():
107+
warnings.filterwarnings("ignore", message=r".*invalid escape sequence",)
109108

109+
stress = os.path.join(TESTS_DIR, fname)
110+
self.check_file_tokenization(stress)
111+
with open(stress) as fstress:
112+
assert re.search(r"(?m) $", fstress.read()), f"{stress} needs a trailing space."
110113

111114
@pytest.mark.skipif(not env.PYBEHAVIOR.soft_keywords, reason="Soft keywords are new in Python 3.10")
112115
class SoftKeywordTest(CoverageTest):

0 commit comments

Comments
 (0)