summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2021-07-28 17:29:52 -0400
committerNed Batchelder <ned@nedbatchelder.com>2021-07-28 17:29:52 -0400
commitc5c1ba084b0b548ff8869cbc086e81608c329eb6 (patch)
tree6b2457d8a63aaccd0099b1e5fc2592caf7e44ac5
parent82213596f5301981ea59c3067f8738ff9dd54bbc (diff)
downloadpython-coveragepy-git-c5c1ba084b0b548ff8869cbc086e81608c329eb6.tar.gz
refactor: convert %-strings to f-strings
-rw-r--r--coverage/control.py8
-rw-r--r--coverage/data.py2
-rw-r--r--coverage/execfile.py4
-rw-r--r--coverage/inorout.py7
-rw-r--r--coverage/misc.py8
-rw-r--r--coverage/parser.py7
-rw-r--r--coverage/plugin_support.py2
-rw-r--r--coverage/sqldata.py2
-rw-r--r--coverage/tomlconfig.py4
-rw-r--r--tests/goldtest.py4
10 files changed, 19 insertions, 29 deletions
diff --git a/coverage/control.py b/coverage/control.py
index fb7f09c4..e1eb9add 100644
--- a/coverage/control.py
+++ b/coverage/control.py
@@ -443,9 +443,7 @@ class Coverage:
elif dycon == "test_function":
context_switchers = [should_start_context_test_function]
else:
- raise CoverageException(
- f"Don't understand dynamic_context setting: {dycon!r}"
- )
+ raise CoverageException(f"Don't understand dynamic_context setting: {dycon!r}")
context_switchers.extend(
plugin.dynamic_context for plugin in self._plugins.context_switchers
@@ -599,9 +597,7 @@ class Coverage:
"""
if not self._started: # pragma: part started
- raise CoverageException(
- "Cannot switch context, coverage is not started"
- )
+ raise CoverageException("Cannot switch context, coverage is not started")
if self._collector.should_start_context:
self._warn("Conflicting dynamic contexts", slug="dynamic-conflict", once=True)
diff --git a/coverage/data.py b/coverage/data.py
index 752822b7..7ba51dc8 100644
--- a/coverage/data.py
+++ b/coverage/data.py
@@ -91,7 +91,7 @@ def combine_parallel_data(data, aliases=None, data_paths=None, strict=False, kee
pattern = os.path.join(os.path.abspath(p), localdot)
files_to_combine.extend(glob.glob(pattern))
else:
- raise CoverageException(f"Couldn't combine from non-existent path '{p}'")
+ raise CoverageException(f"Couldn't combine from non-existent path {p!r}")
if strict and not files_to_combine:
raise CoverageException("No data to combine")
diff --git a/coverage/execfile.py b/coverage/execfile.py
index 66020019..80277815 100644
--- a/coverage/execfile.py
+++ b/coverage/execfile.py
@@ -278,7 +278,7 @@ def make_code_from_py(filename):
try:
source = get_python_source(filename)
except (OSError, NoSource) as exc:
- raise NoSource("No file to run: '%s'" % filename) from exc
+ raise NoSource(f"No file to run: {filename!r}") from exc
code = compile_unicode(source, filename, "exec")
return code
@@ -289,7 +289,7 @@ def make_code_from_pyc(filename):
try:
fpyc = open(filename, "rb")
except OSError as exc:
- raise NoCode("No file to run: '%s'" % filename) from exc
+ raise NoCode(f"No file to run: {filename!r}") from exc
with fpyc:
# First four bytes are a version-specific magic number. It has to
diff --git a/coverage/inorout.py b/coverage/inorout.py
index 32eb9079..a161fa61 100644
--- a/coverage/inorout.py
+++ b/coverage/inorout.py
@@ -369,8 +369,7 @@ class InOrOut:
if not disp.has_dynamic_filename:
if not disp.source_filename:
raise CoverageException(
- "Plugin %r didn't set source_filename for %r" %
- (plugin, disp.original_filename)
+ f"Plugin {plugin!r} didn't set source_filename for {disp.original_filename!r}"
)
reason = self.check_include_omit_etc(disp.source_filename, frame)
if reason:
@@ -487,7 +486,7 @@ class InOrOut:
"""
mod = sys.modules.get(pkg)
if mod is None:
- self.warn("Module %s was never imported." % pkg, slug="module-not-imported")
+ self.warn(f"Module {pkg} was never imported.", slug="module-not-imported")
return
if module_is_namespace(mod):
@@ -496,7 +495,7 @@ class InOrOut:
return
if not module_has_file(mod):
- self.warn("Module %s has no Python source." % pkg, slug="module-not-python")
+ self.warn(f"Module {pkg} has no Python source.", slug="module-not-python")
return
# The module was in sys.modules, and seems like a module with code, but
diff --git a/coverage/misc.py b/coverage/misc.py
index bdc0b3cf..91ccd964 100644
--- a/coverage/misc.py
+++ b/coverage/misc.py
@@ -121,7 +121,7 @@ def expensive(fn):
def _wrapper(self):
if hasattr(self, attr):
- raise AssertionError("Shouldn't have called %s more than once" % fn.__name__)
+ raise AssertionError(f"Shouldn't have called {fn.__name__} more than once")
setattr(self, attr, True)
return fn(self)
return _wrapper
@@ -245,12 +245,10 @@ def _needs_to_implement(that, func_name):
else:
thing = "Class"
klass = that.__class__
- name = "{klass.__module__}.{klass.__name__}".format(klass=klass)
+ name = f"{klass.__module__}.{klass.__name__}"
raise NotImplementedError(
- "{thing} {name!r} needs to implement {func_name}()".format(
- thing=thing, name=name, func_name=func_name
- )
+ f"{thing} {name!r} needs to implement {func_name}()"
)
diff --git a/coverage/parser.py b/coverage/parser.py
index 18458147..a3a41200 100644
--- a/coverage/parser.py
+++ b/coverage/parser.py
@@ -41,7 +41,7 @@ class PythonParser:
try:
self.text = get_python_source(self.filename)
except OSError as err:
- raise NoSource(f"No source for code: '{self.filename}': {err}") from err
+ raise NoSource(f"No source for code: {self.filename!r}: {err}") from err
self.exclude = exclude
@@ -238,9 +238,8 @@ class PythonParser:
else:
lineno = err.args[1][0] # TokenError
raise NotPython(
- "Couldn't parse '%s' as Python source: '%s' at line %d" % (
- self.filename, err.args[0], lineno
- )
+ f"Couldn't parse {self.filename!r} as Python source: " +
+ f"{err.args[0]!r} at line {lineno}"
) from err
self.excluded = self.first_lines(self.raw_excluded)
diff --git a/coverage/plugin_support.py b/coverage/plugin_support.py
index 7accc56f..1b5ba8d7 100644
--- a/coverage/plugin_support.py
+++ b/coverage/plugin_support.py
@@ -45,7 +45,7 @@ class Plugins:
coverage_init = getattr(mod, "coverage_init", None)
if not coverage_init:
raise CoverageException(
- "Plugin module %r didn't define a coverage_init function" % module
+ f"Plugin module {module!r} didn't define a coverage_init function"
)
options = config.get_plugin_options(module)
diff --git a/coverage/sqldata.py b/coverage/sqldata.py
index db3ab73a..d27e12a2 100644
--- a/coverage/sqldata.py
+++ b/coverage/sqldata.py
@@ -541,7 +541,7 @@ class CoverageData(SimpleReprMixin):
file_id = self._file_id(filename)
if file_id is None:
raise CoverageException(
- f"Can't add file tracer data for unmeasured file '{filename}'"
+ f"Can't add file tracer data for unmeasured file {filename!r}"
)
existing_plugin = self.file_tracer(filename)
diff --git a/coverage/tomlconfig.py b/coverage/tomlconfig.py
index 8212cfe6..203192c9 100644
--- a/coverage/tomlconfig.py
+++ b/coverage/tomlconfig.py
@@ -147,9 +147,7 @@ class TomlConfigParser:
try:
re.compile(value)
except re.error as e:
- raise CoverageException(
- f"Invalid [{name}].{option} value {value!r}: {e}"
- ) from e
+ raise CoverageException(f"Invalid [{name}].{option} value {value!r}: {e}") from e
return values
def getint(self, section, option):
diff --git a/tests/goldtest.py b/tests/goldtest.py
index 7321166c..cd946efb 100644
--- a/tests/goldtest.py
+++ b/tests/goldtest.py
@@ -109,7 +109,7 @@ def compare(
for f in actual_only:
save_mismatch(f)
- assert not text_diff, "Files differ: %s" % '\n'.join(text_diff)
+ assert not text_diff, "Files differ: " + "\n".join(text_diff)
assert not expected_only, f"Files in {expected_dir} only: {expected_only}"
if not actual_extra:
@@ -152,7 +152,7 @@ def contains_any(filename, *strlist):
return
assert False, ( # pragma: only failure
- "Missing content in %s: %r [1 of %d]" % (filename, strlist[0], len(strlist),)
+ f"Missing content in {filename}: {strlist[0]!r} [1 of {len(strlist)}]"
)