summaryrefslogtreecommitdiff
path: root/tests/test_config.py
diff options
context:
space:
mode:
authorThomas Grainger <tagrain@gmail.com>2021-07-13 11:23:09 +0100
committerGitHub <noreply@github.com>2021-07-13 03:23:09 -0700
commit80bfea74c10dec30a0fa64e1379b80c897b060a9 (patch)
treec2ee11fb7e506c147c20f48619f3c4cb197ef11f /tests/test_config.py
parent8cb321599e1c738c1e2af8f009a40e35423bcd9f (diff)
downloadpython-coveragepy-git-80bfea74c10dec30a0fa64e1379b80c897b060a9.tar.gz
Support TOML v1.0.0 syntax in `pyproject.toml` (#1186)
* Support TOML v1.0.0 syntax in `pyproject.toml` fixes #1180 Co-authored-by: Taneli Hukkinen <3275109+hukkin@users.noreply.github.com> * fix toml meta test * use pytest.mark.parametrize to narrow test failure * Update tests/test_config.py Co-authored-by: Taneli Hukkinen <3275109+hukkin@users.noreply.github.com> Co-authored-by: Taneli Hukkinen <3275109+hukkin@users.noreply.github.com>
Diffstat (limited to 'tests/test_config.py')
-rw-r--r--tests/test_config.py53
1 files changed, 25 insertions, 28 deletions
diff --git a/tests/test_config.py b/tests/test_config.py
index a8b0ecef..2bef500e 100644
--- a/tests/test_config.py
+++ b/tests/test_config.py
@@ -186,31 +186,28 @@ class ConfigTest(CoverageTest):
with pytest.raises(CoverageException, match=msg):
coverage.Coverage()
- def test_toml_parse_errors(self):
+ @pytest.mark.parametrize("bad_config,msg", [
+ ("[tool.coverage.run]\ntimid = \"maybe?\"\n", r"maybe[?]"),
+ ("[tool.coverage.run\n", None),
+ ('[tool.coverage.report]\nexclude_lines = ["foo("]\n',
+ r"Invalid \[tool.coverage.report\].exclude_lines value u?'foo\(': "
+ r"(unbalanced parenthesis|missing \))"),
+ ('[tool.coverage.report]\npartial_branches = ["foo["]\n',
+ r"Invalid \[tool.coverage.report\].partial_branches value u?'foo\[': "
+ r"(unexpected end of regular expression|unterminated character set)"),
+ ('[tool.coverage.report]\npartial_branches_always = ["foo***"]\n',
+ r"Invalid \[tool.coverage.report\].partial_branches_always value "
+ r"u?'foo\*\*\*': "
+ r"multiple repeat"),
+ ('[tool.coverage.run]\nconcurrency="foo"', "not a list"),
+ ("[tool.coverage.report]\nprecision=1.23", "not an integer"),
+ ('[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.
- bad_configs_and_msgs = [
- ("[tool.coverage.run]\ntimid = \"maybe?\"\n", r"maybe[?]"),
- ("[tool.coverage.run\n", r"Key group"),
- ('[tool.coverage.report]\nexclude_lines = ["foo("]\n',
- r"Invalid \[tool.coverage.report\].exclude_lines value u?'foo\(': "
- r"(unbalanced parenthesis|missing \))"),
- ('[tool.coverage.report]\npartial_branches = ["foo["]\n',
- r"Invalid \[tool.coverage.report\].partial_branches value u?'foo\[': "
- r"(unexpected end of regular expression|unterminated character set)"),
- ('[tool.coverage.report]\npartial_branches_always = ["foo***"]\n',
- r"Invalid \[tool.coverage.report\].partial_branches_always value "
- r"u?'foo\*\*\*': "
- r"multiple repeat"),
- ('[tool.coverage.run]\nconcurrency="foo"', "not a list"),
- ("[tool.coverage.report]\nprecision=1.23", "not an integer"),
- ('[tool.coverage.report]\nfail_under="s"', "not a float"),
- ]
-
- for bad_config, msg in bad_configs_and_msgs:
- print("Trying %r" % bad_config)
- self.make_file("pyproject.toml", bad_config)
- with pytest.raises(CoverageException, match=msg):
- coverage.Coverage()
+ self.make_file("pyproject.toml", bad_config)
+ with pytest.raises(CoverageException, match=msg):
+ coverage.Coverage()
def test_environment_vars_in_config(self):
# Config files can have $envvars in them.
@@ -715,7 +712,7 @@ class ConfigFileTest(UsingModulesMixin, CoverageTest):
def test_no_toml_installed_no_toml(self):
# Can't read a toml file that doesn't exist.
- with without_module(coverage.tomlconfig, 'toml'):
+ with without_module(coverage.tomlconfig, 'tomli'):
msg = "Couldn't read 'cov.toml' as a config file"
with pytest.raises(CoverageException, match=msg):
coverage.Coverage(config_file="cov.toml")
@@ -723,7 +720,7 @@ class ConfigFileTest(UsingModulesMixin, CoverageTest):
def test_no_toml_installed_explicit_toml(self):
# Can't specify a toml config file if toml isn't installed.
self.make_file("cov.toml", "# A toml file!")
- with without_module(coverage.tomlconfig, 'toml'):
+ with without_module(coverage.tomlconfig, 'tomli'):
msg = "Can't read 'cov.toml' without TOML support"
with pytest.raises(CoverageException, match=msg):
coverage.Coverage(config_file="cov.toml")
@@ -735,7 +732,7 @@ class ConfigFileTest(UsingModulesMixin, CoverageTest):
[tool.coverage.run]
xyzzy = 17
""")
- with without_module(coverage.tomlconfig, 'toml'):
+ with without_module(coverage.tomlconfig, 'tomli'):
msg = "Can't read 'pyproject.toml' without TOML support"
with pytest.raises(CoverageException, match=msg):
coverage.Coverage()
@@ -747,7 +744,7 @@ class ConfigFileTest(UsingModulesMixin, CoverageTest):
[tool.something]
xyzzy = 17
""")
- with without_module(coverage.tomlconfig, 'toml'):
+ with without_module(coverage.tomlconfig, 'tomli'):
cov = coverage.Coverage()
# We get default settings:
assert not cov.config.timid