summaryrefslogtreecommitdiff
path: root/tests/test_config.py
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2022-10-28 07:45:29 -0400
committerNed Batchelder <ned@nedbatchelder.com>2022-10-28 08:16:56 -0400
commitb3a1d979f8625e4974eaa7211cdecb211ba90b50 (patch)
treeacae62fba207edf0e55249e5b0a5f8c93abcee53 /tests/test_config.py
parent44fbd3b02ad22326767dc37fe3b94aa93b36e8a3 (diff)
downloadpython-coveragepy-git-b3a1d979f8625e4974eaa7211cdecb211ba90b50.tar.gz
test: correct some config tests, and fully cover tomlconfig.py
Diffstat (limited to 'tests/test_config.py')
-rw-r--r--tests/test_config.py25
1 files changed, 21 insertions, 4 deletions
diff --git a/tests/test_config.py b/tests/test_config.py
index cb3edadb..4afdd1e3 100644
--- a/tests/test_config.py
+++ b/tests/test_config.py
@@ -12,6 +12,7 @@ import pytest
import coverage
from coverage.config import HandyConfigParser
from coverage.exceptions import ConfigError, CoverageWarning
+from coverage.tomlconfig import TomlConfigParser
from tests.coveragetest import CoverageTest, UsingModulesMixin
from tests.helpers import without_module
@@ -62,7 +63,7 @@ class ConfigTest(CoverageTest):
assert cov.config.data_file == "delete.me"
def test_toml_config_file(self):
- # A .coveragerc file will be read into the configuration.
+ # A pyproject.toml file will be read into the configuration.
self.make_file("pyproject.toml", """\
# This is just a bogus toml file for testing.
[tool.somethingelse]
@@ -80,7 +81,7 @@ class ConfigTest(CoverageTest):
[tool.coverage.plugins.a_plugin]
hello = "world"
""")
- cov = coverage.Coverage(config_file="pyproject.toml")
+ cov = coverage.Coverage()
assert cov.config.timid
assert not cov.config.branch
assert cov.config.concurrency == ["a", "b"]
@@ -91,13 +92,14 @@ class ConfigTest(CoverageTest):
assert cov.config.fail_under == 90.5
assert cov.config.get_plugin_options("plugins.a_plugin") == {"hello": "world"}
+ def test_toml_ints_can_be_floats(self):
# Test that our class doesn't reject integers when loading floats
self.make_file("pyproject.toml", """\
# This is just a bogus toml file for testing.
[tool.coverage.report]
fail_under = 90
""")
- cov = coverage.Coverage(config_file="pyproject.toml")
+ cov = coverage.Coverage()
assert cov.config.fail_under == 90
assert isinstance(cov.config.fail_under, float)
@@ -435,7 +437,8 @@ class ConfigTest(CoverageTest):
[run]
branch = True
""")
- config = HandyConfigParser("config.ini")
+ config = HandyConfigParser(True)
+ config.read(["config.ini"])
with pytest.raises(ConfigError, match="No section: 'xyzzy'"):
config.options("xyzzy")
with pytest.raises(ConfigError, match="No option 'foo' in section: 'xyzzy'"):
@@ -756,3 +759,17 @@ class ConfigFileTest(UsingModulesMixin, CoverageTest):
assert not cov.config.timid
assert not cov.config.branch
assert cov.config.data_file == ".coverage"
+
+ def test_exceptions_from_missing_toml_things(self):
+ self.make_file("pyproject.toml", """\
+ [tool.coverage.run]
+ branch = true
+ """)
+ config = TomlConfigParser(False)
+ config.read("pyproject.toml")
+ with pytest.raises(ConfigError, match="No section: 'xyzzy'"):
+ config.options("xyzzy")
+ with pytest.raises(ConfigError, match="No section: 'xyzzy'"):
+ config.get("xyzzy", "foo")
+ with pytest.raises(ConfigError, match="No option 'foo' in section: 'tool.coverage.run'"):
+ config.get("run", "foo")