diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2021-10-12 07:21:45 -0400 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2021-10-12 07:24:37 -0400 |
commit | 5b6b6ecb87f4aa1145977b1a4c8359b202da0d7a (patch) | |
tree | 0838a3f5686a94122d952ca7fcdcb87c00741427 /tests | |
parent | ce0e38e131e987c1bba1dd51abb2d4a002ac3c4e (diff) | |
download | python-coveragepy-git-5b6b6ecb87f4aa1145977b1a4c8359b202da0d7a.tar.gz |
test: lightly test the ast_dump function
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_parser.py | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/tests/test_parser.py b/tests/test_parser.py index 82bf7616..ff7d9ef9 100644 --- a/tests/test_parser.py +++ b/tests/test_parser.py @@ -3,15 +3,17 @@ """Tests for coverage.py's code parsing.""" +import os.path +import re import textwrap import pytest from coverage import env from coverage.exceptions import NotPython -from coverage.parser import PythonParser +from coverage.parser import ast_dump, ast_parse, PythonParser -from tests.coveragetest import CoverageTest +from tests.coveragetest import CoverageTest, TESTS_DIR from tests.helpers import arcz_to_arcs @@ -477,3 +479,23 @@ class ParserFileTest(CoverageTest): parser = self.parse_file("abrupt.py") assert parser.statements == {1} + + +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 |