Skip to content

Commit 8bf5006

Browse files
committed
Implement most of @nedbat's feedback
1 parent e1dd118 commit 8bf5006

13 files changed

+44
-43
lines changed

coverage/cmdline.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@
2525
from coverage.control import DEFAULT_DATAFILE
2626
from coverage.data import combinable_files, debug_data_file
2727
from coverage.debug import info_header, short_stack, write_formatted_info
28-
from coverage.exceptions import _BaseCoverageException, _ExceptionDuringRun, NoSource, \
29-
NoDataFilesFoundError
28+
from coverage.exceptions import (
29+
_BaseCoverageException, _ExceptionDuringRun, NoSource, NoDataFilesFoundError,
30+
)
3031
from coverage.execfile import PyRunner
3132
from coverage.results import display_covered, should_fail_under
3233
from coverage.version import __url__

coverage/data.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def combinable_files(data_file: str, data_paths: Iterable[str] | None = None) ->
8282
pattern = glob.escape(os.path.join(os.path.abspath(p), local)) +".*"
8383
files_to_combine.extend(glob.glob(pattern))
8484
else:
85-
raise DataFileOrDirectoryNotFoundError.new_for_data_file_or_directory(
85+
raise DataFileOrDirectoryNotFoundError.new(
8686
p, is_combining=True
8787
)
8888

@@ -91,7 +91,7 @@ def combinable_files(data_file: str, data_paths: Iterable[str] | None = None) ->
9191
files_to_combine = [fnm for fnm in files_to_combine if not fnm.endswith("-journal")]
9292

9393
if not files_to_combine:
94-
raise NoDataFilesFoundError.new_for_data_directory(data_dir)
94+
raise NoDataFilesFoundError.new(data_dir)
9595

9696
# Sorting isn't usually needed, since it shouldn't matter what order files
9797
# are combined, but sorting makes tests more predictable, and makes
@@ -197,7 +197,7 @@ def combine_parallel_data(
197197
file_be_gone(f)
198198

199199
if strict and not combined_any:
200-
raise UnusableDataFilesError.new_for_data_files(*files_to_combine)
200+
raise UnusableDataFilesError.new(*files_to_combine)
201201

202202

203203
def debug_data_file(filename: str) -> None:

coverage/exceptions.py

+11-11
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
def _message_append_combine_hint(message: str, is_combining: bool) -> str:
1212
"""Append information about the combine command to error messages."""
1313
if not is_combining:
14-
message += " Perhaps `coverage combine` must be run first."
14+
message += " Perhaps 'coverage combine' must be run first."
1515
return message
1616

1717

@@ -43,48 +43,48 @@ class NoDataError(CoverageException):
4343
class DataFileOrDirectoryNotFoundError(NoDataError):
4444
"""A data file or data directory could be found."""
4545
@classmethod
46-
def new_for_data_file_or_directory(
46+
def new(
4747
cls, data_file_or_directory_path: str, *, is_combining: bool = False
48-
) -> 'DataFileOrDirectoryNotFoundError':
48+
) -> DataFileOrDirectoryNotFoundError:
4949
"""
5050
Create a new instance.
5151
"""
5252
message = (
53-
f"The data file or directory `{os.path.abspath(data_file_or_directory_path)}` could not"
54-
" be found."
53+
f"The data file or directory '{os.path.abspath(data_file_or_directory_path)}' could not"
54+
+ " be found."
5555
)
5656
return cls(_message_append_combine_hint(message, is_combining))
5757

5858

5959
class NoDataFilesFoundError(NoDataError):
6060
"""No data files could be found in a data directory."""
6161
@classmethod
62-
def new_for_data_directory(
62+
def new(
6363
cls, data_directory_path: str, *, is_combining: bool = False
6464
) -> 'NoDataFilesFoundError':
6565
"""
6666
Create a new instance.
6767
"""
6868
message = (
69-
f"The data directory `{os.path.abspath(data_directory_path)}` does not contain any data"
70-
" files."
69+
f"The data directory '{os.path.abspath(data_directory_path)}' does not contain any data"
70+
+ " files."
7171
)
7272
return cls(_message_append_combine_hint(message, is_combining))
7373

7474

7575
class UnusableDataFilesError(NoDataError):
7676
"""The given data files are unusable."""
7777
@classmethod
78-
def new_for_data_files(cls, *data_file_paths: str) -> 'UnusableDataFilesError':
78+
def new(cls, *data_file_paths: str) -> 'UnusableDataFilesError':
7979
"""
8080
Create a new instance.
8181
"""
8282
message = (
8383
"The following data files are unusable, perhaps because they do not contain valid"
84-
" coverage information:"
84+
+ " coverage information:"
8585
)
8686
for data_file_path in data_file_paths:
87-
message += f"\n- `{os.path.abspath(data_file_path)}`"
87+
message += f"\n- '{os.path.abspath(data_file_path)}'"
8888

8989
return cls(message)
9090

coverage/html.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ def report(self, morfs: Iterable[TMorf] | None) -> float:
317317
file_be_gone(os.path.join(self.directory, ftr.html_filename))
318318

319319
if not have_data:
320-
raise DataFileOrDirectoryNotFoundError.new_for_data_file_or_directory(
320+
raise DataFileOrDirectoryNotFoundError.new(
321321
os.path.dirname(self.coverage.get_data().base_filename())
322322
)
323323

coverage/report.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ def report(self, morfs: Iterable[TMorf] | None, outfile: IO[str] | None = None)
183183
self.report_one_file(fr, analysis)
184184

185185
if not self.total.n_files and not self.skipped_count:
186-
raise DataFileOrDirectoryNotFoundError.new_for_data_file_or_directory(
186+
raise DataFileOrDirectoryNotFoundError.new(
187187
os.path.dirname(self.coverage.get_data().base_filename())
188188
)
189189

coverage/report_core.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def get_analysis_to_report(
9494
fr_morfs = [(fr, morf) for (fr, morf) in fr_morfs if not matcher.match(fr.filename)]
9595

9696
if not fr_morfs:
97-
raise DataFileOrDirectoryNotFoundError.new_for_data_file_or_directory(
97+
raise DataFileOrDirectoryNotFoundError.new(
9898
os.path.dirname(coverage.get_data().base_filename())
9999
)
100100

tests/test_api.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -303,8 +303,8 @@ def test_empty_reporting(self) -> None:
303303
with pytest.raises(
304304
NoDataError,
305305
match=(
306-
r"^The data file or directory `(.+?)` could not be found\. Perhaps `coverage "
307-
r"combine` must be run first\.$"
306+
r"^The data file or directory '(.+?)' could not be found\. Perhaps 'coverage "
307+
r"combine' must be run first\.$"
308308
)
309309
):
310310
cov.report()
@@ -455,8 +455,8 @@ def test_combining_twice(self) -> None:
455455
with pytest.raises(
456456
NoDataError,
457457
match=(
458-
r"^The data directory `(.+?)` does not contain any data files. Perhaps `coverage "
459-
r"combine` must be run first.$"
458+
r"^The data directory '(.+?)' does not contain any data files. Perhaps 'coverage "
459+
r"combine' must be run first.$"
460460
)
461461
):
462462
cov2.combine(strict=True, keep=False)
@@ -1392,7 +1392,7 @@ def test_combine_no_usable_files(self) -> None:
13921392
NoDataError,
13931393
match=(
13941394
r"^The following data files are unusable, perhaps because they do not contain "
1395-
r"valid coverage information:\n- `(.+?)`\n- `(.+?)`$"
1395+
r"valid coverage information:\n- '(.+?)'\n- '(.+?)'$"
13961396
)
13971397
):
13981398
cov.combine(strict=True)

tests/test_coverage.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -1638,8 +1638,8 @@ def test_no_data_to_report_on_annotate(self) -> None:
16381638
with pytest.raises(
16391639
NoDataError,
16401640
match=(
1641-
r"^The data file or directory `(.+?)` could not be found\. Perhaps `coverage "
1642-
r"combine` must be run first\.$"
1641+
r"^The data file or directory '(.+?)' could not be found\. Perhaps 'coverage "
1642+
r"combine' must be run first\.$"
16431643
)
16441644
):
16451645
self.command_line("annotate -d ann")
@@ -1651,8 +1651,8 @@ def test_no_data_to_report_on_html(self) -> None:
16511651
with pytest.raises(
16521652
NoDataError,
16531653
match=(
1654-
r"^The data file or directory `(.+?)` could not be found\. Perhaps `coverage "
1655-
r"combine` must be run first\.$"
1654+
r"^The data file or directory '(.+?)' could not be found\. Perhaps 'coverage "
1655+
r"combine' must be run first\.$"
16561656
)
16571657
):
16581658
self.command_line("html -d htmlcov")
@@ -1663,8 +1663,8 @@ def test_no_data_to_report_on_xml(self) -> None:
16631663
with pytest.raises(
16641664
NoDataError,
16651665
match=(
1666-
r"^The data file or directory `(.+?)` could not be found\. Perhaps `coverage "
1667-
r"combine` must be run first\.$"
1666+
r"^The data file or directory '(.+?)' could not be found\. Perhaps 'coverage "
1667+
r"combine' must be run first\.$"
16681668
)
16691669
):
16701670
self.command_line("xml")

tests/test_data.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -915,7 +915,7 @@ def test_combining_from_files(self) -> None:
915915

916916
def test_combining_from_nonexistent_directories(self) -> None:
917917
covdata = DebugCoverageData()
918-
msg = r"^The data file or directory `(.+?)` could not be found.$"
918+
msg = r"^The data file or directory '(.+?)' could not be found.$"
919919
with pytest.raises(NoDataError, match=msg):
920920
combine_parallel_data(covdata, data_paths=['xyzzy'])
921921

tests/test_html.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -429,8 +429,8 @@ def test_dothtml_not_python(self) -> None:
429429
with pytest.raises(
430430
NoDataError,
431431
match=(
432-
r"^The data file or directory `(.+?)` could not be found\. Perhaps `coverage "
433-
r"combine` must be run first\.$"
432+
r"^The data file or directory '(.+?)' could not be found\. Perhaps 'coverage "
433+
r"combine' must be run first\.$"
434434
)
435435
):
436436
cov.html_report()

tests/test_process.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1145,8 +1145,8 @@ def test_report(self) -> None:
11451145
st, out = self.run_command_status("coverage report")
11461146
assert re.match(
11471147
(
1148-
r"The data file or directory `([^`]+?)` could not be found\. Perhaps `coverage "
1149-
r"combine` must be run first\."
1148+
r"The data file or directory '([^']+?)' could not be found\. Perhaps 'coverage "
1149+
+ r"combine' must be run first\."
11501150
),
11511151
out
11521152
)

tests/test_report.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -554,8 +554,8 @@ def test_report_skip_covered_no_data(self) -> None:
554554
with pytest.raises(
555555
NoDataError,
556556
match=(
557-
r"^The data file or directory `(.+?)` could not be found\. Perhaps `coverage "
558-
r"combine` must be run first\.$"
557+
r"^The data file or directory '(.+?)' could not be found\. Perhaps 'coverage "
558+
r"combine' must be run first\.$"
559559
)
560560
):
561561
self.get_report(cov, skip_covered=True)
@@ -753,8 +753,8 @@ def test_dotpy_not_python_ignored(self) -> None:
753753
with pytest.raises(
754754
NoDataError,
755755
match=(
756-
r"^The data file or directory `(.+?)` could not be found\. Perhaps `coverage "
757-
r"combine` must be run first\.$"
756+
r"^The data file or directory '(.+?)' could not be found\. Perhaps 'coverage "
757+
r"combine' must be run first\.$"
758758
)
759759
):
760760
with pytest.warns(Warning) as warns:
@@ -776,8 +776,8 @@ def test_dothtml_not_python(self) -> None:
776776
with pytest.raises(
777777
NoDataError,
778778
match=(
779-
r"^The data file or directory `(.+?)` could not be found\. Perhaps `coverage "
780-
r"combine` must be run first\.$"
779+
r"^The data file or directory '(.+?)' could not be found\. Perhaps 'coverage "
780+
r"combine' must be run first\.$"
781781
)
782782
):
783783
self.get_report(cov, morfs=["mycode.html"])

tests/test_xml.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,8 @@ def test_no_data(self) -> None:
148148
with pytest.raises(
149149
NoDataError,
150150
match=(
151-
r"^The data file or directory `(.+?)` could not be found\. Perhaps `coverage "
152-
r"combine` must be run first\.$"
151+
r"^The data file or directory '(.+?)' could not be found\. Perhaps 'coverage "
152+
r"combine' must be run first\.$"
153153
)
154154
):
155155
self.run_xml_report()

0 commit comments

Comments
 (0)