-
-
Notifications
You must be signed in to change notification settings - Fork 445
/
Copy pathexceptions.py
123 lines (87 loc) · 3.2 KB
/
exceptions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0
# For details: https://github.com/nedbat/coveragepy/blob/master/NOTICE.txt
"""Exceptions coverage.py can raise."""
from __future__ import annotations
import os.path
def _message_append_combine_hint(message: str, is_combining: bool) -> str:
"""Append information about the combine command to error messages."""
if not is_combining:
message += " Perhaps 'coverage combine' must be run first."
return message
class _BaseCoverageException(Exception):
"""The base-base of all Coverage exceptions."""
pass
class CoverageException(_BaseCoverageException):
"""The base class of all exceptions raised by Coverage.py."""
pass
class ConfigError(_BaseCoverageException):
"""A problem with a config file, or a value in one."""
pass
class DataError(CoverageException):
"""An error in using a data file."""
pass
class NoDataError(CoverageException):
"""We didn't have data to work with."""
pass
class DataFileOrDirectoryNotFoundError(NoDataError):
"""A data file or data directory could be found."""
@classmethod
def new(
cls, data_file_or_directory_path: str, *, is_combining: bool = False
) -> DataFileOrDirectoryNotFoundError:
"""
Create a new instance.
"""
message = (
f"The data file or directory '{os.path.abspath(data_file_or_directory_path)}' could not"
+ " be found."
)
return cls(_message_append_combine_hint(message, is_combining))
class NoDataFilesFoundError(NoDataError):
"""No data files could be found in a data directory."""
@classmethod
def new(
cls, data_directory_path: str, *, is_combining: bool = False
) -> 'NoDataFilesFoundError':
"""
Create a new instance.
"""
message = (
f"The data directory '{os.path.abspath(data_directory_path)}' does not contain any data"
+ " files."
)
return cls(_message_append_combine_hint(message, is_combining))
class UnusableDataFilesError(NoDataError):
"""The given data files are unusable."""
@classmethod
def new(cls, *data_file_paths: str) -> 'UnusableDataFilesError':
"""
Create a new instance.
"""
message = (
"The following data files are unusable, perhaps because they do not contain valid"
+ " coverage information:"
)
for data_file_path in data_file_paths:
message += f"\n- '{os.path.abspath(data_file_path)}'"
return cls(message)
class NoSource(CoverageException):
"""We couldn't find the source for a module."""
pass
class NoCode(NoSource):
"""We couldn't find any code at all."""
pass
class NotPython(CoverageException):
"""A source file turned out not to be parsable Python."""
pass
class PluginError(CoverageException):
"""A plugin misbehaved."""
pass
class _ExceptionDuringRun(CoverageException):
"""An exception happened while running customer code.
Construct it with three arguments, the values from `sys.exc_info`.
"""
pass
class CoverageWarning(Warning):
"""A warning from Coverage.py."""
pass