summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2023-01-03 13:53:45 -0500
committerNed Batchelder <ned@nedbatchelder.com>2023-01-03 13:53:45 -0500
commit98301ed240a141592573c2ed239e006d42a26161 (patch)
treef774b5fa50df5b994c963a8be589aa8fc8754e18
parent9d2e1b055cf7ed02eba725b86d476c24a718178d (diff)
downloadpython-coveragepy-git-98301ed240a141592573c2ed239e006d42a26161.tar.gz
mypy: test_config.py, test_context.py
-rw-r--r--coverage/config.py2
-rw-r--r--coverage/types.py2
-rw-r--r--tests/test_config.py109
-rw-r--r--tests/test_context.py67
-rw-r--r--tox.ini18
5 files changed, 101 insertions, 97 deletions
diff --git a/coverage/config.py b/coverage/config.py
index 69159d99..02d54716 100644
--- a/coverage/config.py
+++ b/coverage/config.py
@@ -73,7 +73,7 @@ class HandyConfigParser(configparser.ConfigParser):
def get_section(self, section: str) -> TConfigSection:
"""Get the contents of a section, as a dictionary."""
- d: TConfigSection = {}
+ d: Dict[str, TConfigValue] = {}
for opt in self.options(section):
d[opt] = self.get(section, opt)
return d
diff --git a/coverage/types.py b/coverage/types.py
index ddfcdb81..54c1dfba 100644
--- a/coverage/types.py
+++ b/coverage/types.py
@@ -109,7 +109,7 @@ TCovKwargs = Any
# One value read from a config file.
TConfigValue = Optional[Union[bool, int, float, str, List[str]]]
# An entire config section, mapping option names to values.
-TConfigSection = Dict[str, TConfigValue]
+TConfigSection = Mapping[str, TConfigValue]
class TConfigurable(Protocol):
"""Something that can proxy to the coverage configuration settings."""
diff --git a/tests/test_config.py b/tests/test_config.py
index 26276c47..66e71d23 100644
--- a/tests/test_config.py
+++ b/tests/test_config.py
@@ -9,6 +9,7 @@ from unittest import mock
import pytest
import coverage
+from coverage import Coverage
from coverage.config import HandyConfigParser
from coverage.exceptions import ConfigError, CoverageWarning
from coverage.tomlconfig import TomlConfigParser
@@ -20,14 +21,14 @@ from tests.helpers import without_module
class ConfigTest(CoverageTest):
"""Tests of the different sources of configuration settings."""
- def test_default_config(self):
+ def test_default_config(self) -> None:
# Just constructing a coverage() object gets the right defaults.
cov = coverage.Coverage()
assert not cov.config.timid
assert not cov.config.branch
assert cov.config.data_file == ".coverage"
- def test_arguments(self):
+ def test_arguments(self) -> None:
# Arguments to the constructor are applied to the configuration.
cov = coverage.Coverage(timid=True, data_file="fooey.dat", concurrency="multiprocessing")
assert cov.config.timid
@@ -35,7 +36,7 @@ class ConfigTest(CoverageTest):
assert cov.config.data_file == "fooey.dat"
assert cov.config.concurrency == ["multiprocessing"]
- def test_config_file(self):
+ def test_config_file(self) -> None:
# A .coveragerc file will be read into the configuration.
self.make_file(".coveragerc", """\
# This is just a bogus .rc file for testing.
@@ -48,7 +49,7 @@ class ConfigTest(CoverageTest):
assert not cov.config.branch
assert cov.config.data_file == ".hello_kitty.data"
- def test_named_config_file(self):
+ def test_named_config_file(self) -> None:
# You can name the config file what you like.
self.make_file("my_cov.ini", """\
[run]
@@ -61,7 +62,7 @@ class ConfigTest(CoverageTest):
assert not cov.config.branch
assert cov.config.data_file == "delete.me"
- def test_toml_config_file(self):
+ def test_toml_config_file(self) -> None:
# A pyproject.toml file will be read into the configuration.
self.make_file("pyproject.toml", """\
# This is just a bogus toml file for testing.
@@ -91,7 +92,7 @@ class ConfigTest(CoverageTest):
assert cov.config.fail_under == 90.5
assert cov.config.get_plugin_options("plugins.a_plugin") == {"hello": "world"}
- def test_toml_ints_can_be_floats(self):
+ def test_toml_ints_can_be_floats(self) -> None:
# Test that our class doesn't reject integers when loading floats
self.make_file("pyproject.toml", """\
# This is just a bogus toml file for testing.
@@ -102,7 +103,7 @@ class ConfigTest(CoverageTest):
assert cov.config.fail_under == 90
assert isinstance(cov.config.fail_under, float)
- def test_ignored_config_file(self):
+ def test_ignored_config_file(self) -> None:
# You can disable reading the .coveragerc file.
self.make_file(".coveragerc", """\
[run]
@@ -114,7 +115,7 @@ class ConfigTest(CoverageTest):
assert not cov.config.branch
assert cov.config.data_file == ".coverage"
- def test_config_file_then_args(self):
+ def test_config_file_then_args(self) -> None:
# The arguments override the .coveragerc file.
self.make_file(".coveragerc", """\
[run]
@@ -126,7 +127,7 @@ class ConfigTest(CoverageTest):
assert not cov.config.branch
assert cov.config.data_file == ".mycov"
- def test_data_file_from_environment(self):
+ def test_data_file_from_environment(self) -> None:
# There's an environment variable for the data_file.
self.make_file(".coveragerc", """\
[run]
@@ -140,7 +141,7 @@ class ConfigTest(CoverageTest):
cov = coverage.Coverage(data_file="fromarg.dat")
assert cov.config.data_file == "fromarg.dat"
- def test_debug_from_environment(self):
+ def test_debug_from_environment(self) -> None:
self.make_file(".coveragerc", """\
[run]
debug = dataio, pids
@@ -149,7 +150,7 @@ class ConfigTest(CoverageTest):
cov = coverage.Coverage()
assert cov.config.debug == ["dataio", "pids", "callers", "fooey"]
- def test_rcfile_from_environment(self):
+ def test_rcfile_from_environment(self) -> None:
self.make_file("here.ini", """\
[run]
data_file = overthere.dat
@@ -158,7 +159,7 @@ class ConfigTest(CoverageTest):
cov = coverage.Coverage()
assert cov.config.data_file == "overthere.dat"
- def test_missing_rcfile_from_environment(self):
+ def test_missing_rcfile_from_environment(self) -> None:
self.set_environ("COVERAGE_RCFILE", "nowhere.ini")
msg = "Couldn't read 'nowhere.ini' as a config file"
with pytest.raises(ConfigError, match=msg):
@@ -179,7 +180,7 @@ class ConfigTest(CoverageTest):
r"'foo\*\*\*': " +
r"multiple repeat"),
])
- def test_parse_errors(self, bad_config, msg):
+ def test_parse_errors(self, bad_config: str, msg: str) -> None:
# Im-parsable values raise ConfigError, with details.
self.make_file(".coveragerc", bad_config)
with pytest.raises(ConfigError, match=msg):
@@ -202,13 +203,13 @@ class ConfigTest(CoverageTest):
("[tool.coverage.report]\nprecision=1.23", "not an integer"),
('[tool.coverage.report]\nfail_under="s"', "couldn't convert to a float"),
])
- def test_toml_parse_errors(self, bad_config, msg):
+ def test_toml_parse_errors(self, bad_config: str, msg: str) -> None:
# Im-parsable values raise ConfigError, with details.
self.make_file("pyproject.toml", bad_config)
with pytest.raises(ConfigError, match=msg):
coverage.Coverage()
- def test_environment_vars_in_config(self):
+ def test_environment_vars_in_config(self) -> None:
# Config files can have $envvars in them.
self.make_file(".coveragerc", """\
[run]
@@ -230,7 +231,7 @@ class ConfigTest(CoverageTest):
assert cov.config.branch is True
assert cov.config.exclude_list == ["the_$one", "anotherZZZ", "xZZZy", "xy", "huh${X}what"]
- def test_environment_vars_in_toml_config(self):
+ def test_environment_vars_in_toml_config(self) -> None:
# Config files can have $envvars in them.
self.make_file("pyproject.toml", """\
[tool.coverage.run]
@@ -263,7 +264,7 @@ class ConfigTest(CoverageTest):
assert cov.config.data_file == "hello-world.fooey"
assert cov.config.exclude_list == ["the_$one", "anotherZZZ", "xZZZy", "xy", "huh${X}what"]
- def test_tilde_in_config(self):
+ def test_tilde_in_config(self) -> None:
# Config entries that are file paths can be tilde-expanded.
self.make_file(".coveragerc", """\
[run]
@@ -286,7 +287,7 @@ class ConfigTest(CoverageTest):
~/src
~joe/source
""")
- def expanduser(s):
+ def expanduser(s: str) -> str:
"""Fake tilde expansion"""
s = s.replace("~/", "/Users/me/")
s = s.replace("~joe/", "/Users/joe/")
@@ -300,7 +301,7 @@ class ConfigTest(CoverageTest):
assert cov.config.exclude_list == ["~/data.file", "~joe/html_dir"]
assert cov.config.paths == {'mapping': ['/Users/me/src', '/Users/joe/source']}
- def test_tilde_in_toml_config(self):
+ def test_tilde_in_toml_config(self) -> None:
# Config entries that are file paths can be tilde-expanded.
self.make_file("pyproject.toml", """\
[tool.coverage.run]
@@ -319,7 +320,7 @@ class ConfigTest(CoverageTest):
"~joe/html_dir",
]
""")
- def expanduser(s):
+ def expanduser(s: str) -> str:
"""Fake tilde expansion"""
s = s.replace("~/", "/Users/me/")
s = s.replace("~joe/", "/Users/joe/")
@@ -332,7 +333,7 @@ class ConfigTest(CoverageTest):
assert cov.config.xml_output == "/Users/me/somewhere/xml.out"
assert cov.config.exclude_list == ["~/data.file", "~joe/html_dir"]
- def test_tweaks_after_constructor(self):
+ def test_tweaks_after_constructor(self) -> None:
# set_option can be used after construction to affect the config.
cov = coverage.Coverage(timid=True, data_file="fooey.dat")
cov.set_option("run:timid", False)
@@ -345,7 +346,7 @@ class ConfigTest(CoverageTest):
assert not cov.get_option("run:branch")
assert cov.get_option("run:data_file") == "fooey.dat"
- def test_tweaks_paths_after_constructor(self):
+ def test_tweaks_paths_after_constructor(self) -> None:
self.make_file(".coveragerc", """\
[paths]
first =
@@ -371,7 +372,7 @@ class ConfigTest(CoverageTest):
assert cov.get_option("paths") == new_paths
- def test_tweak_error_checking(self):
+ def test_tweak_error_checking(self) -> None:
# Trying to set an unknown config value raises an error.
cov = coverage.Coverage()
with pytest.raises(ConfigError, match="No such option: 'run:xyzzy'"):
@@ -383,7 +384,7 @@ class ConfigTest(CoverageTest):
with pytest.raises(ConfigError, match="No such option: 'xyzzy:foo'"):
_ = cov.get_option("xyzzy:foo")
- def test_tweak_plugin_options(self):
+ def test_tweak_plugin_options(self) -> None:
# Plugin options have a more flexible syntax.
cov = coverage.Coverage()
cov.set_option("run:plugins", ["fooey.plugin", "xyzzy.coverage.plugin"])
@@ -397,7 +398,7 @@ class ConfigTest(CoverageTest):
with pytest.raises(ConfigError, match="No such option: 'no_such.plugin:foo'"):
_ = cov.get_option("no_such.plugin:foo")
- def test_unknown_option(self):
+ def test_unknown_option(self) -> None:
self.make_file(".coveragerc", """\
[run]
xyzzy = 17
@@ -406,7 +407,7 @@ class ConfigTest(CoverageTest):
with pytest.warns(CoverageWarning, match=msg):
_ = coverage.Coverage()
- def test_unknown_option_toml(self):
+ def test_unknown_option_toml(self) -> None:
self.make_file("pyproject.toml", """\
[tool.coverage.run]
xyzzy = 17
@@ -415,7 +416,7 @@ class ConfigTest(CoverageTest):
with pytest.warns(CoverageWarning, match=msg):
_ = coverage.Coverage()
- def test_misplaced_option(self):
+ def test_misplaced_option(self) -> None:
self.make_file(".coveragerc", """\
[report]
branch = True
@@ -424,7 +425,7 @@ class ConfigTest(CoverageTest):
with pytest.warns(CoverageWarning, match=msg):
_ = coverage.Coverage()
- def test_unknown_option_in_other_ini_file(self):
+ def test_unknown_option_in_other_ini_file(self) -> None:
self.make_file("setup.cfg", """\
[coverage:run]
huh = what?
@@ -433,7 +434,7 @@ class ConfigTest(CoverageTest):
with pytest.warns(CoverageWarning, match=msg):
_ = coverage.Coverage()
- def test_exceptions_from_missing_things(self):
+ def test_exceptions_from_missing_things(self) -> None:
self.make_file("config.ini", """\
[run]
branch = True
@@ -547,7 +548,7 @@ class ConfigFileTest(UsingModulesMixin, CoverageTest):
python igor.py zip_mods
"""
- def assert_config_settings_are_correct(self, cov):
+ def assert_config_settings_are_correct(self, cov: Coverage) -> None:
"""Check that `cov` has all the settings from LOTSA_SETTINGS."""
assert cov.config.timid
assert cov.config.data_file == "something_or_other.dat"
@@ -594,38 +595,38 @@ class ConfigFileTest(UsingModulesMixin, CoverageTest):
assert cov.config.json_pretty_print is True
assert cov.config.include_namespace_packages is True
- def test_config_file_settings(self):
+ def test_config_file_settings(self) -> None:
self.make_file(".coveragerc", self.LOTSA_SETTINGS.format(section=""))
cov = coverage.Coverage()
self.assert_config_settings_are_correct(cov)
- def check_config_file_settings_in_other_file(self, fname, contents):
+ def check_config_file_settings_in_other_file(self, fname: str, contents: str) -> None:
"""Check config will be read from another file, with prefixed sections."""
nested = self.LOTSA_SETTINGS.format(section="coverage:")
fname = self.make_file(fname, nested + "\n" + contents)
cov = coverage.Coverage()
self.assert_config_settings_are_correct(cov)
- def test_config_file_settings_in_setupcfg(self):
+ def test_config_file_settings_in_setupcfg(self) -> None:
self.check_config_file_settings_in_other_file("setup.cfg", self.SETUP_CFG)
- def test_config_file_settings_in_toxini(self):
+ def test_config_file_settings_in_toxini(self) -> None:
self.check_config_file_settings_in_other_file("tox.ini", self.TOX_INI)
- def check_other_config_if_coveragerc_specified(self, fname, contents):
+ def check_other_config_if_coveragerc_specified(self, fname: str, contents: str) -> None:
"""Check that config `fname` is read if .coveragerc is missing, but specified."""
nested = self.LOTSA_SETTINGS.format(section="coverage:")
self.make_file(fname, nested + "\n" + contents)
cov = coverage.Coverage(config_file=".coveragerc")
self.assert_config_settings_are_correct(cov)
- def test_config_file_settings_in_setupcfg_if_coveragerc_specified(self):
+ def test_config_file_settings_in_setupcfg_if_coveragerc_specified(self) -> None:
self.check_other_config_if_coveragerc_specified("setup.cfg", self.SETUP_CFG)
- def test_config_file_settings_in_tox_if_coveragerc_specified(self):
+ def test_config_file_settings_in_tox_if_coveragerc_specified(self) -> None:
self.check_other_config_if_coveragerc_specified("tox.ini", self.TOX_INI)
- def check_other_not_read_if_coveragerc(self, fname):
+ def check_other_not_read_if_coveragerc(self, fname: str) -> None:
"""Check config `fname` is not read if .coveragerc exists."""
self.make_file(".coveragerc", """\
[run]
@@ -641,13 +642,13 @@ class ConfigFileTest(UsingModulesMixin, CoverageTest):
assert cov.config.run_omit == []
assert cov.config.branch is False
- def test_setupcfg_only_if_not_coveragerc(self):
+ def test_setupcfg_only_if_not_coveragerc(self) -> None:
self.check_other_not_read_if_coveragerc("setup.cfg")
- def test_toxini_only_if_not_coveragerc(self):
+ def test_toxini_only_if_not_coveragerc(self) -> None:
self.check_other_not_read_if_coveragerc("tox.ini")
- def check_other_config_need_prefixes(self, fname):
+ def check_other_config_need_prefixes(self, fname: str) -> None:
"""Check that `fname` sections won't be read if un-prefixed."""
self.make_file(fname, """\
[run]
@@ -658,13 +659,13 @@ class ConfigFileTest(UsingModulesMixin, CoverageTest):
assert cov.config.run_omit == []
assert cov.config.branch is False
- def test_setupcfg_only_if_prefixed(self):
+ def test_setupcfg_only_if_prefixed(self) -> None:
self.check_other_config_need_prefixes("setup.cfg")
- def test_toxini_only_if_prefixed(self):
+ def test_toxini_only_if_prefixed(self) -> None:
self.check_other_config_need_prefixes("tox.ini")
- def test_tox_ini_even_if_setup_cfg(self):
+ def test_tox_ini_even_if_setup_cfg(self) -> None:
# There's a setup.cfg, but no coverage settings in it, so tox.ini
# is read.
nested = self.LOTSA_SETTINGS.format(section="coverage:")
@@ -673,14 +674,14 @@ class ConfigFileTest(UsingModulesMixin, CoverageTest):
cov = coverage.Coverage()
self.assert_config_settings_are_correct(cov)
- def test_read_prefixed_sections_from_explicit_file(self):
+ def test_read_prefixed_sections_from_explicit_file(self) -> None:
# You can point to a tox.ini, and it will find [coverage:run] sections
nested = self.LOTSA_SETTINGS.format(section="coverage:")
self.make_file("tox.ini", self.TOX_INI + "\n" + nested)
cov = coverage.Coverage(config_file="tox.ini")
self.assert_config_settings_are_correct(cov)
- def test_non_ascii(self):
+ def test_non_ascii(self) -> None:
self.make_file(".coveragerc", """\
[report]
exclude_lines =
@@ -697,20 +698,20 @@ class ConfigFileTest(UsingModulesMixin, CoverageTest):
assert cov.config.html_title == "tabblo & «ταБЬℓσ» # numbers"
@pytest.mark.parametrize("bad_file", ["nosuchfile.txt", "."])
- def test_unreadable_config(self, bad_file):
+ def test_unreadable_config(self, bad_file: str) -> None:
# If a config file is explicitly specified, then it is an error for it
# to not be readable.
msg = f"Couldn't read {bad_file!r} as a config file"
with pytest.raises(ConfigError, match=msg):
coverage.Coverage(config_file=bad_file)
- def test_nocoveragerc_file_when_specified(self):
+ def test_nocoveragerc_file_when_specified(self) -> None:
cov = coverage.Coverage(config_file=".coveragerc")
assert not cov.config.timid
assert not cov.config.branch
assert cov.config.data_file == ".coverage"
- def test_no_toml_installed_no_toml(self):
+ def test_no_toml_installed_no_toml(self) -> None:
# Can't read a toml file that doesn't exist.
with without_module(coverage.tomlconfig, 'tomllib'):
msg = "Couldn't read 'cov.toml' as a config file"
@@ -718,7 +719,7 @@ class ConfigFileTest(UsingModulesMixin, CoverageTest):
coverage.Coverage(config_file="cov.toml")
@pytest.mark.skipif(sys.version_info >= (3, 11), reason="Python 3.11 has toml in stdlib")
- def test_no_toml_installed_explicit_toml(self):
+ def test_no_toml_installed_explicit_toml(self) -> None:
# Can't specify a toml config file if toml isn't installed.
self.make_file("cov.toml", "# A toml file!")
with without_module(coverage.tomlconfig, 'tomllib'):
@@ -727,7 +728,7 @@ class ConfigFileTest(UsingModulesMixin, CoverageTest):
coverage.Coverage(config_file="cov.toml")
@pytest.mark.skipif(sys.version_info >= (3, 11), reason="Python 3.11 has toml in stdlib")
- def test_no_toml_installed_pyproject_toml(self):
+ def test_no_toml_installed_pyproject_toml(self) -> None:
# Can't have coverage config in pyproject.toml without toml installed.
self.make_file("pyproject.toml", """\
# A toml file!
@@ -740,7 +741,7 @@ class ConfigFileTest(UsingModulesMixin, CoverageTest):
coverage.Coverage()
@pytest.mark.skipif(sys.version_info >= (3, 11), reason="Python 3.11 has toml in stdlib")
- def test_no_toml_installed_pyproject_toml_shorter_syntax(self):
+ def test_no_toml_installed_pyproject_toml_shorter_syntax(self) -> None:
# Can't have coverage config in pyproject.toml without toml installed.
self.make_file("pyproject.toml", """\
# A toml file!
@@ -753,7 +754,7 @@ class ConfigFileTest(UsingModulesMixin, CoverageTest):
coverage.Coverage()
@pytest.mark.skipif(sys.version_info >= (3, 11), reason="Python 3.11 has toml in stdlib")
- def test_no_toml_installed_pyproject_no_coverage(self):
+ def test_no_toml_installed_pyproject_no_coverage(self) -> None:
# It's ok to have non-coverage pyproject.toml without toml installed.
self.make_file("pyproject.toml", """\
# A toml file!
@@ -767,7 +768,7 @@ class ConfigFileTest(UsingModulesMixin, CoverageTest):
assert not cov.config.branch
assert cov.config.data_file == ".coverage"
- def test_exceptions_from_missing_toml_things(self):
+ def test_exceptions_from_missing_toml_things(self) -> None:
self.make_file("pyproject.toml", """\
[tool.coverage.run]
branch = true
diff --git a/tests/test_context.py b/tests/test_context.py
index 4a1635a2..d818c790 100644
--- a/tests/test_context.py
+++ b/tests/test_context.py
@@ -5,11 +5,14 @@
import inspect
import os.path
+
+from typing import Any, List, Optional, Tuple
from unittest import mock
import coverage
from coverage.context import qualname_from_frame
from coverage.data import CoverageData, sorted_lines
+from coverage.types import TArc, TCovKwargs, TLineNo
from tests.coveragetest import CoverageTest
from tests.helpers import assert_count_equal
@@ -18,14 +21,14 @@ from tests.helpers import assert_count_equal
class StaticContextTest(CoverageTest):
"""Tests of the static context."""
- def test_no_context(self):
+ def test_no_context(self) -> None:
self.make_file("main.py", "a = 1")
cov = coverage.Coverage()
self.start_import_stop(cov, "main")
data = cov.get_data()
assert_count_equal(data.measured_contexts(), [""])
- def test_static_context(self):
+ def test_static_context(self) -> None:
self.make_file("main.py", "a = 1")
cov = coverage.Coverage(context="gooey")
self.start_import_stop(cov, "main")
@@ -42,7 +45,7 @@ class StaticContextTest(CoverageTest):
LINES = [1, 2, 4]
ARCS = [(-1, 1), (1, 2), (2, 4), (4, -1)]
- def run_red_blue(self, **options):
+ def run_red_blue(self, **options: TCovKwargs) -> Tuple[CoverageData, CoverageData]:
"""Run red.py and blue.py, and return their CoverageData objects."""
self.make_file("red.py", self.SOURCE)
red_cov = coverage.Coverage(context="red", data_suffix="r", source=["."], **options)
@@ -58,7 +61,7 @@ class StaticContextTest(CoverageTest):
return red_data, blue_data
- def test_combining_line_contexts(self):
+ def test_combining_line_contexts(self) -> None:
red_data, blue_data = self.run_red_blue()
for datas in [[red_data, blue_data], [blue_data, red_data]]:
combined = CoverageData(suffix="combined")
@@ -73,7 +76,7 @@ class StaticContextTest(CoverageTest):
fred = full_names['red.py']
fblue = full_names['blue.py']
- def assert_combined_lines(filename, context, lines):
+ def assert_combined_lines(filename: str, context: str, lines: List[TLineNo]) -> None:
# pylint: disable=cell-var-from-loop
combined.set_query_context(context)
assert combined.lines(filename) == lines
@@ -83,7 +86,7 @@ class StaticContextTest(CoverageTest):
assert_combined_lines(fblue, 'red', [])
assert_combined_lines(fblue, 'blue', self.LINES)
- def test_combining_arc_contexts(self):
+ def test_combining_arc_contexts(self) -> None:
red_data, blue_data = self.run_red_blue(branch=True)
for datas in [[red_data, blue_data], [blue_data, red_data]]:
combined = CoverageData(suffix="combined")
@@ -98,7 +101,7 @@ class StaticContextTest(CoverageTest):
fred = full_names['red.py']
fblue = full_names['blue.py']
- def assert_combined_lines(filename, context, lines):
+ def assert_combined_lines(filename: str, context: str, lines: List[TLineNo]) -> None:
# pylint: disable=cell-var-from-loop
combined.set_query_context(context)
assert combined.lines(filename) == lines
@@ -108,7 +111,7 @@ class StaticContextTest(CoverageTest):
assert_combined_lines(fblue, 'red', [])
assert_combined_lines(fblue, 'blue', self.LINES)
- def assert_combined_arcs(filename, context, lines):
+ def assert_combined_arcs(filename: str, context: str, lines: List[TArc]) -> None:
# pylint: disable=cell-var-from-loop
combined.set_query_context(context)
assert combined.arcs(filename) == lines
@@ -149,7 +152,7 @@ class DynamicContextTest(CoverageTest):
TEST_ONE_LINES = [5, 6, 2]
TEST_TWO_LINES = [9, 10, 11, 13, 14, 15, 2]
- def test_dynamic_alone(self):
+ def test_dynamic_alone(self) -> None:
self.make_file("two_tests.py", self.SOURCE)
cov = coverage.Coverage(source=["."])
cov.set_option("run:dynamic_context", "test_function")
@@ -163,7 +166,7 @@ class DynamicContextTest(CoverageTest):
["", "two_tests.test_one", "two_tests.test_two"]
)
- def assert_context_lines(context, lines):
+ def assert_context_lines(context: str, lines: List[TLineNo]) -> None:
data.set_query_context(context)
assert_count_equal(lines, sorted_lines(data, fname))
@@ -171,7 +174,7 @@ class DynamicContextTest(CoverageTest):
assert_context_lines("two_tests.test_one", self.TEST_ONE_LINES)
assert_context_lines("two_tests.test_two", self.TEST_TWO_LINES)
- def test_static_and_dynamic(self):
+ def test_static_and_dynamic(self) -> None:
self.make_file("two_tests.py", self.SOURCE)
cov = coverage.Coverage(context="stat", source=["."])
cov.set_option("run:dynamic_context", "test_function")
@@ -185,7 +188,7 @@ class DynamicContextTest(CoverageTest):
["stat", "stat|two_tests.test_one", "stat|two_tests.test_two"]
)
- def assert_context_lines(context, lines):
+ def assert_context_lines(context: str, lines: List[TLineNo]) -> None:
data.set_query_context(context)
assert_count_equal(lines, sorted_lines(data, fname))
@@ -194,24 +197,24 @@ class DynamicContextTest(CoverageTest):
assert_context_lines("stat|two_tests.test_two", self.TEST_TWO_LINES)
-def get_qualname():
+def get_qualname() -> Optional[str]:
"""Helper to return qualname_from_frame for the caller."""
stack = inspect.stack()[1:]
if any(sinfo[0].f_code.co_name == "get_qualname" for sinfo in stack):
# We're calling ourselves recursively, maybe because we're testing
# properties. Return an int to try to get back on track.
- return 17
+ return 17 # type: ignore[return-value]
caller_frame = stack[0][0]
return qualname_from_frame(caller_frame)
# pylint: disable=missing-class-docstring, missing-function-docstring, unused-argument
class Parent:
- def meth(self):
+ def meth(self) -> Optional[str]:
return get_qualname()
@property
- def a_property(self):
+ def a_property(self) -> Optional[str]:
return get_qualname()
class Child(Parent):
@@ -223,16 +226,16 @@ class SomethingElse:
class MultiChild(SomethingElse, Child):
pass
-def no_arguments():
+def no_arguments() -> Optional[str]:
return get_qualname()
-def plain_old_function(a, b):
+def plain_old_function(a: Any, b: Any) -> Optional[str]:
return get_qualname()
-def fake_out(self):
+def fake_out(self: Any) -> Optional[str]:
return get_qualname()
-def patch_meth(self):
+def patch_meth(self: Any) -> Optional[str]:
return get_qualname()
# pylint: enable=missing-class-docstring, missing-function-docstring, unused-argument
@@ -246,38 +249,38 @@ class QualnameTest(CoverageTest):
run_in_temp_dir = False
- def test_method(self):
+ def test_method(self) -> None:
assert Parent().meth() == "tests.test_context.Parent.meth"
- def test_inherited_method(self):
+ def test_inherited_method(self) -> None:
assert Child().meth() == "tests.test_context.Parent.meth"
- def test_mi_inherited_method(self):
+ def test_mi_inherited_method(self) -> None:
assert MultiChild().meth() == "tests.test_context.Parent.meth"
- def test_no_arguments(self):
+ def test_no_arguments(self) -> None:
assert no_arguments() == "tests.test_context.no_arguments"
- def test_plain_old_function(self):
+ def test_plain_old_function(self) -> None:
assert plain_old_function(0, 1) == "tests.test_context.plain_old_function"
- def test_fake_out(self):
+ def test_fake_out(self) -> None:
assert fake_out(0) == "tests.test_context.fake_out"
- def test_property(self):
+ def test_property(self) -> None:
assert Parent().a_property == "tests.test_context.Parent.a_property"
- def test_changeling(self):
+ def test_changeling(self) -> None:
c = Child()
- c.meth = patch_meth
- assert c.meth(c) == "tests.test_context.patch_meth"
+ c.meth = patch_meth # type: ignore[assignment]
+ assert c.meth(c) == "tests.test_context.patch_meth" # type: ignore[call-arg]
- def test_bug_829(self):
+ def test_bug_829(self) -> None:
# A class with a name like a function shouldn't confuse qualname_from_frame.
class test_something: # pylint: disable=unused-variable
assert get_qualname() is None
- def test_bug_1210(self):
+ def test_bug_1210(self) -> None:
# Under pyarmor (an obfuscator), a function can have a "self" argument,
# but then not have a "self" local.
co = mock.Mock(co_name="a_co_name", co_argcount=1, co_varnames=["self"])
diff --git a/tox.ini b/tox.ini
index fc255dc2..1dc67de7 100644
--- a/tox.ini
+++ b/tox.ini
@@ -95,15 +95,15 @@ deps =
setenv =
{[testenv]setenv}
- C__B=coverage/__init__.py coverage/__main__.py coverage/annotate.py coverage/bytecode.py
- C_CC=coverage/cmdline.py coverage/collector.py coverage/config.py coverage/context.py coverage/control.py
- C_DE=coverage/data.py coverage/disposition.py coverage/env.py coverage/exceptions.py
- C_FN=coverage/files.py coverage/inorout.py coverage/jsonreport.py coverage/lcovreport.py coverage/multiproc.py coverage/numbits.py
- C_OP=coverage/parser.py coverage/phystokens.py coverage/plugin.py coverage/plugin_support.py coverage/python.py
- C_QZ=coverage/report.py coverage/results.py coverage/sqldata.py coverage/tomlconfig.py coverage/types.py coverage/version.py coverage/xmlreport.py
- T_AC=tests/test_annotate.py tests/test_api.py tests/test_arcs.py tests/test_cmdline.py tests/test_collector.py tests/test_concurrency.py
- T_DZ=tests/goldtest.py tests/helpers.py tests/test_html.py tests/test_python.py tests/test_xml.py
- TYPEABLE={env:C__B} {env:C_CC} {env:C_DE} {env:C_FN} {env:C_OP} {env:C_QZ} {env:T_AC} {env:T_DZ}
+ C1=coverage/__init__.py coverage/__main__.py coverage/annotate.py coverage/bytecode.py
+ C2=coverage/cmdline.py coverage/collector.py coverage/config.py coverage/context.py coverage/control.py
+ C3=coverage/data.py coverage/disposition.py coverage/env.py coverage/exceptions.py
+ C4=coverage/files.py coverage/inorout.py coverage/jsonreport.py coverage/lcovreport.py coverage/multiproc.py coverage/numbits.py
+ C5=coverage/parser.py coverage/phystokens.py coverage/plugin.py coverage/plugin_support.py coverage/python.py
+ C6=coverage/report.py coverage/results.py coverage/sqldata.py coverage/tomlconfig.py coverage/types.py coverage/version.py coverage/xmlreport.py
+ T1=tests/test_annotate.py tests/test_api.py tests/test_arcs.py tests/test_cmdline.py tests/test_collector.py tests/test_concurrency.py tests/test_config.py tests/test_context.py
+ T2=tests/goldtest.py tests/helpers.py tests/test_html.py tests/test_python.py tests/test_xml.py
+ TYPEABLE={env:C1} {env:C2} {env:C3} {env:C4} {env:C5} {env:C6} {env:T1} {env:T2}
commands =
# PYVERSIONS