12
12
import coverage
13
13
from coverage .config import HandyConfigParser
14
14
from coverage .exceptions import ConfigError , CoverageWarning
15
+ from coverage .tomlconfig import TomlConfigParser
15
16
16
17
from tests .coveragetest import CoverageTest , UsingModulesMixin
17
18
from tests .helpers import without_module
@@ -62,7 +63,7 @@ def test_named_config_file(self):
62
63
assert cov .config .data_file == "delete.me"
63
64
64
65
def test_toml_config_file (self ):
65
- # A .coveragerc file will be read into the configuration.
66
+ # A pyproject.toml file will be read into the configuration.
66
67
self .make_file ("pyproject.toml" , """\
67
68
# This is just a bogus toml file for testing.
68
69
[tool.somethingelse]
@@ -80,7 +81,7 @@ def test_toml_config_file(self):
80
81
[tool.coverage.plugins.a_plugin]
81
82
hello = "world"
82
83
""" )
83
- cov = coverage .Coverage (config_file = "pyproject.toml" )
84
+ cov = coverage .Coverage ()
84
85
assert cov .config .timid
85
86
assert not cov .config .branch
86
87
assert cov .config .concurrency == ["a" , "b" ]
@@ -91,13 +92,14 @@ def test_toml_config_file(self):
91
92
assert cov .config .fail_under == 90.5
92
93
assert cov .config .get_plugin_options ("plugins.a_plugin" ) == {"hello" : "world" }
93
94
95
+ def test_toml_ints_can_be_floats (self ):
94
96
# Test that our class doesn't reject integers when loading floats
95
97
self .make_file ("pyproject.toml" , """\
96
98
# This is just a bogus toml file for testing.
97
99
[tool.coverage.report]
98
100
fail_under = 90
99
101
""" )
100
- cov = coverage .Coverage (config_file = "pyproject.toml" )
102
+ cov = coverage .Coverage ()
101
103
assert cov .config .fail_under == 90
102
104
assert isinstance (cov .config .fail_under , float )
103
105
@@ -435,7 +437,8 @@ def test_exceptions_from_missing_things(self):
435
437
[run]
436
438
branch = True
437
439
""" )
438
- config = HandyConfigParser ("config.ini" )
440
+ config = HandyConfigParser (True )
441
+ config .read (["config.ini" ])
439
442
with pytest .raises (ConfigError , match = "No section: 'xyzzy'" ):
440
443
config .options ("xyzzy" )
441
444
with pytest .raises (ConfigError , match = "No option 'foo' in section: 'xyzzy'" ):
@@ -756,3 +759,17 @@ def test_no_toml_installed_pyproject_no_coverage(self):
756
759
assert not cov .config .timid
757
760
assert not cov .config .branch
758
761
assert cov .config .data_file == ".coverage"
762
+
763
+ def test_exceptions_from_missing_toml_things (self ):
764
+ self .make_file ("pyproject.toml" , """\
765
+ [tool.coverage.run]
766
+ branch = true
767
+ """ )
768
+ config = TomlConfigParser (False )
769
+ config .read ("pyproject.toml" )
770
+ with pytest .raises (ConfigError , match = "No section: 'xyzzy'" ):
771
+ config .options ("xyzzy" )
772
+ with pytest .raises (ConfigError , match = "No section: 'xyzzy'" ):
773
+ config .get ("xyzzy" , "foo" )
774
+ with pytest .raises (ConfigError , match = "No option 'foo' in section: 'tool.coverage.run'" ):
775
+ config .get ("run" , "foo" )
0 commit comments