diff options
-rw-r--r-- | coverage/config.py | 3 | ||||
-rw-r--r-- | coverage/control.py | 5 | ||||
-rw-r--r-- | coverage/data.py | 7 | ||||
-rw-r--r-- | test/test_api.py | 20 | ||||
-rw-r--r-- | test/test_config.py | 18 | ||||
-rw-r--r-- | test/test_farm.py | 2 |
6 files changed, 45 insertions, 10 deletions
diff --git a/coverage/config.py b/coverage/config.py index e95b74e..125121b 100644 --- a/coverage/config.py +++ b/coverage/config.py @@ -11,6 +11,7 @@ class CoverageConfig(object): 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): # Timidity: for nose users, read an environment variable. This is a @@ -39,3 +40,5 @@ class CoverageConfig(object): # 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') diff --git a/coverage/control.py b/coverage/control.py index 121f52b..7767854 100644 --- a/coverage/control.py +++ b/coverage/control.py @@ -68,7 +68,8 @@ class coverage(object): self.config.from_file(config_file) self.config.from_environment('COVERAGE_OPTIONS') self.config.from_args( - cover_pylib=cover_pylib, timid=timid, branch=branch + data_file=data_file, cover_pylib=cover_pylib, timid=timid, + branch=branch ) self.auto_data = auto_data @@ -92,7 +93,7 @@ class coverage(object): data_suffix = None self.data = CoverageData( - basename=data_file, suffix=data_suffix, + basename=self.config.data_file, suffix=data_suffix, collector="coverage v%s" % __version__ ) diff --git a/coverage/data.py b/coverage/data.py index 452ce73..55ed7a3 100644 --- a/coverage/data.py +++ b/coverage/data.py @@ -2,7 +2,7 @@ import os -from coverage.backward import pickle, sorted # pylint: disable-msg=W0622 +from coverage.backward import pickle, sorted # pylint: disable-msg=W0622 class CoverageData(object): @@ -39,14 +39,13 @@ class CoverageData(object): `collector` is a string describing the coverage measurement software. """ - self.collector = collector + self.collector = collector or 'unknown' self.use_file = True # Construct the filename that will be used for data file storage, if we # ever do any file storage. - self.filename = (basename or - os.environ.get(self.filename_env, self.filename_default)) + self.filename = basename or ".coverage" if suffix: self.filename += suffix self.filename = os.path.abspath(self.filename) diff --git a/test/test_api.py b/test/test_api.py index 270c723..8470a66 100644 --- a/test/test_api.py +++ b/test/test_api.py @@ -243,6 +243,26 @@ class ApiTest(CoverageTest): self.assertSameElements(os.listdir("."), ["datatest3.py", "datatest3.pyc", "cov.data.14"]) + def testDatafileFromRcFile(self): + # You can specify the data file name in the .coveragerc file + self.make_file("datatest4.py", """\ + fooey = 17 + """) + self.make_file(".coveragerc", """\ + [run] + data_file = mydata.dat + """) + + self.assertSameElements(os.listdir("."), + ["datatest4.py", ".coveragerc"]) + cov = coverage.coverage() + cov.start() + self.import_module("datatest4") + cov.stop() + cov.save() + self.assertSameElements(os.listdir("."), + ["datatest4.py", "datatest4.pyc", ".coveragerc", "mydata.dat"]) + def testEmptyReporting(self): # Used to be you'd get an exception reporting on nothing... cov = coverage.coverage() diff --git a/test/test_config.py b/test/test_config.py index 4206fa9..06d43d3 100644 --- a/test/test_config.py +++ b/test/test_config.py @@ -15,49 +15,61 @@ class ConfigTest(CoverageTest): cov = coverage.coverage() self.assertFalse(cov.config.timid) self.assertFalse(cov.config.branch) + self.assertEqual(cov.config.data_file, ".coverage") def test_arguments(self): # Arguments to the constructor are applied to the configuation. - cov = coverage.coverage(timid=True) + cov = coverage.coverage(timid=True, data_file="fooey.dat") self.assert_(cov.config.timid) self.assertFalse(cov.config.branch) + self.assertEqual(cov.config.data_file, "fooey.dat") def test_config_file(self): # A .coveragerc file will be read into the configuration. self.make_file(".coveragerc", """\ + # This is just a bogus .rc file for testing. [run] - timid = True + timid = True + data_file = .hello_kitty.data """) cov = coverage.coverage() self.assert_(cov.config.timid) self.assertFalse(cov.config.branch) + self.assertEqual(cov.config.data_file, ".hello_kitty.data") def test_named_config_file(self): # You can name the config file what you like. self.make_file("my_cov.ini", """\ [run] timid = True + ; I wouldn't really use this as a data file... + data_file = delete.me """) cov = coverage.coverage(config_file="my_cov.ini") self.assert_(cov.config.timid) self.assertFalse(cov.config.branch) + self.assertEqual(cov.config.data_file, "delete.me") def test_ignored_config_file(self): # You can disable reading the .coveragerc file. self.make_file(".coveragerc", """\ [run] timid = True + data_file = delete.me """) cov = coverage.coverage(config_file=False) self.assertFalse(cov.config.timid) self.assertFalse(cov.config.branch) + self.assertEqual(cov.config.data_file, ".coverage") def test_config_file_then_args(self): # The arguments override the .coveragerc file. self.make_file(".coveragerc", """\ [run] timid = True + data_file = weirdo.file """) - cov = coverage.coverage(timid=False) + cov = coverage.coverage(timid=False, data_file=".mycov") self.assertFalse(cov.config.timid) self.assertFalse(cov.config.branch) + self.assertEqual(cov.config.data_file, ".mycov") diff --git a/test/test_farm.py b/test/test_farm.py index 859ba41..a36ae12 100644 --- a/test/test_farm.py +++ b/test/test_farm.py @@ -3,7 +3,7 @@ import difflib, filecmp, fnmatch, glob, os, re, shutil, sys sys.path.insert(0, os.path.split(__file__)[0]) # Force relative import for Py3k -from backtest import run_command, execfile # pylint: disable-msg=W0622 +from backtest import run_command, execfile # pylint: disable-msg=W0622 def test_farm(clean_only=False): |