summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2023-01-05 20:10:24 -0500
committerNed Batchelder <ned@nedbatchelder.com>2023-01-05 20:10:24 -0500
commit78444f4c06df6a634fa67dd99ee7c07b6b633d9e (patch)
tree4651930bc1ec5449e408c347b2d660522f8ac9e4 /tests
parentd4339ee90c3146f370d572cbb1b9ab9907daafad (diff)
downloadpython-coveragepy-git-78444f4c06df6a634fa67dd99ee7c07b6b633d9e.tar.gz
style: use good style for annotated defaults parameters
Diffstat (limited to 'tests')
-rw-r--r--tests/coveragetest.py48
-rw-r--r--tests/goldtest.py6
-rw-r--r--tests/helpers.py14
-rw-r--r--tests/mixins.py6
-rw-r--r--tests/test_api.py4
-rw-r--r--tests/test_cmdline.py20
-rw-r--r--tests/test_concurrency.py6
-rw-r--r--tests/test_data.py2
-rw-r--r--tests/test_files.py10
-rw-r--r--tests/test_html.py12
-rw-r--r--tests/test_lcov.py2
-rw-r--r--tests/test_xml.py4
12 files changed, 67 insertions, 67 deletions
diff --git a/tests/coveragetest.py b/tests/coveragetest.py
index 100b8e3b..0055c691 100644
--- a/tests/coveragetest.py
+++ b/tests/coveragetest.py
@@ -76,7 +76,7 @@ class CoverageTest(
self,
cov: Coverage,
modname: str,
- modfile: Optional[str]=None
+ modfile: Optional[str] = None
) -> ModuleType:
"""Start coverage, import a file, then stop coverage.
@@ -96,7 +96,7 @@ class CoverageTest(
cov.stop()
return mod
- def get_report(self, cov: Coverage, squeeze: bool=True, **kwargs: Any) -> str:
+ def get_report(self, cov: Coverage, squeeze: bool = True, **kwargs: Any) -> str:
"""Get the report from `cov`, and canonicalize it."""
repout = io.StringIO()
kwargs.setdefault("show_missing", False)
@@ -137,17 +137,17 @@ class CoverageTest(
def check_coverage(
self,
text: str,
- lines: Optional[Union[Sequence[TLineNo], Sequence[List[TLineNo]]]]=None,
- missing: Union[str, Sequence[str]]="",
- report: str="",
- excludes: Optional[Iterable[str]]=None,
- partials: Iterable[str]=(),
- arcz: Optional[str]=None,
- arcz_missing: Optional[str]=None,
- arcz_unpredicted: Optional[str]=None,
- arcs: Optional[Iterable[TArc]]=None,
- arcs_missing: Optional[Iterable[TArc]]=None,
- arcs_unpredicted: Optional[Iterable[TArc]]=None,
+ lines: Optional[Union[Sequence[TLineNo], Sequence[List[TLineNo]]]] = None,
+ missing: Union[str, Sequence[str]] = "",
+ report: str = "",
+ excludes: Optional[Iterable[str]] = None,
+ partials: Iterable[str] = (),
+ arcz: Optional[str] = None,
+ arcz_missing: Optional[str] = None,
+ arcz_unpredicted: Optional[str] = None,
+ arcs: Optional[Iterable[TArc]] = None,
+ arcs_missing: Optional[Iterable[TArc]] = None,
+ arcs_unpredicted: Optional[Iterable[TArc]] = None,
) -> Coverage:
"""Check the coverage measurement of `text`.
@@ -248,11 +248,11 @@ class CoverageTest(
def make_data_file(
self,
- basename: Optional[str]=None,
- suffix: Optional[str]=None,
- lines: Optional[Mapping[str, Collection[TLineNo]]]=None,
- arcs: Optional[Mapping[str, Collection[TArc]]]=None,
- file_tracers: Optional[Mapping[str, str]]=None,
+ basename: Optional[str] = None,
+ suffix: Optional[str] = None,
+ lines: Optional[Mapping[str, Collection[TLineNo]]] = None,
+ arcs: Optional[Mapping[str, Collection[TArc]]] = None,
+ file_tracers: Optional[Mapping[str, str]] = None,
) -> CoverageData:
"""Write some data into a coverage data file."""
data = coverage.CoverageData(basename=basename, suffix=suffix)
@@ -271,7 +271,7 @@ class CoverageTest(
self,
cov: Coverage,
warnings: Iterable[str],
- not_warnings: Iterable[str]=(),
+ not_warnings: Iterable[str] = (),
) -> Iterator[None]:
"""A context manager to check that particular warnings happened in `cov`.
@@ -292,8 +292,8 @@ class CoverageTest(
saved_warnings = []
def capture_warning(
msg: str,
- slug: Optional[str]=None,
- once: bool=False, # pylint: disable=unused-argument
+ slug: Optional[str] = None,
+ once: bool = False, # pylint: disable=unused-argument
) -> None:
"""A fake implementation of Coverage._warn, to capture warnings."""
# NOTE: we don't implement `once`.
@@ -353,15 +353,15 @@ class CoverageTest(
def assert_recent_datetime(
self,
dt: datetime.datetime,
- seconds: int=10,
- msg: Optional[str]=None,
+ seconds: int = 10,
+ msg: Optional[str] = None,
) -> None:
"""Assert that `dt` marks a time at most `seconds` seconds ago."""
age = datetime.datetime.now() - dt
assert age.total_seconds() >= 0, msg
assert age.total_seconds() <= seconds, msg
- def command_line(self, args: str, ret: int=OK) -> None:
+ def command_line(self, args: str, ret: int = OK) -> None:
"""Run `args` through the command line.
Use this when you want to run the full coverage machinery, but in the
diff --git a/tests/goldtest.py b/tests/goldtest.py
index 4d2be842..12a04af6 100644
--- a/tests/goldtest.py
+++ b/tests/goldtest.py
@@ -27,9 +27,9 @@ def gold_path(path: str) -> str:
def compare(
expected_dir: str,
actual_dir: str,
- file_pattern: Optional[str]=None,
- actual_extra: bool=False,
- scrubs: Optional[List[Tuple[str, str]]]=None,
+ file_pattern: Optional[str] = None,
+ actual_extra: bool = False,
+ scrubs: Optional[List[Tuple[str, str]]] = None,
) -> None:
"""Compare files matching `file_pattern` in `expected_dir` and `actual_dir`.
diff --git a/tests/helpers.py b/tests/helpers.py
index 0f958a39..1c4b2f96 100644
--- a/tests/helpers.py
+++ b/tests/helpers.py
@@ -64,9 +64,9 @@ def run_command(cmd: str) -> Tuple[int, str]:
def make_file(
filename: str,
- text: str="",
- bytes: bytes=b"",
- newline: Optional[str]=None,
+ text: str = "",
+ bytes: bytes = b"",
+ newline: Optional[str] = None,
) -> str:
"""Create a file for testing.
@@ -154,7 +154,7 @@ class CheckUniqueFilenames:
return self.wrapped(filename, *args, **kwargs)
-def re_lines(pat: str, text: str, match: bool=True) -> List[str]:
+def re_lines(pat: str, text: str, match: bool = True) -> List[str]:
"""Return a list of lines selected by `pat` in the string `text`.
If `match` is false, the selection is inverted: only the non-matching
@@ -167,7 +167,7 @@ def re_lines(pat: str, text: str, match: bool=True) -> List[str]:
return [l for l in text.splitlines() if bool(re.search(pat, l)) == match]
-def re_lines_text(pat: str, text: str, match: bool=True) -> str:
+def re_lines_text(pat: str, text: str, match: bool = True) -> str:
"""Return the multi-line text of lines selected by `pat`."""
return "".join(l + "\n" for l in re_lines(pat, text, match=match))
@@ -320,8 +320,8 @@ def assert_coverage_warnings(
@contextlib.contextmanager
def swallow_warnings(
- message: str=r".",
- category: Type[Warning]=CoverageWarning,
+ message: str = r".",
+ category: Type[Warning] = CoverageWarning,
) -> Iterator[None]:
"""Swallow particular warnings.
diff --git a/tests/mixins.py b/tests/mixins.py
index 586dcac5..d207f779 100644
--- a/tests/mixins.py
+++ b/tests/mixins.py
@@ -81,9 +81,9 @@ class TempDirMixin:
def make_file(
self,
filename: str,
- text: str="",
- bytes: bytes=b"",
- newline: Optional[str]=None,
+ text: str = "",
+ bytes: bytes = b"",
+ newline: Optional[str] = None,
) -> str:
"""Make a file. See `tests.helpers.make_file`"""
# pylint: disable=redefined-builtin # bytes
diff --git a/tests/test_api.py b/tests/test_api.py
index 0eb73350..1c565421 100644
--- a/tests/test_api.py
+++ b/tests/test_api.py
@@ -1062,7 +1062,7 @@ class TestRunnerPluginTest(CoverageTest):
way they do.
"""
- def pretend_to_be_nose_with_cover(self, erase: bool=False, cd: bool=False) -> None:
+ def pretend_to_be_nose_with_cover(self, erase: bool = False, cd: bool = False) -> None:
"""This is what the nose --with-cover plugin does."""
self.make_file("no_biggie.py", """\
a = 1
@@ -1492,7 +1492,7 @@ class CombiningTest(CoverageTest):
class ReportMapsPathsTest(CoverageTest):
"""Check that reporting implicitly maps paths."""
- def make_files(self, data: str, settings: bool=False) -> None:
+ def make_files(self, data: str, settings: bool = False) -> None:
"""Create the test files we need for line coverage."""
src = """\
if VER == 1:
diff --git a/tests/test_cmdline.py b/tests/test_cmdline.py
index 13b6e73e..6caac307 100644
--- a/tests/test_cmdline.py
+++ b/tests/test_cmdline.py
@@ -98,7 +98,7 @@ class BaseCmdLineTest(CoverageTest):
def mock_command_line(
self,
args: str,
- options: Optional[Mapping[str, TConfigValueIn]]=None,
+ options: Optional[Mapping[str, TConfigValueIn]] = None,
) -> Tuple[mock.Mock, int]:
"""Run `args` through the command line, with a Mock.
@@ -131,8 +131,8 @@ class BaseCmdLineTest(CoverageTest):
self,
args: str,
code: str,
- ret: int=OK,
- options: Optional[Mapping[str, TConfigValueIn]]=None,
+ ret: int = OK,
+ options: Optional[Mapping[str, TConfigValueIn]] = None,
) -> None:
"""Assert that the `args` end up executing the sequence in `code`."""
called, status = self.mock_command_line(args, options=options)
@@ -175,9 +175,9 @@ class BaseCmdLineTest(CoverageTest):
def cmd_help(
self,
args: str,
- help_msg: Optional[str]=None,
- topic: Optional[str]=None,
- ret: int=ERR,
+ help_msg: Optional[str] = None,
+ topic: Optional[str] = None,
+ ret: int = ERR,
) -> None:
"""Run a command line, and check that it prints the right help.
@@ -1129,10 +1129,10 @@ class CoverageReportingFake:
def __init__(
self,
report_result: float,
- html_result: float=0,
- xml_result: float=0,
- json_report: float=0,
- lcov_result: float=0,
+ html_result: float = 0,
+ xml_result: float = 0,
+ json_report: float = 0,
+ lcov_result: float = 0,
) -> None:
self.config = CoverageConfig()
self.report_result = report_result
diff --git a/tests/test_concurrency.py b/tests/test_concurrency.py
index c80136c4..3360094b 100644
--- a/tests/test_concurrency.py
+++ b/tests/test_concurrency.py
@@ -207,7 +207,7 @@ class ConcurrencyTest(CoverageTest):
code: str,
concurrency: str,
the_module: ModuleType,
- expected_out: Optional[str]=None,
+ expected_out: Optional[str] = None,
) -> None:
"""Run some concurrency testing code and see that it was all covered.
@@ -460,8 +460,8 @@ class MultiprocessingTest(CoverageTest):
the_module: ModuleType,
nprocs: int,
start_method: str,
- concurrency: str="multiprocessing",
- args: str="",
+ concurrency: str = "multiprocessing",
+ args: str = "",
) -> None:
"""Run code using multiprocessing, it should produce `expected_out`."""
self.make_file("multi.py", code)
diff --git a/tests/test_data.py b/tests/test_data.py
index 8ed4f842..ab4e03f7 100644
--- a/tests/test_data.py
+++ b/tests/test_data.py
@@ -88,7 +88,7 @@ TCoverageData = Callable[..., CoverageData]
def assert_line_counts(
covdata: CoverageData,
counts: Mapping[str, int],
- fullpath: bool=False,
+ fullpath: bool = False,
) -> None:
"""Check that the line_counts of `covdata` is `counts`."""
assert line_counts(covdata, fullpath) == counts
diff --git a/tests/test_files.py b/tests/test_files.py
index fe6c36a2..35270e7b 100644
--- a/tests/test_files.py
+++ b/tests/test_files.py
@@ -133,10 +133,10 @@ def test_flat_rootname(original: str, flat: str) -> None:
def globs_to_regex_params(
patterns: Iterable[str],
- case_insensitive: bool=False,
- partial: bool=False,
- matches: Iterable[str]=(),
- nomatches: Iterable[str]=(),
+ case_insensitive: bool = False,
+ partial: bool = False,
+ matches: Iterable[str] = (),
+ nomatches: Iterable[str] = (),
) -> Iterator[Any]:
"""Generate parameters for `test_globs_to_regex`.
@@ -399,7 +399,7 @@ class PathAliasesTest(CoverageTest):
expected = files.canonical_filename(out)
assert mapped == expected
- def assert_unchanged(self, aliases: PathAliases, inp: str, exists: bool=True) -> None:
+ def assert_unchanged(self, aliases: PathAliases, inp: str, exists: bool = True) -> None:
"""Assert that `inp` mapped through `aliases` is unchanged."""
assert aliases.map(inp, exists=lambda p: exists) == inp
diff --git a/tests/test_html.py b/tests/test_html.py
index 5960962e..8893993c 100644
--- a/tests/test_html.py
+++ b/tests/test_html.py
@@ -55,8 +55,8 @@ class HtmlTestHelpers(CoverageTest):
def run_coverage(
self,
- covargs: Optional[Dict[str, Any]]=None,
- htmlargs: Optional[Dict[str, Any]]=None,
+ covargs: Optional[Dict[str, Any]] = None,
+ htmlargs: Optional[Dict[str, Any]] = None,
) -> float:
"""Run coverage.py on main_file.py, and create an HTML report."""
self.clean_local_file_imports()
@@ -136,7 +136,7 @@ class FileWriteTracker:
def __init__(self, written: Set[str]) -> None:
self.written = written
- def open(self, filename: str, mode: str="r") -> IO[str]:
+ def open(self, filename: str, mode: str = "r") -> IO[str]:
"""Be just like `open`, but write written file names to `self.written`."""
if mode.startswith("w"):
self.written.add(filename.replace('\\', '/'))
@@ -158,8 +158,8 @@ class HtmlDeltaTest(HtmlTestHelpers, CoverageTest):
def run_coverage(
self,
- covargs: Optional[Dict[str, Any]]=None,
- htmlargs: Optional[Dict[str, Any]]=None,
+ covargs: Optional[Dict[str, Any]] = None,
+ htmlargs: Optional[Dict[str, Any]] = None,
) -> float:
"""Run coverage in-process for the delta tests.
@@ -658,7 +658,7 @@ def filepath_to_regex(path: str) -> str:
def compare_html(
expected: str,
actual: str,
- extra_scrubs: Optional[List[Tuple[str, str]]]=None,
+ extra_scrubs: Optional[List[Tuple[str, str]]] = None,
) -> None:
"""Specialized compare function for our HTML files."""
__tracebackhide__ = True # pytest, please don't show me this function.
diff --git a/tests/test_lcov.py b/tests/test_lcov.py
index 95bc5fee..30065a8d 100644
--- a/tests/test_lcov.py
+++ b/tests/test_lcov.py
@@ -46,7 +46,7 @@ class LcovTest(CoverageTest):
self.assertAlmostEqual(cuboid_volume(5.5),166.375)
""")
- def get_lcov_report_content(self, filename: str="coverage.lcov") -> str:
+ def get_lcov_report_content(self, filename: str = "coverage.lcov") -> str:
"""Return the content of an LCOV report."""
with open(filename, "r") as file:
return file.read()
diff --git a/tests/test_xml.py b/tests/test_xml.py
index a6a15281..005f9d5a 100644
--- a/tests/test_xml.py
+++ b/tests/test_xml.py
@@ -37,7 +37,7 @@ class XmlTestHelpers(CoverageTest):
self.start_import_stop(cov, "main")
return cov
- def make_tree(self, width: int, depth: int, curdir: str=".") -> None:
+ def make_tree(self, width: int, depth: int, curdir: str = ".") -> None:
"""Make a tree of packages.
Makes `width` directories, named d0 .. d{width-1}. Each directory has
@@ -457,7 +457,7 @@ class XmlPackageStructureTest(XmlTestHelpers, CoverageTest):
assert [elt.text for elt in elts] == ["src"]
-def compare_xml(expected: str, actual: str, actual_extra: bool=False) -> None:
+def compare_xml(expected: str, actual: str, actual_extra: bool = False) -> None:
"""Specialized compare function for our XML files."""
source_path = coverage.files.relative_directory().rstrip(r"\/")