summaryrefslogtreecommitdiff
path: root/coverage
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2015-08-02 12:51:14 -0400
committerNed Batchelder <ned@nedbatchelder.com>2015-08-02 12:51:14 -0400
commit532ca16b158b8e8ffb8857237a801ec7e641bf46 (patch)
tree0cfbeedffe34378a1f5149a0bf05362dc8b3739b /coverage
parent959447537d8d8f4d91f5bf25b810e49bdaffddf6 (diff)
downloadpython-coveragepy-git-532ca16b158b8e8ffb8857237a801ec7e641bf46.tar.gz
Change the coverage.config item-access syntax to a real method call.
The square brackets were too cute, and I couldn't figure out how to document them anyway!
Diffstat (limited to 'coverage')
-rw-r--r--coverage/cmdline.py11
-rw-r--r--coverage/config.py26
-rw-r--r--coverage/control.py35
3 files changed, 63 insertions, 9 deletions
diff --git a/coverage/cmdline.py b/coverage/cmdline.py
index f1482009..0a84aa1d 100644
--- a/coverage/cmdline.py
+++ b/coverage/cmdline.py
@@ -469,9 +469,9 @@ class CoverageScript(object):
# Apply the command line fail-under options, and then use the config
# value, so we can get fail_under from the config file.
if options.fail_under is not None:
- self.coverage.config["report:fail_under"] = options.fail_under
+ self.coverage.set_option("report:fail_under", options.fail_under)
- if self.coverage.config["report:fail_under"]:
+ if self.coverage.get_option("report:fail_under"):
# Total needs to be rounded, but be careful of 0 and 100.
if 0 < total < 1:
@@ -481,7 +481,7 @@ class CoverageScript(object):
else:
total = round(total)
- if total >= self.coverage.config["report:fail_under"]:
+ if total >= self.coverage.get_option("report:fail_under"):
return OK
else:
return FAIL_UNDER
@@ -555,7 +555,7 @@ class CoverageScript(object):
def do_run(self, options, args):
"""Implementation of 'coverage run'."""
- if not self.coverage.config["run:parallel"]:
+ if not self.coverage.get_option("run:parallel"):
if not options.append:
self.coverage.erase()
@@ -575,7 +575,8 @@ class CoverageScript(object):
self.coverage.stop()
if code_ran:
if options.append:
- self.coverage.combine(data_paths=[self.coverage.config["run:data_file"]])
+ data_paths = [self.coverage.get_option("run:data_file")]
+ self.coverage.combine(data_paths=data_paths)
self.coverage.save()
return OK
diff --git a/coverage/config.py b/coverage/config.py
index 9939d6c0..83eea519 100644
--- a/coverage/config.py
+++ b/coverage/config.py
@@ -310,8 +310,17 @@ class CoverageConfig(object):
"""Get a dictionary of options for the plugin named `plugin`."""
return self.plugin_options.get(plugin, {})
- # TODO: docs for this.
- def __setitem__(self, option_name, value):
+ def set_option(self, option_name, value):
+ """Set an option in the configuration.
+
+ `option_name` is a colon-separated string indicating the section and
+ option name. For example, the ``branch`` option in the ``[run]``
+ section of the config file would be indicated with `"run:branch"`.
+
+ `value` is the new value for the option.
+
+ """
+
# Check all the hard-coded options.
for option_spec in self.CONFIG_FILE_OPTIONS:
attr, where = option_spec[:2]
@@ -328,8 +337,17 @@ class CoverageConfig(object):
# If we get here, we didn't find the option.
raise CoverageException("No such option: %r" % option_name)
- # TODO: docs for this.
- def __getitem__(self, option_name):
+ def get_option(self, option_name):
+ """Get an option from the configuration.
+
+ `option_name` is a colon-separated string indicating the section and
+ 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.
+
+ """
+
# 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 ad3c1bdf..02fe66bf 100644
--- a/coverage/control.py
+++ b/coverage/control.py
@@ -596,6 +596,41 @@ class Coverage(object):
msg = "[%d] %s" % (os.getpid(), msg)
sys.stderr.write("Coverage.py warning: %s\n" % msg)
+ def get_option(self, option_name):
+ """Get an option from the configuration.
+
+ `option_name` is a colon-separated string indicating the section and
+ 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.
+
+ """
+ return self.config.get_option(option_name)
+
+ def set_option(self, option_name, value):
+ """Set an option in the configuration.
+
+ `option_name` is a colon-separated string indicating the section and
+ option name. For example, the ``branch`` option in the ``[run]``
+ section of the config file would be indicated with `"run:branch"`.
+
+ `value` is the new value for the option. This should be a Python
+ value where appropriate. For example, use True for booleans, not the
+ string ``"True"``.
+
+ As an example, calling::
+
+ cov.set_option("run:branch", True)
+
+ has the same effect as this configuration file:
+
+ [run]
+ branch = True
+
+ """
+ self.config.set_option(option_name, value)
+
def use_cache(self, usecache):
"""Obsolete method."""
self._init()