diff options
Diffstat (limited to 'coverage/config.py')
-rw-r--r-- | coverage/config.py | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/coverage/config.py b/coverage/config.py index f262a04..4d599ee 100644 --- a/coverage/config.py +++ b/coverage/config.py @@ -2,6 +2,8 @@ import os, re, sys from coverage.backward import string_class, iitems +from coverage.misc import CoverageException + # In py3, # ConfigParser was renamed to the more-standard configparser try: @@ -268,16 +270,35 @@ class CoverageConfig(object): return self.plugin_options.get(plugin, {}) # TODO: docs for this. - def __setitem__(self, names, value): + def __setitem__(self, option_name, value): + # Check all the hard-coded options. for option_spec in self.CONFIG_FILE_OPTIONS: attr, where = option_spec[:2] - if where == names: + if where == option_name: setattr(self, attr, value) return + # See if it's a plugin option. + plugin_name, _, key = option_name.partition(":") + if key and plugin_name in self.plugins: + self.plugin_options.setdefault(plugin_name, {})[key] = value + return + + # 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, names): + def __getitem__(self, option_name): + # Check all the hard-coded options. for option_spec in self.CONFIG_FILE_OPTIONS: attr, where = option_spec[:2] - if where == names: + if where == option_name: return getattr(self, attr) + + # See if it's a plugin option. + plugin_name, _, key = option_name.partition(":") + if key and plugin_name in self.plugins: + return self.plugin_options.get(plugin_name, {}).get(key) + + # If we get here, we didn't find the option. + raise CoverageException("No such option: %r" % option_name) |