diff options
-rw-r--r-- | CHANGES.rst | 6 | ||||
-rw-r--r-- | CONTRIBUTORS.txt | 1 | ||||
-rw-r--r-- | coverage/config.py | 8 | ||||
-rw-r--r-- | coverage/control.py | 9 | ||||
-rw-r--r-- | tests/test_config.py | 25 |
5 files changed, 48 insertions, 1 deletions
diff --git a/CHANGES.rst b/CHANGES.rst index c5dba71d..b88341a0 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -28,7 +28,13 @@ Unreleased decorated async functions (`issue 946`_). This is now fixed. Thanks, Kjell Braden. +- The :meth:`~coverage.Coverage.get_option` and + :meth:`~coverage.Coverage.set_option` methods can now manipulate the + ``[paths]`` configuration setting. Thanks to Bernát Gábor for the fix for + `issue 967`_. + .. _issue 946: https://github.com/nedbat/coveragepy/issues/946 +.. _issue 967: https://github.com/nedbat/coveragepy/issues/967 .. _changes_504: diff --git a/CONTRIBUTORS.txt b/CONTRIBUTORS.txt index 940c4728..a3cc9be7 100644 --- a/CONTRIBUTORS.txt +++ b/CONTRIBUTORS.txt @@ -20,6 +20,7 @@ Arcadiy Ivanov Aron Griffis Artem Dayneko Ben Finney +Bernát Gábor Bill Hart Brandon Rhodes Brett Cannon diff --git a/coverage/config.py b/coverage/config.py index 78a3e86a..7876052b 100644 --- a/coverage/config.py +++ b/coverage/config.py @@ -421,6 +421,10 @@ class CoverageConfig(object): `value` is the new value for the option. """ + # Special-cased options. + if option_name == "paths": + self.paths = value + return # Check all the hard-coded options. for option_spec in self.CONFIG_FILE_OPTIONS: @@ -448,6 +452,10 @@ class CoverageConfig(object): Returns the value of the option. """ + # Special-cased options. + if option_name == "paths": + return self.paths + # Check all the hard-coded options. for option_spec in self.CONFIG_FILE_OPTIONS: attr, where = option_spec[:2] diff --git a/coverage/control.py b/coverage/control.py index f7db26e9..2b8c3d26 100644 --- a/coverage/control.py +++ b/coverage/control.py @@ -367,7 +367,11 @@ class Coverage(object): option name. For example, the ``branch`` option in the ``[run]`` section of the config file would be indicated with `"run:branch"`. - Returns the value of the option. + Returns the value of the option. The type depends on the option + selected. + + As a special case, an `option_name` of ``"paths"`` will return an + OrderedDict with the entire ``[paths]`` section value. .. versionadded:: 4.0 @@ -394,6 +398,9 @@ class Coverage(object): [run] branch = True + As a special case, an `option_name` of ``"paths"`` will replace the + entire ``[paths]`` section. The value should be an OrderedDict. + .. versionadded:: 4.0 """ diff --git a/tests/test_config.py b/tests/test_config.py index fe9e001e..51d9b9ef 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -3,6 +3,7 @@ # For details: https://github.com/nedbat/coveragepy/blob/master/NOTICE.txt """Test the config file handling for coverage.py""" +from collections import OrderedDict import mock @@ -340,6 +341,30 @@ class ConfigTest(CoverageTest): self.assertFalse(cov.get_option("run:branch")) self.assertEqual(cov.get_option("run:data_file"), "fooey.dat") + def test_tweaks_paths_after_constructor(self): + self.make_file(".coveragerc", """\ + [paths] + first = + /first/1 + /first/2 + + second = + /second/a + /second/b + """) + old_paths = OrderedDict() + old_paths["first"] = ["/first/1", "/first/2"] + old_paths["second"] = ["/second/a", "/second/b"] + cov = coverage.Coverage() + paths = cov.get_option("paths") + self.assertEqual(paths, old_paths) + + new_paths = OrderedDict() + new_paths['magic'] = ['src', 'ok'] + cov.set_option("paths", new_paths) + + self.assertEqual(cov.get_option("paths"), new_paths) + def test_tweak_error_checking(self): # Trying to set an unknown config value raises an error. cov = coverage.Coverage() |