diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2014-09-25 06:40:09 -0400 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2014-09-25 06:40:09 -0400 |
commit | bee4695b9dd3ac9aee5d2dc2746a49a37aae0742 (patch) | |
tree | 6d062b7fbd51f987fac3f9e7170dbae26da5fd95 | |
parent | 7b5457967f256696d3b6c936e81436aa60b4b409 (diff) | |
download | python-coveragepy-git-bee4695b9dd3ac9aee5d2dc2746a49a37aae0742.tar.gz |
Some error checking and more tests for concurrency control.
-rw-r--r-- | coverage/cmdline.py | 5 | ||||
-rw-r--r-- | coverage/collector.py | 4 | ||||
-rw-r--r-- | coverage/control.py | 4 | ||||
-rw-r--r-- | tests/test_cmdline.py | 18 | ||||
-rw-r--r-- | tests/test_config.py | 4 |
5 files changed, 28 insertions, 7 deletions
diff --git a/coverage/cmdline.py b/coverage/cmdline.py index 51aa5fe5..58f4817f 100644 --- a/coverage/cmdline.py +++ b/coverage/cmdline.py @@ -19,9 +19,12 @@ class Opts(object): '', '--branch', action='store_true', help="Measure branch coverage in addition to statement coverage." ) + CONCURRENCY_CHOICES = ["thread", "gevent", "greenlet", "eventlet"] concurrency = optparse.make_option( '', '--concurrency', action='store', metavar="LIB", - help="Properly measure code using a concurrency library." + choices=CONCURRENCY_CHOICES, + help="Properly measure code using a concurrency library. " + "Valid values are: %s." % ", ".join(CONCURRENCY_CHOICES) ) debug = optparse.make_option( '', '--debug', action='store', metavar="OPTS", diff --git a/coverage/collector.py b/coverage/collector.py index 07318240..9c6288cd 100644 --- a/coverage/collector.py +++ b/coverage/collector.py @@ -68,7 +68,9 @@ class Collector(object): `warn` is a warning function, taking a single string message argument, to be used if a warning needs to be issued. - TODO: `concurrency` + `concurrency` is a string indicating the concurrency library in use. + Valid values are "greenlet", "eventlet", "gevent", or "thread" (the + default). """ self.should_trace = should_trace diff --git a/coverage/control.py b/coverage/control.py index 510ced7b..cc1ad36c 100644 --- a/coverage/control.py +++ b/coverage/control.py @@ -86,8 +86,8 @@ class Coverage(object): `concurrency` is a string indicating the concurrency library being used in the measured code. Without this, coverage.py will get incorrect - results. Valid strings are "greenlet", "eventlet", or "gevent", which - are all equivalent. TODO: really? + results. Valid strings are "greenlet", "eventlet", "gevent", or + "thread" (the default). `plugins` TODO. diff --git a/tests/test_cmdline.py b/tests/test_cmdline.py index bf96f27e..a2fec397 100644 --- a/tests/test_cmdline.py +++ b/tests/test_cmdline.py @@ -8,6 +8,8 @@ from coverage.misc import ExceptionDuringRun from tests.coveragetest import CoverageTest, OK, ERR +# TODO: change bare asserts to unittest asserts. +# TODO: base these tests on new cmdline, not old. class CmdLineTest(CoverageTest): """Tests of execution paths through the command line interpreter.""" @@ -565,8 +567,7 @@ class NewCmdLineTest(CmdLineTest): .stop() .save() """) - self.cmd_executes("run --source=quux,hi.there,/home/bar foo.py", - """\ + self.cmd_executes("run --source=quux,hi.there,/home/bar foo.py", """\ .coverage(source=["quux", "hi.there", "/home/bar"]) .erase() .start() @@ -574,6 +575,19 @@ class NewCmdLineTest(CmdLineTest): .stop() .save() """) + self.cmd_executes("run --concurrency=gevent foo.py", """\ + .coverage(concurrency='gevent') + .erase() + .start() + .run_python_file('foo.py', ['foo.py']) + .stop() + .save() + """) + + def test_bad_concurrency(self): + self.command_line("run --concurrency=nothing", ret=ERR) + out = self.stdout() + self.assertIn("option --concurrency: invalid choice: 'nothing'", out) def test_run_debug(self): self.cmd_executes("run --debug=opt1 foo.py", """\ diff --git a/tests/test_config.py b/tests/test_config.py index bf84423d..4c8735d2 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -144,6 +144,7 @@ class ConfigFileTest(CoverageTest): cover_pylib = TRUE parallel = on include = a/ , b/ + concurrency = thread plugins = plugins.a_plugin plugins.another @@ -210,6 +211,7 @@ class ConfigFileTest(CoverageTest): self.assertTrue(cov.config.branch) self.assertTrue(cov.config.cover_pylib) self.assertTrue(cov.config.parallel) + self.assertEqual(cov.config.concurrency, "thread") self.assertEqual(cov.get_exclude_list(), ["if 0:", r"pragma:?\s+no cover", "another_tab"] @@ -274,7 +276,7 @@ class ConfigFileTest(CoverageTest): self.assertEqual(cov.config.omit, None) self.assertEqual(cov.config.branch, False) - def test_one(self): + def test_non_ascii(self): self.make_file(".coveragerc", """\ [html] title = tabblo & «ταБЬℓσ» # numbers |