diff options
Diffstat (limited to 'tests/test_parser.py')
-rw-r--r-- | tests/test_parser.py | 37 |
1 files changed, 21 insertions, 16 deletions
diff --git a/tests/test_parser.py b/tests/test_parser.py index ff7d9ef9..3197ffb4 100644 --- a/tests/test_parser.py +++ b/tests/test_parser.py @@ -4,7 +4,6 @@ """Tests for coverage.py's code parsing.""" import os.path -import re import textwrap import pytest @@ -14,7 +13,7 @@ from coverage.exceptions import NotPython from coverage.parser import ast_dump, ast_parse, PythonParser from tests.coveragetest import CoverageTest, TESTS_DIR -from tests.helpers import arcz_to_arcs +from tests.helpers import arcz_to_arcs, re_lines class PythonParserTest(CoverageTest): @@ -485,17 +484,23 @@ def test_ast_dump(): # Run the AST_DUMP code to make sure it doesn't fail, with some light # assertions. Use parser.py as the test code since it is the longest file, # and fitting, since it's the AST_DUMP code. - parser_py = os.path.join(TESTS_DIR, "../coverage/parser.py") - with open(parser_py) as f: - ast_root = ast_parse(f.read()) - result = [] - ast_dump(ast_root, print=result.append) - assert len(result) > 10000 - assert result[0] == "<Module" - assert result[-1] == ">" - - def count(pat): - return sum(1 for line in result if re.search(pat, line)) - - assert count(r"^\s+>") > 2000 - assert count(r"<Name @ \d+,\d+(:\d+)? id: '\w+'>") > 1000 + files = [ + os.path.join(TESTS_DIR, "../coverage/parser.py"), + os.path.join(TESTS_DIR, "stress_phystoken.tok"), + ] + for fname in files: + 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) + result = [] + ast_dump(ast_root, print=result.append) + if num_lines < 100: + continue + assert len(result) > 5 * num_lines + assert result[0] == "<Module" + assert result[-1] == ">" + result_text = "\n".join(result) + assert len(re_lines(result_text, r"^\s+>")) > num_lines + assert len(re_lines(result_text, r"<Name @ \d+,\d+(:\d+)? id: '\w+'>")) > num_lines // 2 |