diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2009-12-05 17:34:50 -0500 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2009-12-05 17:34:50 -0500 |
commit | d62fbbcec0d4a5340eff8b0002c705df5666c1c5 (patch) | |
tree | 66e3a2d465a161ac3f9aab07019ac085340bbb54 /coverage/config.py | |
parent | 12da359e95a2f4aa3df4afb714df5ba1b6450e0f (diff) | |
parent | 0fed6109aa32baf8b968dd11337e3841f054d2ba (diff) | |
download | python-coveragepy-git-d62fbbcec0d4a5340eff8b0002c705df5666c1c5.tar.gz |
Merged config changes to default. Let the 3.3 wild rumpus start!
Diffstat (limited to 'coverage/config.py')
-rw-r--r-- | coverage/config.py | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/coverage/config.py b/coverage/config.py new file mode 100644 index 00000000..0955347b --- /dev/null +++ b/coverage/config.py @@ -0,0 +1,59 @@ +"""Config file for coverage.py""" + +import os +from coverage.backward import configparser # pylint: disable-msg=W0622 + + +class CoverageConfig(object): + """Coverage.py configuration. + + The attributes of this class are the various settings that control the + operation of coverage.py. + + """ + + def __init__(self): + """Initialize the configuration attributes to their defaults.""" + # Defaults. + self.cover_pylib = False + self.timid = False + self.branch = False + self.exclude_list = ['# *pragma[: ]*[nN][oO] *[cC][oO][vV][eE][rR]'] + self.data_file = ".coverage" + + def from_environment(self, env_var): + """Read configuration from the `env_var` environment variable.""" + # Timidity: for nose users, read an environment variable. This is a + # cheap hack, since the rest of the command line arguments aren't + # recognized, but it solves some users' problems. + env = os.environ.get(env_var, '') + if env: + self.timid = ('--timid' in env) + + def from_args(self, **kwargs): + """Read config values from `kwargs`.""" + for k, v in kwargs.items(): + if v is not None: + setattr(self, k, v) + + def from_file(self, *files): + """Read configurating from .rc files. + + Each argument in `files` is a file name to read. + + """ + cp = configparser.RawConfigParser() + cp.read(files) + + if cp.has_option('run', 'timid'): + self.timid = cp.getboolean('run', 'timid') + if cp.has_option('run', 'cover_pylib'): + self.cover_pylib = cp.getboolean('run', 'cover_pylib') + if cp.has_option('run', 'branch'): + self.branch = cp.getboolean('run', 'branch') + if cp.has_option('report', 'exclude'): + # Exclude is a list of lines, leave out the blank ones. + exclude_list = cp.get('report', 'exclude') + self.exclude_list = filter(None, exclude_list.split('\n')) + if cp.has_option('run', 'data_file'): + self.data_file = cp.get('run', 'data_file') |