summaryrefslogtreecommitdiff
path: root/tests/plugin1.py
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2023-01-12 20:51:58 -0500
committerNed Batchelder <ned@nedbatchelder.com>2023-01-12 21:04:26 -0500
commitb5b223723fd1aeaa8ed650b8440b4b8c08f8e378 (patch)
tree3fcf638c95544992e80c1523c1b6084dec05ad93 /tests/plugin1.py
parenta5aeec363e2f50312007ef40903f1dcaae0b5133 (diff)
downloadpython-coveragepy-git-b5b223723fd1aeaa8ed650b8440b4b8c08f8e378.tar.gz
mypy: all of coverage/ and tests/ are checked
Diffstat (limited to 'tests/plugin1.py')
-rw-r--r--tests/plugin1.py35
1 files changed, 22 insertions, 13 deletions
diff --git a/tests/plugin1.py b/tests/plugin1.py
index 3283fbda..4848eaff 100644
--- a/tests/plugin1.py
+++ b/tests/plugin1.py
@@ -3,28 +3,34 @@
"""A file tracer plugin for test_plugins.py to import."""
+from __future__ import annotations
+
import os.path
-import coverage
+from types import FrameType
+from typing import Any, Optional, Set, Tuple, Union
+from coverage import CoveragePlugin, FileReporter, FileTracer
+from coverage.plugin_support import Plugins
+from coverage.types import TLineNo
-class Plugin(coverage.CoveragePlugin):
+class Plugin(CoveragePlugin):
"""A file tracer plugin to import, so that it isn't in the test's current directory."""
- def file_tracer(self, filename):
+ def file_tracer(self, filename: str) -> Optional[FileTracer]:
"""Trace only files named xyz.py"""
if "xyz.py" in filename:
- return FileTracer(filename)
+ return MyFileTracer(filename)
return None
- def file_reporter(self, filename):
- return FileReporter(filename)
+ def file_reporter(self, filename: str) -> Union[FileReporter, str]:
+ return MyFileReporter(filename)
-class FileTracer(coverage.FileTracer):
+class MyFileTracer(FileTracer):
"""A FileTracer emulating a simple static plugin."""
- def __init__(self, filename):
+ def __init__(self, filename: str) -> None:
"""Claim that */*xyz.py was actually sourced from /src/*ABC.zz"""
self._filename = filename
self._source_filename = os.path.join(
@@ -32,21 +38,24 @@ class FileTracer(coverage.FileTracer):
os.path.basename(filename.replace("xyz.py", "ABC.zz"))
)
- def source_filename(self):
+ def source_filename(self) -> str:
return self._source_filename
- def line_number_range(self, frame):
+ def line_number_range(self, frame: FrameType) -> Tuple[TLineNo, TLineNo]:
"""Map the line number X to X05,X06,X07."""
lineno = frame.f_lineno
return lineno*100+5, lineno*100+7
-class FileReporter(coverage.FileReporter):
+class MyFileReporter(FileReporter):
"""Dead-simple FileReporter."""
- def lines(self):
+ def lines(self) -> Set[TLineNo]:
return {105, 106, 107, 205, 206, 207}
-def coverage_init(reg, options): # pylint: disable=unused-argument
+def coverage_init(
+ reg: Plugins,
+ options: Any, # pylint: disable=unused-argument
+) -> None:
"""Called by coverage to initialize the plugins here."""
reg.add_file_tracer(Plugin())