diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2009-12-06 22:31:54 -0500 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2009-12-06 22:31:54 -0500 |
commit | d1296d9cf4465ae62786f84801c6f5e3fc2540f7 (patch) | |
tree | 45be09fd6be8800dea62bb2a770140056f4ae996 | |
parent | f5853dc3ee646454179dc1b49ae41c073915c482 (diff) | |
download | python-coveragepy-git-d1296d9cf4465ae62786f84801c6f5e3fc2540f7.tar.gz |
A --rcfile argument to specify the config file.
-rw-r--r-- | TODO.txt | 2 | ||||
-rw-r--r-- | coverage/cmdline.py | 33 | ||||
-rw-r--r-- | test/test_cmdline.py | 24 |
3 files changed, 36 insertions, 23 deletions
@@ -3,7 +3,7 @@ Coverage TODO * 3.3 - Config file - - A command switch to point to the rc file. + + A command switch to point to the rc file. - Write docs - Better omit handling that ignores files during measurement. - Deal with ~ in specified paths correctly. diff --git a/coverage/cmdline.py b/coverage/cmdline.py index 27c28d48..c6659a07 100644 --- a/coverage/cmdline.py +++ b/coverage/cmdline.py @@ -63,6 +63,10 @@ class Opts(object): help="Include the machine name and process id in the .coverage " "data file name." ) + rcfile = optparse.Option( + '', '--rcfile', action='store', + help="Specify configuration file. Defaults to '.coveragerc'" + ) timid = optparse.Option( '', '--timid', action='store_true', help="Use a simpler but slower trace method. Try this if you get " @@ -95,6 +99,7 @@ class CoverageOptionParser(optparse.OptionParser, object): omit=None, parallel_mode=None, pylib=None, + rcfile=True, show_missing=None, timid=None, erase_first=None, @@ -197,6 +202,10 @@ class CmdOptionParser(CoverageOptionParser): # results, and they will compare equal to objects. return (other == "<CmdOptionParser:%s>" % self.cmd) +GLOBAL_ARGS = [ + Opts.rcfile, + Opts.help, + ] CMDS = { 'annotate': CmdOptionParser("annotate", @@ -204,15 +213,14 @@ CMDS = { Opts.directory, Opts.ignore_errors, Opts.omit, - Opts.help, - ], + ] + GLOBAL_ARGS, usage = "[options] [modules]", description = "Make annotated copies of the given files, marking " "statements that are executed with > and statements that are " "missed with !." ), - 'help': CmdOptionParser("help", [Opts.help], + 'help': CmdOptionParser("help", GLOBAL_ARGS, usage = "[command]", description = "Describe how to use coverage.py" ), @@ -222,22 +230,21 @@ CMDS = { Opts.directory, Opts.ignore_errors, Opts.omit, - Opts.help, - ], + ] + GLOBAL_ARGS, usage = "[options] [modules]", description = "Create an HTML report of the coverage of the files. " "Each file gets its own page, with the source decorated to show " "executed, excluded, and missed lines." ), - 'combine': CmdOptionParser("combine", [Opts.help], + 'combine': CmdOptionParser("combine", GLOBAL_ARGS, usage = " ", description = "Combine data from multiple coverage files collected " "with 'run -p'. The combined results are written to a single " "file representing the union of the data." ), - 'debug': CmdOptionParser("debug", [Opts.help], + 'debug': CmdOptionParser("debug", GLOBAL_ARGS, usage = "<topic>", description = "Display information on the internals of coverage.py, " "for diagnosing problems. " @@ -245,7 +252,7 @@ CMDS = { "or 'sys' to show installation information." ), - 'erase': CmdOptionParser("erase", [Opts.help], + 'erase': CmdOptionParser("erase", GLOBAL_ARGS, usage = " ", description = "Erase previously collected coverage data." ), @@ -255,8 +262,7 @@ CMDS = { Opts.ignore_errors, Opts.omit, Opts.show_missing, - Opts.help, - ], + ] + GLOBAL_ARGS, usage = "[options] [modules]", description = "Report coverage statistics on modules." ), @@ -268,8 +274,7 @@ CMDS = { Opts.pylib, Opts.parallel_mode, Opts.timid, - Opts.help, - ], + ] + GLOBAL_ARGS, defaults = {'erase_first': True}, cmd = "run", usage = "[options] <pyfile> [program options]", @@ -281,8 +286,7 @@ CMDS = { Opts.ignore_errors, Opts.omit, Opts.output_xml, - Opts.help, - ], + ] + GLOBAL_ARGS, cmd = "xml", defaults = {'outfile': 'coverage.xml'}, usage = "[options] [modules]", @@ -422,6 +426,7 @@ class CoverageScript(object): cover_pylib = options.pylib, timid = options.timid, branch = options.branch, + config_file = options.rcfile, ) if 'debug' in options.actions: diff --git a/test/test_cmdline.py b/test/test_cmdline.py index 26046e7d..f06e8149 100644 --- a/test/test_cmdline.py +++ b/test/test_cmdline.py @@ -14,7 +14,7 @@ class CmdLineTest(CoverageTest): run_in_temp_dir = False INIT_LOAD = """\ - .coverage(cover_pylib=None, data_suffix=False, timid=None, branch=None) + .coverage(cover_pylib=None, data_suffix=False, timid=None, branch=None, config_file=True) .load()\n""" def model_object(self): @@ -83,7 +83,7 @@ class ClassicCmdLineTest(CmdLineTest): def testErase(self): # coverage -e self.cmd_executes("-e", """\ - .coverage(cover_pylib=None, data_suffix=False, timid=None, branch=None) + .coverage(cover_pylib=None, data_suffix=False, timid=None, branch=None, config_file=True) .erase() """) self.cmd_executes_same("-e", "--erase") @@ -93,7 +93,7 @@ class ClassicCmdLineTest(CmdLineTest): # -x calls coverage.load first. self.cmd_executes("-x foo.py", """\ - .coverage(cover_pylib=None, data_suffix=False, timid=None, branch=None) + .coverage(cover_pylib=None, data_suffix=False, timid=None, branch=None, config_file=True) .load() .start() .run_python_file('foo.py', ['foo.py']) @@ -102,7 +102,7 @@ class ClassicCmdLineTest(CmdLineTest): """) # -e -x calls coverage.erase first. self.cmd_executes("-e -x foo.py", """\ - .coverage(cover_pylib=None, data_suffix=False, timid=None, branch=None) + .coverage(cover_pylib=None, data_suffix=False, timid=None, branch=None, config_file=True) .erase() .start() .run_python_file('foo.py', ['foo.py']) @@ -111,7 +111,7 @@ class ClassicCmdLineTest(CmdLineTest): """) # --timid sets a flag, and program arguments get passed through. self.cmd_executes("-x --timid foo.py abc 123", """\ - .coverage(cover_pylib=None, data_suffix=False, timid=True, branch=None) + .coverage(cover_pylib=None, data_suffix=False, timid=True, branch=None, config_file=True) .load() .start() .run_python_file('foo.py', ['foo.py', 'abc', '123']) @@ -120,7 +120,7 @@ class ClassicCmdLineTest(CmdLineTest): """) # -L sets a flag, and flags for the program don't confuse us. self.cmd_executes("-x -p -L foo.py -a -b", """\ - .coverage(cover_pylib=True, data_suffix=True, timid=None, branch=None) + .coverage(cover_pylib=True, data_suffix=True, timid=None, branch=None, config_file=True) .load() .start() .run_python_file('foo.py', ['foo.py', '-a', '-b']) @@ -137,7 +137,7 @@ class ClassicCmdLineTest(CmdLineTest): def testCombine(self): # coverage -c self.cmd_executes("-c", """\ - .coverage(cover_pylib=None, data_suffix=False, timid=None, branch=None) + .coverage(cover_pylib=None, data_suffix=False, timid=None, branch=None, config_file=True) .load() .combine() .save() @@ -388,7 +388,15 @@ class NewCmdLineTest(CmdLineTest): self.cmd_executes_same("run --timid f.py", "-e -x --timid f.py") self.cmd_executes_same("run", "-x") self.cmd_executes("run --branch foo.py", """\ - .coverage(cover_pylib=None, data_suffix=False, timid=None, branch=True) + .coverage(cover_pylib=None, data_suffix=False, timid=None, branch=True, config_file=True) + .erase() + .start() + .run_python_file('foo.py', ['foo.py']) + .stop() + .save() + """) + self.cmd_executes("run --rcfile=myrc.rc foo.py", """\ + .coverage(cover_pylib=None, data_suffix=False, timid=None, branch=None, config_file="myrc.rc") .erase() .start() .run_python_file('foo.py', ['foo.py']) |