-
-
Notifications
You must be signed in to change notification settings - Fork 447
Report data file errors in more detail #1782
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
…ths, and make helpful suggestions
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ | |
import sys | ||
import textwrap | ||
import traceback | ||
from contextlib import suppress | ||
|
||
from typing import cast, Any, NoReturn | ||
|
||
|
@@ -24,7 +25,8 @@ | |
from coverage.control import DEFAULT_DATAFILE | ||
from coverage.data import combinable_files, debug_data_file | ||
from coverage.debug import info_header, short_stack, write_formatted_info | ||
from coverage.exceptions import _BaseCoverageException, _ExceptionDuringRun, NoSource | ||
from coverage.exceptions import _BaseCoverageException, _ExceptionDuringRun, NoSource, \ | ||
NoDataFilesFoundError | ||
from coverage.execfile import PyRunner | ||
from coverage.results import display_covered, should_fail_under | ||
from coverage.version import __url__ | ||
|
@@ -882,9 +884,10 @@ def do_debug(self, args: list[str]) -> int: | |
print(info_header("data")) | ||
data_file = self.coverage.config.data_file | ||
debug_data_file(data_file) | ||
for filename in combinable_files(data_file): | ||
print("-----") | ||
debug_data_file(filename) | ||
with suppress(NoDataFilesFoundError): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we need to suppress this error here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We do not, but I tried to limit how many outputs I changed. Would you like this to display a friendly error instead? |
||
for filename in combinable_files(data_file): | ||
print("-----") | ||
debug_data_file(filename) | ||
elif args[0] == "config": | ||
write_formatted_info(print, "config", self.coverage.config.debug_info()) | ||
elif args[0] == "premain": | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,7 @@ | |
|
||
import coverage | ||
from coverage.data import CoverageData, add_data_to_hash | ||
from coverage.exceptions import NoDataError | ||
from coverage.exceptions import DataFileOrDirectoryNotFoundError | ||
from coverage.files import flat_rootname | ||
from coverage.misc import ( | ||
ensure_dir, file_be_gone, Hasher, isolate_module, format_local_datetime, | ||
|
@@ -317,7 +317,9 @@ def report(self, morfs: Iterable[TMorf] | None) -> float: | |
file_be_gone(os.path.join(self.directory, ftr.html_filename)) | ||
|
||
if not have_data: | ||
raise NoDataError("No data to report.") | ||
raise DataFileOrDirectoryNotFoundError.new_for_data_file_or_directory( | ||
os.path.dirname(self.coverage.get_data().base_filename()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have to think through whether the message here is correct. Is it always that the file doesn't exist? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's good that the exceptions centralize the messages, but everywhere this exception is created it uses the same fairly complex expression. Can we centralize that as well? |
||
) | ||
|
||
self.make_directory() | ||
self.make_local_static_report_files() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -300,7 +300,13 @@ def test_empty_reporting(self) -> None: | |
# empty summary reports raise exception, just like the xml report | ||
cov = coverage.Coverage() | ||
cov.erase() | ||
with pytest.raises(NoDataError, match="No data to report."): | ||
with pytest.raises( | ||
NoDataError, | ||
match=( | ||
r"^The data file or directory `(.+?)` could not be found\. Perhaps `coverage " | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "The data file or directory" seems odd to me. Don't we know whether we are expecting a file or directory? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These results depend on the paths entered in the CLI. As far as I understand the code these are allowed to be data file paths or paths to directories containing data files. If the path does not exist, I'm not sure we would know if the user meant a file or a directory. |
||
r"combine` must be run first\.$" | ||
) | ||
): | ||
cov.report() | ||
|
||
def test_completely_zero_reporting(self) -> None: | ||
|
@@ -446,7 +452,13 @@ def test_combining_twice(self) -> None: | |
self.assert_exists(".coverage") | ||
|
||
cov2 = coverage.Coverage() | ||
with pytest.raises(NoDataError, match=r"No data to combine"): | ||
with pytest.raises( | ||
NoDataError, | ||
match=( | ||
r"^The data directory `(.+?)` does not contain any data files. Perhaps `coverage " | ||
r"combine` must be run first.$" | ||
) | ||
): | ||
cov2.combine(strict=True, keep=False) | ||
|
||
cov3 = coverage.Coverage() | ||
|
@@ -1326,7 +1338,7 @@ def test_combine_parallel_data(self) -> None: | |
# Running combine again should fail, because there are no parallel data | ||
# files to combine. | ||
cov = coverage.Coverage() | ||
with pytest.raises(NoDataError, match=r"No data to combine"): | ||
with pytest.raises(NoDataError): | ||
cov.combine(strict=True) | ||
|
||
# And the originally combined data is still there. | ||
|
@@ -1376,7 +1388,13 @@ def test_combine_no_usable_files(self) -> None: | |
# Combine the parallel coverage data files into .coverage, but nothing is readable. | ||
cov = coverage.Coverage() | ||
with pytest.warns(Warning) as warns: | ||
with pytest.raises(NoDataError, match=r"No usable data files"): | ||
with pytest.raises( | ||
NoDataError, | ||
match=( | ||
r"^The following data files are unusable, perhaps because they do not contain " | ||
r"valid coverage information:\n- `(.+?)`\n- `(.+?)`$" | ||
) | ||
): | ||
cov.combine(strict=True) | ||
|
||
warn_rx = re.compile( | ||
|
Uh oh!
There was an error while loading. Please reload this page.