summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/backtest.py12
-rw-r--r--test/backunittest.py10
-rw-r--r--test/coverage_coverage.py10
-rw-r--r--test/coveragetest.py70
-rw-r--r--test/osinfo.py6
-rw-r--r--test/test_api.py32
-rw-r--r--test/test_arcs.py8
-rw-r--r--test/test_cmdline.py30
-rw-r--r--test/test_codeunit.py3
-rw-r--r--test/test_coverage.py158
-rw-r--r--test/test_data.py22
-rw-r--r--test/test_execfile.py6
-rw-r--r--test/test_farm.py74
-rw-r--r--test/test_oddball.py42
-rw-r--r--test/test_parser.py10
-rw-r--r--test/test_phystokens.py2
-rw-r--r--test/test_results.py4
-rw-r--r--test/test_summary.py4
-rw-r--r--test/test_templite.py14
19 files changed, 257 insertions, 260 deletions
diff --git a/test/backtest.py b/test/backtest.py
index 21a14d6d..12bdbc97 100644
--- a/test/backtest.py
+++ b/test/backtest.py
@@ -12,18 +12,18 @@ try:
except ImportError:
def run_command(cmd):
"""Run a command in a subprocess.
-
+
Returns the exit code and the combined stdout and stderr.
-
+
"""
_, stdouterr = os.popen4(cmd)
return 0, stdouterr.read()
else:
def run_command(cmd):
"""Run a command in a subprocess.
-
+
Returns the exit code and the combined stdout and stderr.
-
+
"""
if sys.hexversion > 0x03000000 and cmd.startswith("coverage "):
@@ -36,13 +36,13 @@ else:
stderr=subprocess.STDOUT
)
retcode = proc.wait()
-
+
# Get the output, and canonicalize it to strings with newlines.
output = proc.stdout.read()
if not isinstance(output, str):
output = output.decode('utf-8')
output = output.replace('\r', '')
-
+
return retcode, output
# No more execfile in Py3k
diff --git a/test/backunittest.py b/test/backunittest.py
index 2088f2f7..28978c78 100644
--- a/test/backunittest.py
+++ b/test/backunittest.py
@@ -12,10 +12,10 @@ def _need(method):
class TestCase(unittest.TestCase):
"""Just like unittest.TestCase, but with assert methods added.
-
+
Designed to be compatible with 3.1 unittest. Methods are only defined if
the builtin `unittest` doesn't have them.
-
+
"""
if _need('assertFalse'):
def assertFalse(self, exp):
@@ -69,16 +69,16 @@ class TestCase(unittest.TestCase):
if _need('assertMultiLineEqual'):
def assertMultiLineEqual(self, first, second):
"""Assert that two multi-line strings are equal.
-
+
If they aren't, show a nice diff.
-
+
"""
# Adapted from Py3.1 unittest.
self.assert_(isinstance(first, str), (
'First argument is not a string'))
self.assert_(isinstance(second, str), (
'Second argument is not a string'))
-
+
if first != second:
msg = ''.join(difflib.ndiff(first.splitlines(True),
second.splitlines(True)))
diff --git a/test/coverage_coverage.py b/test/coverage_coverage.py
index 73ff3be3..b7f903bf 100644
--- a/test/coverage_coverage.py
+++ b/test/coverage_coverage.py
@@ -8,7 +8,7 @@ HTML_DIR = "htmlcov"
def run_tests_with_coverage():
"""Run the test suite with coverage measuring itself."""
import coverage
-
+
tracer = os.environ.get('COVERAGE_TEST_TRACER', 'c')
version = "%s%s" % sys.version_info[:2]
suffix = ".%s_%s" % (version, tracer)
@@ -20,7 +20,7 @@ def run_tests_with_coverage():
cov.cover_prefix = "Please measure coverage.py!"
cov.erase()
cov.start()
-
+
# Re-import coverage to get it coverage tested! I don't understand all the
# mechanics here, but if I don't carry over the imported modules (in
# covmods), then things go haywire (os == None, eventually).
@@ -39,7 +39,7 @@ def run_tests_with_coverage():
# Run nosetests, with the arguments from our command line.
print(":: Running nosetests %s" % " ".join(sys.argv[1:]))
nose.run()
-
+
cov.stop()
print(":: Saving .coverage%s" % suffix)
cov.save()
@@ -59,7 +59,7 @@ def report_on_combined_files():
cov.exclude("def __repr__")
cov.exclude("if __name__ == .__main__.:")
cov.exclude("raise AssertionError")
-
+
cov.html_report(
directory=HTML_DIR, ignore_errors=True, omit_prefixes=["mock"]
)
@@ -69,7 +69,7 @@ try:
cmd = sys.argv[1]
except IndexError:
cmd = ''
-
+
if cmd == 'run':
# Ugly hack: nose.run reads sys.argv directly, so here I delete my command
# argument so that sys.argv is left as just nose arguments.
diff --git a/test/coveragetest.py b/test/coveragetest.py
index 073dc39f..4471392f 100644
--- a/test/coveragetest.py
+++ b/test/coveragetest.py
@@ -13,7 +13,7 @@ class Tee(object):
def __init__(self, *files):
"""Make a Tee that writes to all the files in `files.`"""
self.files = files
-
+
def write(self, data):
"""Write `data` to all the files."""
for f in self.files:
@@ -27,7 +27,7 @@ class CoverageTest(TestCase):
"""A base class for Coverage test cases."""
run_in_temp_dir = True
-
+
def setUp(self):
if self.run_in_temp_dir:
# Create a temporary directory.
@@ -37,14 +37,14 @@ class CoverageTest(TestCase):
os.makedirs(self.temp_dir)
self.old_dir = os.getcwd()
os.chdir(self.temp_dir)
-
+
# Preserve changes to PYTHONPATH.
self.old_pypath = os.environ.get('PYTHONPATH', '')
-
+
# Modules should be importable from this temp directory.
self.old_syspath = sys.path[:]
sys.path.insert(0, '')
-
+
# Keep a counter to make every call to check_coverage unique.
self.n = 0
@@ -52,17 +52,17 @@ class CoverageTest(TestCase):
self.old_stdout = sys.stdout
self.captured_stdout = StringIO()
sys.stdout = Tee(sys.stdout, self.captured_stdout)
-
+
def tearDown(self):
if self.run_in_temp_dir:
# Restore the original sys.path and PYTHONPATH
sys.path = self.old_syspath
os.environ['PYTHONPATH'] = self.old_pypath
-
+
# Get rid of the temporary directory.
os.chdir(self.old_dir)
shutil.rmtree(self.temp_root)
-
+
# Restore stdout.
sys.stdout = self.old_stdout
@@ -72,14 +72,14 @@ class CoverageTest(TestCase):
def make_file(self, filename, text):
"""Create a temp file.
-
+
`filename` is the file name, and `text` is the content.
-
+
"""
# Tests that call `make_file` should be run in a temp environment.
assert self.run_in_temp_dir
text = textwrap.dedent(text)
-
+
# Create the file.
f = open(filename, 'w')
f.write(text)
@@ -89,7 +89,7 @@ class CoverageTest(TestCase):
"""Import the module named modname, and return the module object."""
modfile = modname + '.py'
f = open(modfile, 'r')
-
+
for suff in imp.get_suffixes():
if suff[0] == '.py':
break
@@ -110,23 +110,23 @@ class CoverageTest(TestCase):
modname = 'coverage_test_' + self.noise + str(self.n)
self.n += 1
return modname
-
+
# Map chars to numbers for arcz_to_arcs
_arcz_map = {'.': -1}
_arcz_map.update(dict([(c, ord(c)-ord('0')) for c in '123456789']))
_arcz_map.update(dict(
[(c, 10+ord(c)-ord('A')) for c in 'ABCDEFGHIJKLMNOPQRSTUVWXYZ']
))
-
+
def arcz_to_arcs(self, arcz):
"""Convert a compact textual representation of arcs to a list of pairs.
-
+
The text has space-separated pairs of letters. Period is -1, 1-9 are
1-9, A-Z are 10 through 36. The resulting list is sorted regardless of
the order of the input pairs.
-
+
".1 12 2." --> [(-1,1), (1,2), (2,-1)]
-
+
"""
arcs = []
for a,b in arcz.split():
@@ -136,23 +136,23 @@ class CoverageTest(TestCase):
def check_coverage(self, text, lines=None, missing="", excludes=None,
report="", arcz=None, arcz_missing="", arcz_unpredicted=""):
"""Check the coverage measurement of `text`.
-
+
The source `text` is run and measured. `lines` are the line numbers
that are executable, `missing` are the lines not executed, `excludes`
are regexes to match against for excluding lines, and `report` is
the text of the measurement report.
-
+
For arc measurement, `arcz` is a string that can be decoded into arcs
in the code (see `arcz_to_arcs` for the encoding scheme),
`arcz_missing` are the arcs that are not executed, and
`arcs_unpredicted` are the arcs executed in the code, but not deducible
from the code.
-
+
"""
# We write the code into a file so that we can import it.
# Coverage wants to deal with things as modules with file names.
modname = self.get_module_name()
-
+
self.make_file(modname+".py", text)
arcs = arcs_missing = arcs_unpredicted = None
@@ -160,7 +160,7 @@ class CoverageTest(TestCase):
arcs = self.arcz_to_arcs(arcz)
arcs_missing = self.arcz_to_arcs(arcz_missing or "")
arcs_unpredicted = self.arcz_to_arcs(arcz_unpredicted or "")
-
+
# Start up Coverage.
cov = coverage.coverage(branch=(arcs_missing is not None))
cov.erase()
@@ -174,7 +174,7 @@ class CoverageTest(TestCase):
finally:
# Stop Coverage.
cov.stop()
-
+
# Clean up our side effects
del sys.modules[modname]
@@ -218,36 +218,36 @@ class CoverageTest(TestCase):
cov.report(mod, file=frep)
rep = " ".join(frep.getvalue().split("\n")[2].split()[1:])
self.assertEqual(report, rep)
-
+
def nice_file(self, *fparts):
"""Canonicalize the filename composed of the parts in `fparts`."""
fname = os.path.join(*fparts)
return os.path.normcase(os.path.abspath(os.path.realpath(fname)))
-
+
def command_line(self, args, ret=OK):
"""Run `args` through the command line.
-
+
Use this when you want to run the full coverage machinery, but in the
current process. Exceptions may be thrown from deep in the code.
Asserts that `ret` is returned by `CoverageScript.command_line`.
-
+
Compare with `run_command`.
-
+
Returns None.
-
+
"""
ret_actual = coverage.CoverageScript().command_line(shlex.split(args))
self.assertEqual(ret_actual, ret)
-
+
def run_command(self, cmd):
""" Run the command-line `cmd` in a subprocess, and print its output.
-
+
Use this when you need to test the process behavior of coverage.
-
+
Compare with `command_line`.
-
+
Returns the process' stdout text.
-
+
"""
# Add our test modules directory to PYTHONPATH. I'm sure there's too
# much path munging here, but...
@@ -259,7 +259,7 @@ class CoverageTest(TestCase):
pypath += os.pathsep
pypath += testmods + os.pathsep + zipfile
os.environ['PYTHONPATH'] = pypath
-
+
_, output = run_command(cmd)
print(output)
return output
diff --git a/test/osinfo.py b/test/osinfo.py
index 7a82610a..8bed2afd 100644
--- a/test/osinfo.py
+++ b/test/osinfo.py
@@ -23,7 +23,7 @@ if sys.hexversion >= 0x02050000 and sys.platform == 'win32':
('PeakPagefileUsage', ctypes.c_size_t),
('PrivateUsage', ctypes.c_size_t),
]
-
+
mem_struct = PROCESS_MEMORY_COUNTERS_EX()
ret = ctypes.windll.psapi.GetProcessMemoryInfo(
ctypes.windll.kernel32.GetCurrentProcess(),
@@ -37,9 +37,9 @@ if sys.hexversion >= 0x02050000 and sys.platform == 'win32':
elif sys.platform == 'linux2':
# Linux implementation
import os
-
+
_scale = {'kb': 1024, 'mb': 1024*1024}
-
+
def _VmB(key):
"""Read the /proc/PID/status file to find memory use."""
try:
diff --git a/test/test_api.py b/test/test_api.py
index 7308cdc6..2552d114 100644
--- a/test/test_api.py
+++ b/test/test_api.py
@@ -25,17 +25,17 @@ class ApiTest(CoverageTest):
c = 4
d = 5
""")
-
+
# Import the python file, executing it.
coverage.start()
self.import_module("mycode")
coverage.stop()
-
+
_, statements, missing, missingtext = coverage.analysis("mycode.py")
self.assertEqual(statements, [1,2,3,4,5])
self.assertEqual(missing, [4])
self.assertEqual(missingtext, "4")
-
+
def doReportWork(self, modname):
"""Create a module named `modname`, then measure it."""
coverage.erase()
@@ -49,12 +49,12 @@ class ApiTest(CoverageTest):
e = 6
f = 7
""")
-
+
# Import the python file, executing it.
coverage.start()
self.import_module(modname)
coverage.stop()
-
+
def testReport(self):
self.doReportWork("mycode2")
coverage.report(["mycode2.py"])
@@ -63,7 +63,7 @@ class ApiTest(CoverageTest):
---------------------------------------
mycode2 7 4 57% 4-6
"""))
-
+
def testReportFile(self):
# The file= argument of coverage.report makes the report go there.
self.doReportWork("mycode3")
@@ -93,16 +93,16 @@ class ApiTest(CoverageTest):
c = 4
d = 5
""")
-
+
self.make_file("not_run.py", """\
fooey = 17
""")
-
+
# Import the python file, executing it.
cov.start()
self.import_module("mycode")
cov.stop()
-
+
_, statements, missing, _ = cov.analysis("not_run.py")
self.assertEqual(statements, [1])
self.assertEqual(missing, [1])
@@ -113,22 +113,22 @@ class ApiTest(CoverageTest):
import mymod
a = 1
""")
-
+
self.make_file("mymod.py", """\
fooey = 17
""")
-
+
# Import the python file, executing it.
cov = coverage.coverage()
cov.start()
self.import_module("mymain")
cov.stop()
-
+
filename, _, _, _ = cov.analysis("mymain.py")
self.assertEqual(os.path.basename(filename), "mymain.py")
filename, _, _, _ = cov.analysis("mymod.py")
self.assertEqual(os.path.basename(filename), "mymod.py")
-
+
filename, _, _, _ = cov.analysis(sys.modules["mymain"])
self.assertEqual(os.path.basename(filename), "mymain.py")
filename, _, _, _ = cov.analysis(sys.modules["mymod"])
@@ -140,12 +140,12 @@ class ApiTest(CoverageTest):
cov.start()
self.import_module("mymain")
cov.stop()
-
+
filename, _, _, _ = cov.analysis("mymain.py")
self.assertEqual(os.path.basename(filename), "mymain.py")
filename, _, _, _ = cov.analysis("mymod.py")
self.assertEqual(os.path.basename(filename), "mymod.py")
-
+
filename, _, _, _ = cov.analysis(sys.modules["mymain"])
self.assertEqual(os.path.basename(filename), "mymain.py")
filename, _, _, _ = cov.analysis(sys.modules["mymod"])
@@ -157,7 +157,7 @@ class ApiTest(CoverageTest):
a = 1
hls = colorsys.rgb_to_hls(1.0, 0.5, 0.0)
""")
-
+
self.make_file("mymod.py", """\
fooey = 17
""")
diff --git a/test/test_arcs.py b/test/test_arcs.py
index 47a69987..45ab27e8 100644
--- a/test/test_arcs.py
+++ b/test/test_arcs.py
@@ -25,7 +25,7 @@ class SimpleArcTest(CoverageTest):
a = 2
b = 3
-
+
c = 5
""",
arcz=".2 23 35 5.")
@@ -34,7 +34,7 @@ class SimpleArcTest(CoverageTest):
self.check_coverage("""\
def foo():
a = 2
-
+
foo()
""",
arcz=".1 .2 14 2. 4.")
@@ -54,7 +54,7 @@ class SimpleArcTest(CoverageTest):
assert a == 1
""",
arcz=".1 12 23 24 34 4.", arcz_missing="23 34")
-
+
def test_if_else(self):
self.check_coverage("""\
if len([]) == 0:
@@ -139,7 +139,7 @@ class SimpleArcTest(CoverageTest):
class LoopArcTest(CoverageTest):
"""Arc-measuring tests involving loops."""
-
+
def test_loop(self):
self.check_coverage("""\
for i in range(10):
diff --git a/test/test_cmdline.py b/test/test_cmdline.py
index f1e48e63..258a08ac 100644
--- a/test/test_cmdline.py
+++ b/test/test_cmdline.py
@@ -10,7 +10,7 @@ from coveragetest import CoverageTest, OK, ERR
class CmdLineTest(CoverageTest):
"""Tests of execution paths through the command line interpreter."""
-
+
run_in_temp_dir = False
INIT_LOAD = """\
@@ -25,16 +25,16 @@ class CmdLineTest(CoverageTest):
def mock_command_line(self, args):
"""Run `args` through the command line, with a Mock.
-
+
Returns the Mock it used and the status code returned.
-
+
"""
m = self.model_object()
ret = coverage.CoverageScript(
_covpkg=m, _run_python_file=m.run_python_file, _help_fn=m.help_fn
).command_line(shlex.split(args))
return m, ret
-
+
def cmd_executes(self, args, code, ret=OK):
"""Assert that the `args` end up executing the sequence in `code`."""
m1, r1 = self.mock_command_line(args)
@@ -48,7 +48,7 @@ class CmdLineTest(CoverageTest):
code_obj = compile(code, "<code>", "exec")
eval(code_obj, globals(), { 'm2': m2 })
self.assertEqual(m1.method_calls, m2.method_calls)
-
+
def cmd_executes_same(self, args1, args2):
"""Assert that the `args1` executes the same as `args2`."""
m1, r1 = self.mock_command_line(args1)
@@ -58,10 +58,10 @@ class CmdLineTest(CoverageTest):
def cmd_help(self, args, help_msg=None, topic=None, ret=ERR):
"""Run a command line, and check that it prints the right help.
-
+
Only the last function call in the mock is checked, which should be the
help message that we want to see.
-
+
"""
m, r = self.mock_command_line(args)
self.assertEqual(r, ret,
@@ -75,7 +75,7 @@ class CmdLineTest(CoverageTest):
self.assertEqual(m.method_calls[-1],
('help_fn', (), {'topic':topic})
)
-
+
class ClassicCmdLineTest(CmdLineTest):
"""Tests of the classic coverage.py command line."""
@@ -90,7 +90,7 @@ class ClassicCmdLineTest(CmdLineTest):
def testExecute(self):
# coverage -x [-p] [-L] [--timid] MODULE.py [ARG1 ARG2 ...]
-
+
# -x calls coverage.load first.
self.cmd_executes("-x foo.py", """\
.coverage(cover_pylib=None, data_suffix=False, timid=None, branch=None)
@@ -275,7 +275,7 @@ class ClassicCmdLineTest(CmdLineTest):
self.cmd_help("--version", topic="version", ret=OK)
## Error cases
-
+
def testArglessActions(self):
self.cmd_help("-e foo bar", "Unexpected arguments: foo bar")
self.cmd_help("-c baz quux", "Unexpected arguments: baz quux")
@@ -349,7 +349,7 @@ class NewCmdLineTest(CmdLineTest):
out = self.stdout()
assert "version:" in out
assert "data_path:" in out
-
+
def testErase(self):
self.cmd_executes_same("erase", "-e")
@@ -387,7 +387,7 @@ class NewCmdLineTest(CmdLineTest):
self.cmd_executes_same("run -L f.py", "-e -x -L f.py")
self.cmd_executes_same("run --timid f.py", "-e -x --timid f.py")
self.cmd_executes_same("run", "-x")
-
+
def testXml(self):
# coverage xml [-i] [--omit DIR,...] [FILE1 FILE2 ...]
self.cmd_executes("xml", self.INIT_LOAD + """\
@@ -432,19 +432,19 @@ class NewCmdLineTest(CmdLineTest):
class CmdLineStdoutTest(CmdLineTest):
"""Test the command line with real stdout output."""
-
+
def testMinimumHelp(self):
self.command_line("")
out = self.stdout()
assert "Code coverage for Python." in out
assert out.count("\n") < 4
-
+
def testHelp(self):
self.command_line("help")
out = self.stdout()
assert "nedbatchelder.com" in out
assert out.count("\n") > 10
-
+
def testCmdHelp(self):
self.command_line("help run")
out = self.stdout()
diff --git a/test/test_codeunit.py b/test/test_codeunit.py
index 96df9633..ad073827 100644
--- a/test/test_codeunit.py
+++ b/test/test_codeunit.py
@@ -21,7 +21,7 @@ class CodeUnitTest(CoverageTest):
# Parent class saves and restores sys.path, we can just modify it.
testmods = self.nice_file(os.path.dirname(__file__), 'modules')
sys.path.append(testmods)
-
+
def test_filenames(self):
acu = code_unit_factory("aa/afile.py", FileLocator())
bcu = code_unit_factory("aa/bb/bfile.py", FileLocator())
@@ -81,4 +81,3 @@ class CodeUnitTest(CoverageTest):
self.assertEqual(cu[1].source_file().read().split("\n")[0],
"# My egg file!"
)
- \ No newline at end of file
diff --git a/test/test_coverage.py b/test/test_coverage.py
index 23990ccd..c1a72480 100644
--- a/test/test_coverage.py
+++ b/test/test_coverage.py
@@ -15,18 +15,18 @@ from coveragetest import CoverageTest
class BasicCoverageTest(CoverageTest):
"""The simplest tests, for quick smoke testing of fundamental changes."""
-
+
def testSimple(self):
self.check_coverage("""\
a = 1
b = 2
-
+
c = 4
# Nothing here
d = 6
""",
[1,2,4,6], report="4 4 100%")
-
+
def testIndentationWackiness(self):
# Partial final lines are OK.
self.check_coverage("""\
@@ -57,11 +57,11 @@ class BasicCoverageTest(CoverageTest):
assert l == [12, 14, 16, 18]
""",
[1,5], "")
-
+
class SimpleStatementTest(CoverageTest):
"""Testing simple single-line statements."""
-
+
def testExpression(self):
self.check_coverage("""\
1 + 2
@@ -73,7 +73,7 @@ class SimpleStatementTest(CoverageTest):
def testAssert(self):
self.check_coverage("""\
assert (1 + 2)
- assert (1 +
+ assert (1 +
2)
assert (1 + 2), 'the universe is broken'
assert (1 +
@@ -100,7 +100,7 @@ class SimpleStatementTest(CoverageTest):
assert a == 7 and b == 8 and c == 9
""",
[1,2,3], "")
-
+
def testAttributeAssignment(self):
# Attribute assignment
self.check_coverage("""\
@@ -113,7 +113,7 @@ class SimpleStatementTest(CoverageTest):
1
""",
[1,2,3,4,6], "")
-
+
def testListofAttributeAssignment(self):
self.check_coverage("""\
class obj: pass
@@ -127,7 +127,7 @@ class SimpleStatementTest(CoverageTest):
2
""",
[1,2,3,4,7], "")
-
+
def testAugmentedAssignment(self):
self.check_coverage("""\
a = 1
@@ -153,7 +153,7 @@ class SimpleStatementTest(CoverageTest):
'''
c = len('''
long expression
- ''' +
+ ''' +
'''
on many
lines.
@@ -197,7 +197,7 @@ class SimpleStatementTest(CoverageTest):
Foo().foo()
""",
([1,2,4,5], [1,2,5]), "")
-
+
def testDel(self):
self.check_coverage("""\
d = { 'a': 1, 'b': 1, 'c': 1, 'd': 1, 'e': 1 }
@@ -225,7 +225,7 @@ class SimpleStatementTest(CoverageTest):
print "goodbye",
""",
[1,2,4,5,6,8], "")
-
+
def testRaise(self):
self.check_coverage("""\
try:
@@ -253,7 +253,7 @@ class SimpleStatementTest(CoverageTest):
return (
a +
1)
-
+
x = fn()
assert(x == 2)
""",
@@ -264,7 +264,7 @@ class SimpleStatementTest(CoverageTest):
return (a,
a + 1,
a + 2)
-
+
x,y,z = fn()
assert x == 1 and y == 2 and z == 3
""",
@@ -284,7 +284,7 @@ class SimpleStatementTest(CoverageTest):
assert a == 1 and b == 9 and c == (1,2)
""",
[1,2,3,4,7,9,10], "")
-
+
def testBreak(self):
self.check_coverage("""\
for x in range(10):
@@ -294,7 +294,7 @@ class SimpleStatementTest(CoverageTest):
assert a == 2
""",
[1,2,3,4,5], "4")
-
+
def testContinue(self):
self.check_coverage("""\
for x in range(10):
@@ -304,7 +304,7 @@ class SimpleStatementTest(CoverageTest):
assert a == 11
""",
[1,2,3,4,5], "4")
-
+
if 0:
# Peephole optimization of jumps to jumps can mean that some statements
# never hit the line tracer. The behavior is different in different
@@ -321,7 +321,7 @@ class SimpleStatementTest(CoverageTest):
b += 1
c += 1
assert a == 50 and b == 50 and c == 50
-
+
a = b = c = 0
for n in range(100):
if n % 2:
@@ -334,7 +334,7 @@ class SimpleStatementTest(CoverageTest):
assert a == 33 and b == 50 and c == 50
""",
[1,2,3,4,5,6,8,9,10, 12,13,14,15,16,17,19,20,21], "")
-
+
def testImport(self):
self.check_coverage("""\
import string
@@ -381,7 +381,7 @@ class SimpleStatementTest(CoverageTest):
assert len(path) > 0
""",
[1,3], "")
-
+
def testGlobal(self):
self.check_coverage("""\
g = h = i = 1
@@ -488,24 +488,24 @@ class SimpleStatementTest(CoverageTest):
class CompoundStatementTest(CoverageTest):
"""Testing coverage of multi-line compound statements."""
-
+
def testStatementList(self):
self.check_coverage("""\
a = 1;
b = 2; c = 3
d = 4; e = 5;
-
+
assert (a,b,c,d,e) == (1,2,3,4,5)
""",
[1,2,3,5], "")
-
+
def testIf(self):
self.check_coverage("""\
a = 1
if a == 1:
x = 3
assert x == 3
- if (a ==
+ if (a ==
1):
x = 7
assert x == 7
@@ -541,7 +541,7 @@ class CompoundStatementTest(CoverageTest):
assert x == 4
""",
[1,2,3,4,6,8,9], "6-8")
-
+
def testElif(self):
self.check_coverage("""\
a = 1; b = 2; c = 3;
@@ -655,7 +655,7 @@ class CompoundStatementTest(CoverageTest):
assert z == 7
""",
[1,2,4,5,7,9,10], "4, 7")
-
+
def testPathologicalSplitIf(self):
self.check_coverage("""\
a = 1; b = 2; c = 3;
@@ -702,7 +702,7 @@ class CompoundStatementTest(CoverageTest):
assert z == 7
""",
[1,2,5,6,9,11,12], "5, 9")
-
+
def testAbsurdSplitIf(self):
self.check_coverage("""\
a = 1; b = 2; c = 3;
@@ -788,7 +788,7 @@ class CompoundStatementTest(CoverageTest):
assert a == 2 and b == 1
""",
[1,2,3,4,5,6,8,9], "6-8")
-
+
def testSplitWhile(self):
self.check_coverage("""\
a = 3; b = 0
@@ -836,7 +836,7 @@ class CompoundStatementTest(CoverageTest):
assert a == 1
""",
[1,2,3,4,5,6], "5")
-
+
def testForElse(self):
self.check_coverage("""\
a = 0
@@ -858,7 +858,7 @@ class CompoundStatementTest(CoverageTest):
assert a == 1
""",
[1,2,3,4,5,7,8], "5-7")
-
+
def testSplitFor(self):
self.check_coverage("""\
a = 0
@@ -878,7 +878,7 @@ class CompoundStatementTest(CoverageTest):
assert a == 15
""",
[1,2,6,7], "")
-
+
def testTryExcept(self):
self.check_coverage("""\
a = 0
@@ -948,7 +948,7 @@ class CompoundStatementTest(CoverageTest):
assert a == 99
""",
[1,2,3,4,5,6,8,9], "8")
-
+
def testTryFinally(self):
self.check_coverage("""\
a = 0
@@ -980,7 +980,7 @@ class CompoundStatementTest(CoverageTest):
''' docstring
'''
return 1
-
+
a = foo()
assert a == 1
""",
@@ -993,7 +993,7 @@ class CompoundStatementTest(CoverageTest):
''' docstring
'''
return a+b
-
+
x = foo(17, 23)
assert x == 40
""",
@@ -1009,7 +1009,7 @@ class CompoundStatementTest(CoverageTest):
''' docstring
'''
return a+b
-
+
x = foo()
assert x == 22
""",
@@ -1025,19 +1025,19 @@ class CompoundStatementTest(CoverageTest):
def __init__(self):
''' Another docstring. '''
self.a = 1
-
+
def foo(self):
return self.a
-
+
x = theClass().foo()
assert x == 1
""",
- [2,6,8,10,11,13,14], "")
+ [2,6,8,10,11,13,14], "")
class ExcludeTest(CoverageTest):
"""Tests of the exclusion feature to mark lines as not covered."""
-
+
def testSimple(self):
self.check_coverage("""\
a = 1; b = 2
@@ -1058,7 +1058,7 @@ class ExcludeTest(CoverageTest):
assert a == 1 and b == 2
""",
[1,3,5,7], "5", ['-cc', '-xx'])
-
+
def testExcludingIfSuite(self):
self.check_coverage("""\
a = 1; b = 2
@@ -1085,7 +1085,7 @@ class ExcludeTest(CoverageTest):
assert a == 8 and b == 9
""",
[1,8,9,10], "", ['if 0:'])
-
+
def testExcludingElseSuite(self):
self.check_coverage("""\
a = 1; b = 2
@@ -1107,14 +1107,14 @@ class ExcludeTest(CoverageTest):
a = 4
b = 5
c = 6
-
+
# Lots of comments to confuse the else handler.
# more.
-
+
else: #pragma: NO COVER
# Comments here too.
-
+
a = 8
b = 9
assert a == 4 and b == 5 and c == 6
@@ -1132,7 +1132,7 @@ class ExcludeTest(CoverageTest):
elif 1==0: #pragma: NO COVER
a = 8
b = 9
- else:
+ else:
a = 11
b = 12
assert a == 4 and b == 5 and c == 6
@@ -1145,7 +1145,7 @@ class ExcludeTest(CoverageTest):
a = 2
if 0: x = 3 # no cover
b = 4
-
+
foo()
""",
[1,2,4,6], "", ["no cover"])
@@ -1156,11 +1156,11 @@ class ExcludeTest(CoverageTest):
l = list(range(10))
a = l[:3] # no cover
b = 4
-
+
foo()
""",
[1,2,4,6], "", ["no cover"])
-
+
def testExcludingForSuite(self):
self.check_coverage("""\
a = 0
@@ -1188,7 +1188,7 @@ class ExcludeTest(CoverageTest):
assert a == 1
""",
[1,7], "", ['#pragma: NO COVER'])
-
+
def testExcludingForElse(self):
self.check_coverage("""\
a = 0
@@ -1201,7 +1201,7 @@ class ExcludeTest(CoverageTest):
assert a == 1
""",
[1,2,3,4,5,8], "5", ['#pragma: NO COVER'])
-
+
def testExcludingWhile(self):
self.check_coverage("""\
a = 3; b = 0
@@ -1292,7 +1292,7 @@ class ExcludeTest(CoverageTest):
assert a == 99
""",
[1,2,3,4,5,6,9], "", ['#pragma: NO COVER'])
-
+
def testExcludingTryExceptPass(self):
self.check_coverage("""\
a = 0
@@ -1338,7 +1338,7 @@ class ExcludeTest(CoverageTest):
assert a == 99
""",
[1,2,3,4,5,6,9], "", ['#pragma: NO COVER'])
-
+
def testExcludingIfPass(self):
# From a comment on the coverage page by Michael McNeil Forbes:
self.check_coverage("""\
@@ -1347,18 +1347,18 @@ class ExcludeTest(CoverageTest):
pass # This line still reported as missing
if False: # pragma: no cover
x = 1 # Now it is skipped.
-
+
f()
""",
[1,7], "", ["no cover"])
-
+
def testExcludingFunction(self):
self.check_coverage("""\
def fn(foo): #pragma: NO COVER
a = 1
b = 2
c = 3
-
+
x = 1
assert x == 1
""",
@@ -1369,24 +1369,24 @@ class ExcludeTest(CoverageTest):
class Fooey:
def __init__(self):
self.a = 1
-
+
def foo(self): #pragma: NO COVER
return self.a
-
+
x = Fooey()
assert x.a == 1
""",
[1,2,3,8,9], "", ['#pragma: NO COVER'])
-
+
def testExcludingClass(self):
self.check_coverage("""\
class Fooey: #pragma: NO COVER
def __init__(self):
self.a = 1
-
+
def foo(self):
return self.a
-
+
x = 1
assert x == 1
""",
@@ -1396,20 +1396,20 @@ class ExcludeTest(CoverageTest):
if sys.hexversion >= 0x020400f0:
class Py24Test(CoverageTest):
"""Tests of new syntax in Python 2.4."""
-
+
def testFunctionDecorators(self):
self.check_coverage("""\
def require_int(func):
def wrapper(arg):
assert isinstance(arg, int)
return func(arg)
-
+
return wrapper
-
+
@require_int
def p1(arg):
return arg*2
-
+
assert p1(10) == 20
""",
[1,2,3,4,6,8,10,12], "")
@@ -1422,11 +1422,11 @@ if sys.hexversion >= 0x020400f0:
return extra*func(arg)
return wrapper
return decorator
-
+
@boost_by(10)
def boosted(arg):
return arg*2
-
+
assert boosted(10) == 200
""",
[1,2,3,4,5,6,8,10,12], "")
@@ -1445,19 +1445,19 @@ if sys.hexversion >= 0x020400f0:
return extra*func(arg)
return wrapper
return decorator
-
+
@require_int
@boost_by(10)
def boosted1(arg):
return arg*2
-
+
assert boosted1(10) == 200
@boost_by(10)
@require_int
def boosted2(arg):
return arg*2
-
+
assert boosted2(10) == 200
""",
([1,2,3,4,5,7,8,9,10,11,12,14,15,17,19,21,22,24,26],
@@ -1471,19 +1471,19 @@ if sys.hexversion >= 0x020500f0:
def testWithStatement(self):
self.check_coverage("""\
from __future__ import with_statement
-
+
class Managed:
def __enter__(self):
desc = "enter"
-
+
def __exit__(self, type, value, tb):
desc = "exit"
-
+
m = Managed()
with m:
desc = "block1a"
desc = "block1b"
-
+
try:
with m:
desc = "block2"
@@ -1492,7 +1492,7 @@ if sys.hexversion >= 0x020500f0:
desc = "caught"
""",
[1,3,4,5,7,8,10,11,12,13,15,16,17,18,19,20], "")
-
+
def testTryExceptFinally(self):
self.check_coverage("""\
a = 0; b = 0
@@ -1574,7 +1574,7 @@ if sys.hexversion >= 0x020500f0:
assert a == 99 and b == 2
""",
[1,2,3,4,5,6,8,10,11], "8")
-
+
class ModuleTest(CoverageTest):
"""Tests for the module-level behavior of the `coverage` module."""
@@ -1593,7 +1593,7 @@ class ProcessTest(CoverageTest):
h = "Hello"
w = "world"
""")
-
+
self.assert_(not os.path.exists(".coverage"))
self.run_command("coverage -x mycode.py")
self.assert_(os.path.exists(".coverage"))
@@ -1611,7 +1611,7 @@ class ProcessTest(CoverageTest):
out = self.run_command("coverage -x mycode.py")
self.assert_(os.path.exists(".coverage"))
self.assertEqual(out, 'done\n')
-
+
def testCombineParallelData(self):
self.make_file("b_or_c.py", """\
import sys
@@ -1623,7 +1623,7 @@ class ProcessTest(CoverageTest):
d = 1
print ('done')
""")
-
+
out = self.run_command("coverage -x -p b_or_c.py b")
self.assertEqual(out, 'done\n')
self.assert_(not os.path.exists(".coverage"))
@@ -1631,7 +1631,7 @@ class ProcessTest(CoverageTest):
out = self.run_command("coverage -x -p b_or_c.py c")
self.assertEqual(out, 'done\n')
self.assert_(not os.path.exists(".coverage"))
-
+
# After two -p runs, there should be two .coverage.machine.123 files.
self.assertEqual(
len([f for f in os.listdir('.') if f.startswith('.coverage.')]),
diff --git a/test/test_data.py b/test/test_data.py
index 98acc2bb..4f784253 100644
--- a/test/test_data.py
+++ b/test/test_data.py
@@ -29,11 +29,11 @@ class DataTest(CoverageTest):
def assert_summary(self, covdata, summary):
"""Check that the summary of `covdata` is `summary`."""
self.assertEqual(covdata.summary(), summary)
-
+
def assert_executed_files(self, covdata, execed):
"""Check that `covdata`'s executed files are `execed`."""
self.assertSameElements(covdata.executed_files(), execed)
-
+
def test_reading_empty(self):
covdata = CoverageData()
covdata.read()
@@ -44,12 +44,12 @@ class DataTest(CoverageTest):
covdata.add_line_data(DATA_1)
self.assert_summary(covdata, SUMMARY_1)
self.assert_executed_files(covdata, EXECED_FILES_1)
-
+
def test_writing_and_reading(self):
covdata1 = CoverageData()
covdata1.add_line_data(DATA_1)
covdata1.write()
-
+
covdata2 = CoverageData()
covdata2.read()
self.assert_summary(covdata2, SUMMARY_1)
@@ -58,11 +58,11 @@ class DataTest(CoverageTest):
covdata1 = CoverageData(suffix='1')
covdata1.add_line_data(DATA_1)
covdata1.write()
-
+
covdata2 = CoverageData(suffix='2')
covdata2.add_line_data(DATA_2)
covdata2.write()
-
+
covdata3 = CoverageData()
covdata3.combine_parallel_data()
self.assert_summary(covdata3, SUMMARY_1_2)
@@ -74,7 +74,7 @@ class DataTest(CoverageTest):
covdata1.write()
covdata1.erase()
self.assert_summary(covdata1, {})
-
+
covdata2 = CoverageData()
covdata2.read()
self.assert_summary(covdata2, {})
@@ -84,13 +84,13 @@ class DataTest(CoverageTest):
covdata = CoverageData()
covdata.add_line_data(DATA_1)
covdata.write()
-
+
fdata = open(".coverage", 'rb')
try:
data = pickle.load(fdata)
finally:
fdata.close()
-
+
lines = data['lines']
self.assertSameElements(lines.keys(), EXECED_FILES_1)
self.assertSameElements(lines['a.py'], A_PY_LINES_1)
@@ -103,13 +103,13 @@ class DataTest(CoverageTest):
covdata = CoverageData()
covdata.add_arc_data(ARC_DATA_3)
covdata.write()
-
+
fdata = open(".coverage", 'rb')
try:
data = pickle.load(fdata)
finally:
fdata.close()
-
+
self.assertSameElements(data['lines'].keys(), [])
arcs = data['arcs']
self.assertSameElements(arcs['x.py'], X_PY_ARCS_3)
diff --git a/test/test_execfile.py b/test/test_execfile.py
index 5e9f4fd5..8c5e9a11 100644
--- a/test/test_execfile.py
+++ b/test/test_execfile.py
@@ -17,7 +17,7 @@ class RunTest(CoverageTest):
tryfile = os.path.join(here, "try_execfile.py")
run_python_file(tryfile, [tryfile, "arg1", "arg2"])
mod_globs = eval(self.stdout())
-
+
# The file should think it is __main__
self.assertEqual(mod_globs['__name__'], "__main__")
@@ -30,10 +30,10 @@ class RunTest(CoverageTest):
"Test file for run_python_file.")
self.assertEqual(mod_globs['DATA'], "xyzzy")
self.assertEqual(mod_globs['FN_VAL'], "my_fn('fooey')")
-
+
# It must be self-importable as __main__.
self.assertEqual(mod_globs['__main__.DATA'], "xyzzy")
-
+
# Argv should have the proper values.
self.assertEqual(mod_globs['argv'], [tryfile, "arg1", "arg2"])
diff --git a/test/test_farm.py b/test/test_farm.py
index dcebbac5..de07541b 100644
--- a/test/test_farm.py
+++ b/test/test_farm.py
@@ -15,9 +15,9 @@ def test_farm(clean_only=False):
class FarmTestCase(object):
"""A test case from the farm tree.
-
+
Tests are short Python script files, often called run.py:
-
+
copy("src", "out")
run('''
coverage -x white.py
@@ -29,14 +29,14 @@ class FarmTestCase(object):
Verbs (copy, run, compare, clean) are methods in this class. FarmTestCase
has options to allow various uses of the test cases (normal execution,
cleaning-only, or run and leave the results for debugging).
-
+
"""
def __init__(self, runpy, clean_only=False, dont_clean=False):
"""Create a test case from a run.py file.
-
+
`clean_only` means that only the clean() action is executed.
`dont_clean` means that the clean() action is not executed.
-
+
"""
self.description = runpy
self.dir, self.runpy = os.path.split(runpy)
@@ -54,14 +54,14 @@ class FarmTestCase(object):
oldpath = sys.path[:]
sys.path.insert(0, directory)
return oldpath
-
+
def restorepath(self, path):
"""Restore the system path to `path`."""
sys.path = path
def __call__(self):
"""Execute the test from the run.py file.
-
+
"""
cwd = self.cd(self.dir)
@@ -74,7 +74,7 @@ class FarmTestCase(object):
glo = dict([(fn, getattr(self, fn)) for fn in fns])
if self.dont_clean:
glo['clean'] = self.noop
-
+
try:
execfile(self.runpy, glo)
finally:
@@ -90,11 +90,11 @@ class FarmTestCase(object):
def fnmatch_list(self, files, file_pattern):
"""Filter the list of `files` to only those that match `file_pattern`.
-
+
If `file_pattern` is None, then return the entire list of files.
-
+
Returns a list of the filtered files.
-
+
"""
if file_pattern:
files = [f for f in files if fnmatch.fnmatch(f, file_pattern)]
@@ -106,7 +106,7 @@ class FarmTestCase(object):
# Modules should be importable from the current directory.
self.old_syspath = sys.path[:]
sys.path.insert(0, '')
-
+
def tearDown(self):
"""Test tear down, run by nose after __call__."""
# Make sure no matter what, the test is cleaned up.
@@ -118,11 +118,11 @@ class FarmTestCase(object):
sys.path = self.old_syspath
# Functions usable inside farm run.py files
-
+
def noop(self, *args, **kwargs):
"""A no-op function to stub out run, copy, etc, when only cleaning."""
pass
-
+
def copy(self, src, dst):
"""Copy a directory."""
@@ -132,11 +132,11 @@ class FarmTestCase(object):
def run(self, cmds, rundir="src", outfile=None):
"""Run a list of commands.
-
+
`cmds` is a string, commands separated by newlines.
`rundir` is the directory in which to run the commands.
`outfile` is a filename to redirect stdout to.
-
+
"""
cwd = self.cd(rundir)
try:
@@ -155,12 +155,12 @@ class FarmTestCase(object):
def runfunc(self, fn, rundir="src", addtopath=None):
"""Run a function.
-
+
`fn` is a callable.
`rundir` is the directory in which to run the function.
-
+
"""
-
+
cwd = self.cd(rundir)
oldpath = self.addtopath(addtopath)
try:
@@ -173,28 +173,28 @@ class FarmTestCase(object):
left_extra=False, right_extra=False, scrubs=None
):
"""Compare files matching `file_pattern` in `dir1` and `dir2`.
-
+
`dir2` is interpreted as a prefix, with Python version numbers appended
to find the actual directory to compare with. "foo" will compare against
"foo_v241", "foo_v24", "foo_v2", or "foo", depending on which directory
is found first.
-
+
`size_within` is a percentage delta for the file sizes. If non-zero,
then the file contents are not compared (since they are expected to
often be different), but the file sizes must be within this amount.
For example, size_within=10 means that the two files' sizes must be
within 10 percent of each other to compare equal.
-
+
`left_extra` true means the left directory can have extra files in it
without triggering an assertion. `right_extra` means the right
directory can.
-
+
`scrubs` is a list of pairs, regex find and replace patterns to use to
scrub the files of unimportant differences.
-
+
An assertion will be raised if the directories fail one of their
matches.
-
+
"""
# Search for a dir2 with a version suffix.
version_suff = ''.join(map(str, sys.version_info[:3]))
@@ -207,12 +207,12 @@ class FarmTestCase(object):
assert os.path.exists(dir1), "Left directory missing: %s" % dir1
assert os.path.exists(dir2), "Right directory missing: %s" % dir2
-
+
dc = filecmp.dircmp(dir1, dir2)
diff_files = self.fnmatch_list(dc.diff_files, file_pattern)
left_only = self.fnmatch_list(dc.left_only, file_pattern)
right_only = self.fnmatch_list(dc.right_only, file_pattern)
-
+
if size_within:
# The files were already compared, use the diff_files list as a
# guide for size comparison.
@@ -253,10 +253,10 @@ class FarmTestCase(object):
def _scrub(self, strlist, scrubs):
"""Scrub uninteresting data from the strings in `strlist`.
-
+
`scrubs is a list of (find, replace) pairs of regexes that are used on
each string in `strlist`. A list of scrubbed strings is returned.
-
+
"""
scrubbed = []
for s in strlist:
@@ -267,10 +267,10 @@ class FarmTestCase(object):
def contains(self, filename, *strlist):
"""Check that the file contains all of a list of strings.
-
+
An assert will be raised if one of the arguments in `strlist` is
missing in `filename`.
-
+
"""
text = open(filename, "r").read()
for s in strlist:
@@ -278,10 +278,10 @@ class FarmTestCase(object):
def doesnt_contain(self, filename, *strlist):
"""Check that the file contains none of a list of strings.
-
+
An assert will be raised if any of the strings in strlist appears in
`filename`.
-
+
"""
text = open(filename, "r").read()
for s in strlist:
@@ -294,13 +294,13 @@ class FarmTestCase(object):
def main(): # pragma: no cover
"""Command-line access to test_farm.
-
+
Commands:
-
+
run testcase - Run a single test case.
out testcase - Run a test case, but don't clean up, to see the output.
clean - Clean all the output for all tests.
-
+
"""
op = sys.argv[1]
if op == 'run':
@@ -317,7 +317,7 @@ def main(): # pragma: no cover
test[0].run_fully()
else:
print("Need an operation: run, out, clean")
-
+
# So that we can run just one farm run.py at a time.
if __name__ == '__main__':
main()
diff --git a/test/test_oddball.py b/test/test_oddball.py
index 6c97272d..05252ef8 100644
--- a/test/test_oddball.py
+++ b/test/test_oddball.py
@@ -16,13 +16,13 @@ class ThreadingTest(CoverageTest):
def fromMainThread():
return "called from main thread"
-
+
def fromOtherThread():
return "called from other thread"
-
+
def neverCalled():
return "no one calls me"
-
+
other = threading.Thread(target=fromOtherThread)
other.start()
fromMainThread()
@@ -42,11 +42,11 @@ class RecursionTest(CoverageTest):
return 0
else:
return recur(n-1)+1
-
+
recur(495) # We can get at least this many stack frames.
""",
[1,2,3,5,7], "")
-
+
def testLongRecursion(self):
# We can't finish a very deep recursion, but we don't crash.
self.assertRaises(RuntimeError, self.check_coverage,
@@ -56,7 +56,7 @@ class RecursionTest(CoverageTest):
return 0
else:
return recur(n-1)+1
-
+
recur(100000) # This is definitely too many frames.
""",
[1,2,3,5,7], "")
@@ -135,7 +135,7 @@ class PyexpatTest(CoverageTest):
_, statements, missing, _ = cov.analysis("trydom.py")
self.assertEqual(statements, [1,3,8,9,10,11,13])
self.assertEqual(missing, [])
-
+
_, statements, missing, _ = cov.analysis("outer.py")
self.assertEqual(statements, [101,102])
self.assertEqual(missing, [])
@@ -145,7 +145,7 @@ class ExceptionTest(CoverageTest):
"""I suspect different versions of Python deal with exceptions differently
in the trace function.
"""
-
+
def testException(self):
# Python 2.3's trace function doesn't get called with "return" if the
# scope is exiting due to an exception. This confounds our trace
@@ -156,21 +156,21 @@ class ExceptionTest(CoverageTest):
# stack is in a different file, to try to trip up the tracer. Each
# file has active lines in a different range so we'll see if the lines
# get attributed to the wrong file.
-
+
self.make_file("oops.py", """\
def oops(args):
a = 2
raise Exception("oops")
a = 4
""")
-
+
self.make_file("fly.py", "\n"*100 + """\
def fly(calls):
a = 2
calls[0](calls[1:])
a = 4
""")
-
+
self.make_file("catch.py", "\n"*200 + """\
def catch(calls):
try:
@@ -180,7 +180,7 @@ class ExceptionTest(CoverageTest):
except:
a = 7
""")
-
+
self.make_file("doit.py", "\n"*300 + """\
def doit(calls):
try:
@@ -220,19 +220,19 @@ class ExceptionTest(CoverageTest):
'oops.py': [2,3],
}),
]
-
+
for callnames, lines_expected in runs:
-
+
# Make the list of functions we'll call for this test.
calls = [getattr(sys.modules[cn], cn) for cn in callnames.split()]
-
+
cov = coverage.coverage()
cov.start()
# Call our list of functions: invoke the first, with the rest as
# an argument.
calls[0](calls[1:])
cov.stop()
-
+
# Clean the line data and compare to expected results.
# The filenames are absolute, so keep just the base.
lines = cov.data.line_data()
@@ -248,10 +248,10 @@ class ExceptionTest(CoverageTest):
if sys.hexversion > 0x02050000:
class DoctestTest(CoverageTest):
"""Tests invoked with doctest should measure properly."""
-
+
def setUp(self):
super(DoctestTest, self).setUp()
-
+
# Oh, the irony! This test case exists because Python 2.4's
# doctest module doesn't play well with coverage. But nose fixes
# the problem by monkeypatching doctest. I want to undo the
@@ -260,12 +260,12 @@ if sys.hexversion > 0x02050000:
# enough: when the test imports doctest again, it will get a fresh
# copy without the monkeypatch.
del sys.modules['doctest']
-
+
def testDoctest(self):
self.check_coverage('''\
def return_arg_or_void(arg):
"""If <arg> is None, return "Void"; otherwise return <arg>
-
+
>>> return_arg_or_void(None)
'Void'
>>> return_arg_or_void("arg")
@@ -277,7 +277,7 @@ if sys.hexversion > 0x02050000:
return "Void"
else:
return arg
-
+
import doctest, sys
doctest.testmod(sys.modules[__name__]) # we're not __main__ :(
''',
diff --git a/test/test_parser.py b/test/test_parser.py
index 0dc7089c..b398044d 100644
--- a/test/test_parser.py
+++ b/test/test_parser.py
@@ -19,7 +19,7 @@ class ParserTest(CoverageTest):
cp = CodeParser(text, exclude="nocover")
cp.parse_source()
return cp
-
+
def test_exit_counts(self):
cp = self.parse_source("""\
# check some basic branch counting
@@ -29,7 +29,7 @@ class ParserTest(CoverageTest):
return 5
else:
return 7
-
+
class Bar:
pass
""")
@@ -52,13 +52,13 @@ class ParserTest(CoverageTest):
self.assertEqual(cp.exit_counts(), {
1: 1, 2:1, 3:1, 4:1, 5:1, 6:1, 7:1, 8:1, 9:1
})
-
+
def test_excluded_classes(self):
cp = self.parse_source("""\
class Foo:
def __init__(self):
pass
-
+
if 0: # nocover
class Bar:
pass
@@ -66,7 +66,7 @@ class ParserTest(CoverageTest):
self.assertEqual(cp.exit_counts(), {
1:0, 2:1, 3:1
})
-
+
def test_missing_branch_to_excluded_code(self):
cp = self.parse_source("""\
if fooey:
diff --git a/test/test_phystokens.py b/test/test_phystokens.py
index a01cc374..6b16d68e 100644
--- a/test/test_phystokens.py
+++ b/test/test_phystokens.py
@@ -77,5 +77,3 @@ class PhysTokensTest(CoverageTest):
# Check the tokenization of a stress-test file.
stress = os.path.join(HERE, "stress_phystoken.txt")
self.check_file_tokenization(stress)
-
- \ No newline at end of file
diff --git a/test/test_results.py b/test/test_results.py
index 33ebe4d7..ef15121c 100644
--- a/test/test_results.py
+++ b/test/test_results.py
@@ -10,7 +10,7 @@ from coveragetest import CoverageTest
class NumbersTest(CoverageTest):
"""Tests for Coverage.py's numeric measurement summaries."""
-
+
run_in_temp_dir = False
def test_basic(self):
@@ -19,7 +19,7 @@ class NumbersTest(CoverageTest):
self.assertEqual(n1.n_executed, 180)
self.assertEqual(n1.n_missing, 20)
self.assertEqual(n1.pc_covered, 90)
-
+
def test_addition(self):
n1 = Numbers(n_files=1, n_statements=200, n_missing=20)
n2 = Numbers(n_files=1, n_statements=10, n_missing=8)
diff --git a/test/test_summary.py b/test/test_summary.py
index 36db9969..0eec58ca 100644
--- a/test/test_summary.py
+++ b/test/test_summary.py
@@ -22,7 +22,7 @@ class SummaryTest(CoverageTest):
report = self.run_command(cmd).replace('\\', '/')
self.assert_("error" not in report.lower())
return report
-
+
def line_count(self, report):
"""How many lines are in `report`?"""
self.assertEqual(report.split('\n')[-1], "")
@@ -73,7 +73,7 @@ class SummaryTest(CoverageTest):
prefix = os.path.split(__file__)[0]
self.run_command("coverage -x mycode.py")
report = self.report_from_command("coverage -r -o %s" % prefix)
-
+
# Name Stmts Exec Cover
# ----------------------------
# mycode 4 4 100%
diff --git a/test/test_templite.py b/test/test_templite.py
index 35c1df55..57385cba 100644
--- a/test/test_templite.py
+++ b/test/test_templite.py
@@ -9,9 +9,9 @@ import unittest
class AnyOldObject(object):
"""Simple testing object.
-
+
Use keyword arguments in the constructor to set attributes on the object.
-
+
"""
def __init__(self, **attrs):
for n, v in attrs.items():
@@ -45,7 +45,7 @@ class TempliteTest(unittest.TestCase):
'second': lambda x: x[1],
}
self.try_render("Hello, {{name|upper}}!", data, "Hello, NED!")
-
+
# Pipes can be concatenated.
self.try_render("Hello, {{name|upper|second}}!", data, "Hello, E!")
@@ -55,7 +55,7 @@ class TempliteTest(unittest.TestCase):
'upper': lambda x: x.upper(),
'punct': '!',
}
-
+
template = Templite("This is {{name|upper}}{{punct}}", globs)
self.assertEqual(template.render({'name':'Ned'}), "This is NED!")
self.assertEqual(template.render({'name':'Ben'}), "This is BEN!")
@@ -67,7 +67,7 @@ class TempliteTest(unittest.TestCase):
obj2 = AnyOldObject(obj=obj, b="Bee")
self.try_render("{{obj2.obj.a}} {{obj2.b}}", locals(), "Ay Bee")
-
+
def test_member_function(self):
# Variables' member functions can be used, as long as they are nullary.
class WithMemberFns(AnyOldObject):
@@ -97,7 +97,7 @@ class TempliteTest(unittest.TestCase):
l = l[:]
l.reverse()
return l
-
+
self.try_render(
"Look: {% for n in nums|rev %}{{n}}, {% endfor %}done.",
locals(),
@@ -117,7 +117,7 @@ class TempliteTest(unittest.TestCase):
{'nums':[1,2,3]},
"Look: \n\n1, \n\n2, \n\n3, \ndone."
)
-
+
def test_multiple_loops(self):
self.try_render(
"{% for n in nums %}{{n}}{% endfor %} and "