From edadbece423b100ff3513cd26670b1fc2631cbf3 Mon Sep 17 00:00:00 2001 From: Bernat Gabor Date: Fri, 3 Apr 2020 08:19:23 +0100 Subject: [PATCH] Allow plugins to alter the paths config Signed-off-by: Bernat Gabor --- coverage/config.py | 6 ++++++ tests/test_config.py | 12 ++++++++++++ 2 files changed, 18 insertions(+) diff --git a/coverage/config.py b/coverage/config.py index 78a3e86a1..166f34eab 100644 --- a/coverage/config.py +++ b/coverage/config.py @@ -421,6 +421,9 @@ def set_option(self, option_name, value): `value` is the new value for the option. """ + if option_name == "paths": + self.paths = value + return # Check all the hard-coded options. for option_spec in self.CONFIG_FILE_OPTIONS: @@ -448,6 +451,9 @@ def get_option(self, option_name): Returns the value of the option. """ + 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/tests/test_config.py b/tests/test_config.py index fe9e001e7..880368f7d 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,17 @@ def test_tweaks_after_constructor(self): self.assertFalse(cov.get_option("run:branch")) self.assertEqual(cov.get_option("run:data_file"), "fooey.dat") + def test_tweaks_paths_after_constructor(self): + cov = coverage.Coverage() + paths = cov.get_option("paths") + self.assertEqual(paths, OrderedDict()) + + 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()