summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/test_api.py10
-rw-r--r--tests/test_config.py36
-rw-r--r--tests/test_coverage.py8
-rw-r--r--tests/test_data.py42
-rw-r--r--tests/test_files.py4
-rw-r--r--tests/test_plugins.py6
-rw-r--r--tests/test_results.py4
-rw-r--r--tests/test_summary.py4
8 files changed, 57 insertions, 57 deletions
diff --git a/tests/test_api.py b/tests/test_api.py
index 9d56b23e..6b065709 100644
--- a/tests/test_api.py
+++ b/tests/test_api.py
@@ -18,7 +18,7 @@ import pytest
import coverage
from coverage import env
from coverage.data import line_counts
-from coverage.exceptions import CoverageException
+from coverage.exceptions import CoverageException, DataError, NoDataError, NoSource
from coverage.files import abs_file, relative_filename
from coverage.misc import import_local_file
@@ -293,7 +293,7 @@ class ApiTest(CoverageTest):
# empty summary reports raise exception, just like the xml report
cov = coverage.Coverage()
cov.erase()
- with pytest.raises(CoverageException, match="No data to report."):
+ with pytest.raises(NoDataError, match="No data to report."):
cov.report()
def test_completely_zero_reporting(self):
@@ -322,7 +322,7 @@ class ApiTest(CoverageTest):
)
self.make_file(".coverage", cov4_data)
cov = coverage.Coverage()
- with pytest.raises(CoverageException, match="Looks like a coverage 4.x data file"):
+ with pytest.raises(DataError, match="Looks like a coverage 4.x data file"):
cov.load()
cov.erase()
@@ -445,7 +445,7 @@ class ApiTest(CoverageTest):
self.assert_exists(".coverage")
cov2 = coverage.Coverage()
- with pytest.raises(CoverageException, match=r"No data to combine"):
+ with pytest.raises(NoDataError, match=r"No data to combine"):
cov2.combine(strict=True, keep=False)
cov3 = coverage.Coverage()
@@ -1126,7 +1126,7 @@ class RelativePathTest(CoverageTest):
with change_dir("new"):
cov = coverage.Coverage()
cov.load()
- with pytest.raises(CoverageException, match=expected):
+ with pytest.raises(NoSource, match=expected):
cov.report()
def test_moving_stuff_with_relative(self):
diff --git a/tests/test_config.py b/tests/test_config.py
index 411a456f..9a64d5b1 100644
--- a/tests/test_config.py
+++ b/tests/test_config.py
@@ -10,7 +10,7 @@ import pytest
import coverage
from coverage.config import HandyConfigParser
-from coverage.exceptions import CoverageException, CoverageWarning
+from coverage.exceptions import ConfigError, CoverageWarning
from tests.coveragetest import CoverageTest, UsingModulesMixin
from tests.helpers import without_module
@@ -159,7 +159,7 @@ class ConfigTest(CoverageTest):
def test_missing_rcfile_from_environment(self):
self.set_environ("COVERAGE_RCFILE", "nowhere.ini")
msg = "Couldn't read 'nowhere.ini' as a config file"
- with pytest.raises(CoverageException, match=msg):
+ with pytest.raises(ConfigError, match=msg):
coverage.Coverage()
@pytest.mark.parametrize("bad_config, msg", [
@@ -178,9 +178,9 @@ class ConfigTest(CoverageTest):
r"multiple repeat"),
])
def test_parse_errors(self, bad_config, msg):
- # Im-parsable values raise CoverageException, with details.
+ # Im-parsable values raise ConfigError, with details.
self.make_file(".coveragerc", bad_config)
- with pytest.raises(CoverageException, match=msg):
+ with pytest.raises(ConfigError, match=msg):
coverage.Coverage()
@pytest.mark.parametrize("bad_config, msg", [
@@ -201,9 +201,9 @@ class ConfigTest(CoverageTest):
('[tool.coverage.report]\nfail_under="s"', "not a float"),
])
def test_toml_parse_errors(self, bad_config, msg):
- # Im-parsable values raise CoverageException, with details.
+ # Im-parsable values raise ConfigError, with details.
self.make_file("pyproject.toml", bad_config)
- with pytest.raises(CoverageException, match=msg):
+ with pytest.raises(ConfigError, match=msg):
coverage.Coverage()
def test_environment_vars_in_config(self):
@@ -360,13 +360,13 @@ class ConfigTest(CoverageTest):
def test_tweak_error_checking(self):
# Trying to set an unknown config value raises an error.
cov = coverage.Coverage()
- with pytest.raises(CoverageException, match="No such option: 'run:xyzzy'"):
+ with pytest.raises(ConfigError, match="No such option: 'run:xyzzy'"):
cov.set_option("run:xyzzy", 12)
- with pytest.raises(CoverageException, match="No such option: 'xyzzy:foo'"):
+ with pytest.raises(ConfigError, match="No such option: 'xyzzy:foo'"):
cov.set_option("xyzzy:foo", 12)
- with pytest.raises(CoverageException, match="No such option: 'run:xyzzy'"):
+ with pytest.raises(ConfigError, match="No such option: 'run:xyzzy'"):
_ = cov.get_option("run:xyzzy")
- with pytest.raises(CoverageException, match="No such option: 'xyzzy:foo'"):
+ with pytest.raises(ConfigError, match="No such option: 'xyzzy:foo'"):
_ = cov.get_option("xyzzy:foo")
def test_tweak_plugin_options(self):
@@ -375,12 +375,12 @@ class ConfigTest(CoverageTest):
cov.set_option("run:plugins", ["fooey.plugin", "xyzzy.coverage.plugin"])
cov.set_option("fooey.plugin:xyzzy", 17)
cov.set_option("xyzzy.coverage.plugin:plugh", ["a", "b"])
- with pytest.raises(CoverageException, match="No such option: 'no_such.plugin:foo'"):
+ with pytest.raises(ConfigError, match="No such option: 'no_such.plugin:foo'"):
cov.set_option("no_such.plugin:foo", 23)
assert cov.get_option("fooey.plugin:xyzzy") == 17
assert cov.get_option("xyzzy.coverage.plugin:plugh") == ["a", "b"]
- with pytest.raises(CoverageException, match="No such option: 'no_such.plugin:foo'"):
+ with pytest.raises(ConfigError, match="No such option: 'no_such.plugin:foo'"):
_ = cov.get_option("no_such.plugin:foo")
def test_unknown_option(self):
@@ -425,9 +425,9 @@ class ConfigTest(CoverageTest):
branch = True
""")
config = HandyConfigParser("config.ini")
- with pytest.raises(Exception, match="No section: 'xyzzy'"):
+ with pytest.raises(ConfigError, match="No section: 'xyzzy'"):
config.options("xyzzy")
- with pytest.raises(Exception, match="No option 'foo' in section: 'xyzzy'"):
+ with pytest.raises(ConfigError, match="No option 'foo' in section: 'xyzzy'"):
config.get("xyzzy", "foo")
@@ -683,7 +683,7 @@ class ConfigFileTest(UsingModulesMixin, CoverageTest):
# 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(CoverageException, match=msg):
+ with pytest.raises(ConfigError, match=msg):
coverage.Coverage(config_file=bad_file)
def test_nocoveragerc_file_when_specified(self):
@@ -707,7 +707,7 @@ class ConfigFileTest(UsingModulesMixin, CoverageTest):
# Can't read a toml file that doesn't exist.
with without_module(coverage.tomlconfig, 'tomli'):
msg = "Couldn't read 'cov.toml' as a config file"
- with pytest.raises(CoverageException, match=msg):
+ with pytest.raises(ConfigError, match=msg):
coverage.Coverage(config_file="cov.toml")
def test_no_toml_installed_explicit_toml(self):
@@ -715,7 +715,7 @@ class ConfigFileTest(UsingModulesMixin, CoverageTest):
self.make_file("cov.toml", "# A toml file!")
with without_module(coverage.tomlconfig, 'tomli'):
msg = "Can't read 'cov.toml' without TOML support"
- with pytest.raises(CoverageException, match=msg):
+ with pytest.raises(ConfigError, match=msg):
coverage.Coverage(config_file="cov.toml")
def test_no_toml_installed_pyproject_toml(self):
@@ -727,7 +727,7 @@ class ConfigFileTest(UsingModulesMixin, CoverageTest):
""")
with without_module(coverage.tomlconfig, 'tomli'):
msg = "Can't read 'pyproject.toml' without TOML support"
- with pytest.raises(CoverageException, match=msg):
+ with pytest.raises(ConfigError, match=msg):
coverage.Coverage()
def test_no_toml_installed_pyproject_no_coverage(self):
diff --git a/tests/test_coverage.py b/tests/test_coverage.py
index d69a0418..9fc7a001 100644
--- a/tests/test_coverage.py
+++ b/tests/test_coverage.py
@@ -7,7 +7,7 @@ import pytest
import coverage
from coverage import env
-from coverage.exceptions import CoverageException
+from coverage.exceptions import NoDataError
from tests.coveragetest import CoverageTest
@@ -1850,19 +1850,19 @@ class ReportingTest(CoverageTest):
def test_no_data_to_report_on_annotate(self):
# Reporting with no data produces a nice message and no output
# directory.
- with pytest.raises(CoverageException, match="No data to report."):
+ with pytest.raises(NoDataError, match="No data to report."):
self.command_line("annotate -d ann")
self.assert_doesnt_exist("ann")
def test_no_data_to_report_on_html(self):
# Reporting with no data produces a nice message and no output
# directory.
- with pytest.raises(CoverageException, match="No data to report."):
+ with pytest.raises(NoDataError, match="No data to report."):
self.command_line("html -d htmlcov")
self.assert_doesnt_exist("htmlcov")
def test_no_data_to_report_on_xml(self):
# Reporting with no data produces a nice message.
- with pytest.raises(CoverageException, match="No data to report."):
+ with pytest.raises(NoDataError, match="No data to report."):
self.command_line("xml")
self.assert_doesnt_exist("coverage.xml")
diff --git a/tests/test_data.py b/tests/test_data.py
index 2e20618b..bc06eb23 100644
--- a/tests/test_data.py
+++ b/tests/test_data.py
@@ -16,7 +16,7 @@ import pytest
from coverage.data import CoverageData, combine_parallel_data
from coverage.data import add_data_to_hash, line_counts
from coverage.debug import DebugControlString
-from coverage.exceptions import CoverageException
+from coverage.exceptions import DataError, NoDataError
from coverage.files import PathAliases, canonical_filename
from tests.coveragetest import CoverageTest
@@ -164,14 +164,14 @@ class CoverageDataTest(CoverageTest):
covdata = DebugCoverageData()
covdata.add_lines(LINES_1)
msg = "Can't add branch measurements to existing line data"
- with pytest.raises(CoverageException, match=msg):
+ with pytest.raises(DataError, match=msg):
covdata.add_arcs(ARCS_3)
def test_cant_add_lines_with_arcs(self):
covdata = DebugCoverageData()
covdata.add_arcs(ARCS_3)
msg = "Can't add line measurements to existing branch data"
- with pytest.raises(CoverageException, match=msg):
+ with pytest.raises(DataError, match=msg):
covdata.add_lines(LINES_1)
def test_touch_file_with_lines(self):
@@ -324,11 +324,11 @@ class CoverageDataTest(CoverageTest):
def test_cant_file_tracer_unmeasured_files(self):
covdata = DebugCoverageData()
msg = "Can't add file tracer data for unmeasured file 'p1.foo'"
- with pytest.raises(CoverageException, match=msg):
+ with pytest.raises(DataError, match=msg):
covdata.add_file_tracers({"p1.foo": "p1.plugin"})
covdata.add_lines({"p2.html": [10, 11, 12]})
- with pytest.raises(CoverageException, match=msg):
+ with pytest.raises(DataError, match=msg):
covdata.add_file_tracers({"p1.foo": "p1.plugin"})
def test_cant_change_file_tracer_name(self):
@@ -337,7 +337,7 @@ class CoverageDataTest(CoverageTest):
covdata.add_file_tracers({"p1.foo": "p1.plugin"})
msg = "Conflicting file tracer name for 'p1.foo': 'p1.plugin' vs 'p1.plugin.foo'"
- with pytest.raises(CoverageException, match=msg):
+ with pytest.raises(DataError, match=msg):
covdata.add_file_tracers({"p1.foo": "p1.plugin.foo"})
def test_update_lines(self):
@@ -375,10 +375,10 @@ class CoverageDataTest(CoverageTest):
covdata2 = DebugCoverageData(suffix='2')
covdata2.add_arcs(ARCS_3)
- with pytest.raises(CoverageException, match="Can't combine arc data with line data"):
+ with pytest.raises(DataError, match="Can't combine arc data with line data"):
covdata1.update(covdata2)
- with pytest.raises(CoverageException, match="Can't combine line data with arc data"):
+ with pytest.raises(DataError, match="Can't combine line data with arc data"):
covdata2.update(covdata1)
def test_update_file_tracers(self):
@@ -424,11 +424,11 @@ class CoverageDataTest(CoverageTest):
covdata2.add_file_tracers({"p1.html": "html.other_plugin"})
msg = "Conflicting file tracer name for 'p1.html': 'html.plugin' vs 'html.other_plugin'"
- with pytest.raises(CoverageException, match=msg):
+ with pytest.raises(DataError, match=msg):
covdata1.update(covdata2)
msg = "Conflicting file tracer name for 'p1.html': 'html.other_plugin' vs 'html.plugin'"
- with pytest.raises(CoverageException, match=msg):
+ with pytest.raises(DataError, match=msg):
covdata2.update(covdata1)
def test_update_file_tracer_vs_no_file_tracer(self):
@@ -440,11 +440,11 @@ class CoverageDataTest(CoverageTest):
covdata2.add_lines({"p1.html": [1, 2, 3]})
msg = "Conflicting file tracer name for 'p1.html': 'html.plugin' vs ''"
- with pytest.raises(CoverageException, match=msg):
+ with pytest.raises(DataError, match=msg):
covdata1.update(covdata2)
msg = "Conflicting file tracer name for 'p1.html': '' vs 'html.plugin'"
- with pytest.raises(CoverageException, match=msg):
+ with pytest.raises(DataError, match=msg):
covdata2.update(covdata1)
def test_update_lines_empty(self):
@@ -529,7 +529,7 @@ class CoverageDataTest(CoverageTest):
def test_cant_touch_in_empty_data(self):
covdata = DebugCoverageData()
msg = "Can't touch files in an empty CoverageData"
- with pytest.raises(CoverageException, match=msg):
+ with pytest.raises(DataError, match=msg):
covdata.touch_file("abc.py")
def test_read_and_write_are_opposites(self):
@@ -587,13 +587,13 @@ class CoverageDataInTempDirTest(CoverageTest):
msg = r"Couldn't .* '.*[/\\]{}': \S+"
self.make_file("xyzzy.dat", "xyzzy")
- with pytest.raises(CoverageException, match=msg.format("xyzzy.dat")):
+ with pytest.raises(DataError, match=msg.format("xyzzy.dat")):
covdata = DebugCoverageData("xyzzy.dat")
covdata.read()
assert not covdata
self.make_file("empty.dat", "")
- with pytest.raises(CoverageException, match=msg.format("empty.dat")):
+ with pytest.raises(DataError, match=msg.format("empty.dat")):
covdata = DebugCoverageData("empty.dat")
covdata.read()
assert not covdata
@@ -601,14 +601,14 @@ class CoverageDataInTempDirTest(CoverageTest):
def test_hard_read_error(self):
self.make_file("noperms.dat", "go away")
os.chmod("noperms.dat", 0)
- with pytest.raises(CoverageException, match=r"Couldn't .* '.*[/\\]noperms.dat': "):
+ with pytest.raises(DataError, match=r"Couldn't .* '.*[/\\]noperms.dat': "):
covdata = DebugCoverageData("noperms.dat")
covdata.read()
@pytest.mark.parametrize("klass", [CoverageData, DebugCoverageData])
def test_error_when_closing(self, klass):
msg = r"Couldn't .* '.*[/\\]flaked.dat': \S+"
- with pytest.raises(CoverageException, match=msg):
+ with pytest.raises(DataError, match=msg):
covdata = klass("flaked.dat")
covdata.add_lines(LINES_1)
# I don't know how to make a real error, so let's fake one.
@@ -621,7 +621,7 @@ class CoverageDataInTempDirTest(CoverageTest):
con.execute("create table coverage_schema (version integer)")
con.execute("insert into coverage_schema (version) values (99)")
msg = r"Couldn't .* '.*[/\\]wrong_schema.db': wrong schema: 99 instead of \d+"
- with pytest.raises(CoverageException, match=msg):
+ with pytest.raises(DataError, match=msg):
covdata = DebugCoverageData("wrong_schema.db")
covdata.read()
assert not covdata
@@ -629,7 +629,7 @@ class CoverageDataInTempDirTest(CoverageTest):
with sqlite3.connect("no_schema.db") as con:
con.execute("create table foobar (baz text)")
msg = r"Couldn't .* '.*[/\\]no_schema.db': \S+"
- with pytest.raises(CoverageException, match=msg):
+ with pytest.raises(DataError, match=msg):
covdata = DebugCoverageData("no_schema.db")
covdata.read()
assert not covdata
@@ -854,7 +854,7 @@ class CoverageDataFilesTest(CoverageTest):
def test_combining_from_nonexistent_directories(self):
covdata = DebugCoverageData()
msg = "Couldn't combine from non-existent path 'xyzzy'"
- with pytest.raises(CoverageException, match=msg):
+ with pytest.raises(NoDataError, match=msg):
combine_parallel_data(covdata, data_paths=['xyzzy'])
def test_interleaved_erasing_bug716(self):
@@ -894,5 +894,5 @@ class DumpsLoadsTest(CoverageTest):
re.escape(repr(bad_data[:40])),
len(bad_data),
)
- with pytest.raises(CoverageException, match=msg):
+ with pytest.raises(DataError, match=msg):
covdata.loads(bad_data)
diff --git a/tests/test_files.py b/tests/test_files.py
index de0dbbd5..0780fdb3 100644
--- a/tests/test_files.py
+++ b/tests/test_files.py
@@ -10,7 +10,7 @@ import pytest
from coverage import env
from coverage import files
-from coverage.exceptions import CoverageException
+from coverage.exceptions import ConfigError
from coverage.files import (
TreeMatcher, FnmatchMatcher, ModuleMatcher, PathAliases,
find_python_files, abs_file, actual_path, flat_rootname, fnmatches_to_regex,
@@ -291,7 +291,7 @@ class PathAliasesTest(CoverageTest):
def test_cant_have_wildcard_at_end(self, badpat):
aliases = PathAliases()
msg = "Pattern must not end with wildcards."
- with pytest.raises(CoverageException, match=msg):
+ with pytest.raises(ConfigError, match=msg):
aliases.add(badpat, "fooey")
def test_no_accidental_munging(self):
diff --git a/tests/test_plugins.py b/tests/test_plugins.py
index 5d3b5322..2140f00c 100644
--- a/tests/test_plugins.py
+++ b/tests/test_plugins.py
@@ -14,7 +14,7 @@ import coverage
from coverage import env
from coverage.control import Plugins
from coverage.data import line_counts
-from coverage.exceptions import CoverageException, CoverageWarning
+from coverage.exceptions import CoverageWarning, NoSource, PluginError
from coverage.misc import import_local_file
import coverage.plugin
@@ -133,7 +133,7 @@ class LoadPluginsTest(CoverageTest):
Nothing = 0
""")
msg_pat = "Plugin module 'no_plugin' didn't define a coverage_init function"
- with pytest.raises(CoverageException, match=msg_pat):
+ with pytest.raises(PluginError, match=msg_pat):
list(Plugins.load_plugins(["no_plugin"], None))
@@ -576,7 +576,7 @@ class GoodFileTracerTest(FileTracerTest):
# But completely new filenames are not in the results.
assert len(cov.get_data().measured_files()) == 3
- with pytest.raises(CoverageException):
+ with pytest.raises(NoSource):
cov.analysis("fictional.py")
diff --git a/tests/test_results.py b/tests/test_results.py
index 83968956..8b2a737b 100644
--- a/tests/test_results.py
+++ b/tests/test_results.py
@@ -5,7 +5,7 @@
import pytest
-from coverage.exceptions import CoverageException
+from coverage.exceptions import ConfigError
from coverage.results import format_lines, Numbers, should_fail_under
from tests.coveragetest import CoverageTest
@@ -114,7 +114,7 @@ def test_should_fail_under(total, fail_under, precision, result):
def test_should_fail_under_invalid_value():
- with pytest.raises(CoverageException, match=r"fail_under=101"):
+ with pytest.raises(ConfigError, match=r"fail_under=101"):
should_fail_under(100.0, 101, 0)
diff --git a/tests/test_summary.py b/tests/test_summary.py
index 6fbb034d..769c6ec7 100644
--- a/tests/test_summary.py
+++ b/tests/test_summary.py
@@ -16,7 +16,7 @@ import coverage
from coverage import env
from coverage.control import Coverage
from coverage.data import CoverageData
-from coverage.exceptions import CoverageException
+from coverage.exceptions import ConfigError
from coverage.summary import SummaryReporter
from tests.coveragetest import CoverageTest, TESTS_DIR, UsingModulesMixin
@@ -921,5 +921,5 @@ class SummaryReporterConfigurationTest(CoverageTest):
def test_sort_report_by_invalid_option(self):
# Sort the text report by a nonsense column.
msg = "Invalid sorting option: 'Xyzzy'"
- with pytest.raises(CoverageException, match=msg):
+ with pytest.raises(ConfigError, match=msg):
self.get_summary_text(('report:sort', 'Xyzzy'))