diff options
-rw-r--r-- | CHANGES.txt | 3 | ||||
-rw-r--r-- | coverage/config.py | 15 | ||||
-rw-r--r-- | coverage/control.py | 6 | ||||
-rw-r--r-- | tests/test_config.py | 13 | ||||
-rw-r--r-- | tests/test_plugins.py | 12 |
5 files changed, 41 insertions, 8 deletions
diff --git a/CHANGES.txt b/CHANGES.txt index 2b1f0dda..a69d761d 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -12,6 +12,9 @@ Latest - The ``COVERAGE_OPTIONS`` environment variable is no longer supported. It was a hack for ``--timid`` before configuration files were available. +- You can now programmatically adjust the configuration of coverage by setting + items on `Coverage.config` after construcion. + - Made some PyPy-specific tweaks to improve speed under PyPy. Thanks, Alex Gaynor. diff --git a/coverage/config.py b/coverage/config.py index ece68ba8..f262a043 100644 --- a/coverage/config.py +++ b/coverage/config.py @@ -266,3 +266,18 @@ class CoverageConfig(object): def get_plugin_options(self, plugin): """Get a dictionary of options for the plugin named `plugin`.""" return self.plugin_options.get(plugin, {}) + + # TODO: docs for this. + def __setitem__(self, names, value): + for option_spec in self.CONFIG_FILE_OPTIONS: + attr, where = option_spec[:2] + if where == names: + setattr(self, attr, value) + return + + # TODO: docs for this. + def __getitem__(self, names): + for option_spec in self.CONFIG_FILE_OPTIONS: + attr, where = option_spec[:2] + if where == names: + return getattr(self, attr) diff --git a/coverage/control.py b/coverage/control.py index af9cbcc7..7b033793 100644 --- a/coverage/control.py +++ b/coverage/control.py @@ -45,7 +45,7 @@ class Coverage(object): def __init__(self, data_file=None, data_suffix=None, cover_pylib=None, auto_data=False, timid=None, branch=None, config_file=True, source=None, omit=None, include=None, debug=None, - concurrency=None, plugins=None): + concurrency=None): """ `data_file` is the base name of the data file to use, defaulting to ".coverage". `data_suffix` is appended (with a dot) to `data_file` to @@ -88,8 +88,6 @@ class Coverage(object): results. Valid strings are "greenlet", "eventlet", "gevent", or "thread" (the default). - `plugins` TODO. - """ # Build our configuration from a number of sources: # 1: defaults: @@ -121,7 +119,7 @@ class Coverage(object): data_file=data_file, cover_pylib=cover_pylib, timid=timid, branch=branch, parallel=bool_or_none(data_suffix), source=source, omit=omit, include=include, debug=debug, - concurrency=concurrency, plugins=plugins, + concurrency=concurrency, ) self._debug_file = None diff --git a/tests/test_config.py b/tests/test_config.py index 4c8735d2..109a2fbc 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -123,6 +123,19 @@ class ConfigTest(CoverageTest): ["the_$one", "anotherZZZ", "xZZZy", "xy", "huh${X}what"] ) + def test_tweaks_after_constructor(self): + # Arguments to the constructor are applied to the configuation. + cov = coverage.coverage(timid=True, data_file="fooey.dat") + cov.config["run:timid"] = False + + self.assertFalse(cov.config.timid) + self.assertFalse(cov.config.branch) + self.assertEqual(cov.config.data_file, "fooey.dat") + + self.assertFalse(cov.config["run:timid"]) + self.assertFalse(cov.config["run:branch"]) + self.assertEqual(cov.config["run:data_file"], "fooey.dat") + class ConfigFileTest(CoverageTest): """Tests of the config file settings in particular.""" diff --git a/tests/test_plugins.py b/tests/test_plugins.py index 1bd2067d..1540c500 100644 --- a/tests/test_plugins.py +++ b/tests/test_plugins.py @@ -101,7 +101,8 @@ class PluginTest(CoverageTest): """) self.assert_doesnt_exist("evidence.out") - cov = coverage.Coverage(plugins=["my_plugin"]) + cov = coverage.Coverage() + cov.config["run:plugins"] = ["my_plugin"] cov.start() cov.stop() @@ -111,7 +112,8 @@ class PluginTest(CoverageTest): def test_missing_plugin_raises_import_error(self): # Prove that a missing plugin will raise an ImportError. with self.assertRaises(ImportError): - cov = coverage.Coverage(plugins=["does_not_exist_woijwoicweo"]) + cov = coverage.Coverage() + cov.config["run:plugins"] = ["does_not_exist_woijwoicweo"] cov.start() cov.stop() @@ -121,7 +123,8 @@ class PluginTest(CoverageTest): 1/0 """) with self.assertRaises(ZeroDivisionError): - cov = coverage.Coverage(plugins=["plugin_over_zero"]) + cov = coverage.Coverage() + cov.config["run:plugins"] = ["plugin_over_zero"] cov.start() cov.stop() @@ -139,7 +142,8 @@ class PluginTest(CoverageTest): d = 4 """) - cov = coverage.Coverage(plugins=["tests.test_plugins"]) + cov = coverage.Coverage() + cov.config["run:plugins"] = ["tests.test_plugins"] # Import the python file, executing it. self.start_import_stop(cov, "simple") |