diff options
-rw-r--r-- | tests/backtest.py | 25 | ||||
-rw-r--r-- | tests/coveragetest.py | 23 | ||||
-rw-r--r-- | tests/helpers.py | 26 | ||||
-rw-r--r-- | tests/test_farm.py | 19 |
4 files changed, 53 insertions, 40 deletions
diff --git a/tests/backtest.py b/tests/backtest.py index 73b1067d..50834721 100644 --- a/tests/backtest.py +++ b/tests/backtest.py @@ -4,31 +4,6 @@ # (Redefining built-in blah) # The whole point of this file is to redefine built-ins, so shut up about it. -import subprocess - - -# This isn't really a backward compatibility thing, should be moved into a -# helpers file or something. -def run_command(cmd): - """Run a command in a sub-process. - - Returns the exit status code and the combined stdout and stderr. - - """ - proc = subprocess.Popen(cmd, shell=True, - stdin=subprocess.PIPE, stdout=subprocess.PIPE, - stderr=subprocess.STDOUT - ) - output, _ = proc.communicate() - status = proc.returncode - - # Get the output, and canonicalize it to strings with newlines. - if not isinstance(output, str): - output = output.decode('utf-8') - output = output.replace('\r', '') - - return status, output - # No more execfile in Py3 try: diff --git a/tests/coveragetest.py b/tests/coveragetest.py index 288fc438..d673f6d6 100644 --- a/tests/coveragetest.py +++ b/tests/coveragetest.py @@ -10,7 +10,7 @@ import sys import coverage from coverage.backunittest import TestCase -from coverage.backward import StringIO, import_local_file +from coverage.backward import StringIO, import_local_file, string_class from coverage.control import _TEST_NAME_FILE from coverage.test_helpers import ( EnvironmentAwareMixin, StdStreamCapturingMixin, TempDirMixin, @@ -18,12 +18,13 @@ from coverage.test_helpers import ( from nose.plugins.skip import SkipTest -from tests.backtest import run_command +from tests.helpers import run_command # Status returns for the command line. OK, ERR = 0, 1 + class CoverageTest( EnvironmentAwareMixin, StdStreamCapturingMixin, @@ -125,15 +126,15 @@ class CoverageTest( for pair in arcz.split(): asgn = bsgn = 1 if len(pair) == 2: - a,b = pair + a, b = pair else: assert len(pair) == 3 if pair[0] == '-': - _,a,b = pair + _, a, b = pair asgn = -1 else: assert pair[1] == '-' - a,_,b = pair + a, _, b = pair bsgn = -1 arcs.append((asgn*self._arcz_map[a], bsgn*self._arcz_map[b])) return sorted(arcs) @@ -145,9 +146,11 @@ class CoverageTest( s2 = "\n".join(repr(a) for a in a2) + "\n" self.assertMultiLineEqual(s1, s2, msg) - def check_coverage(self, text, lines=None, missing="", report="", - excludes=None, partials="", - arcz=None, arcz_missing="", arcz_unpredicted=""): + def check_coverage( + self, text, lines=None, missing="", report="", + excludes=None, partials="", + arcz=None, arcz_missing="", arcz_unpredicted="" + ): """Check the coverage measurement of `text`. The source `text` is run and measured. `lines` are the line numbers @@ -192,7 +195,7 @@ class CoverageTest( analysis = cov._analyze(mod) statements = sorted(analysis.statements) if lines is not None: - if type(lines[0]) == type(1): + if isinstance(lines[0], int): # lines is just a list of numbers, it must match the statements # found in the code. self.assertEqual(statements, lines) @@ -208,7 +211,7 @@ class CoverageTest( ) missing_formatted = analysis.missing_formatted() - if type(missing) == type(""): + if isinstance(missing, string_class): self.assertEqual(missing_formatted, missing) else: for missing_list in missing: diff --git a/tests/helpers.py b/tests/helpers.py index db20d798..c26f4859 100644 --- a/tests/helpers.py +++ b/tests/helpers.py @@ -1,5 +1,31 @@ """Helpers for coverage.py tests.""" +import subprocess + + +# This isn't really a backward compatibility thing, should be moved into a +# helpers file or something. +def run_command(cmd): + """Run a command in a sub-process. + + Returns the exit status code and the combined stdout and stderr. + + """ + proc = subprocess.Popen( + cmd, shell=True, + stdin=subprocess.PIPE, stdout=subprocess.PIPE, + stderr=subprocess.STDOUT + ) + output, _ = proc.communicate() + status = proc.returncode + + # Get the output, and canonicalize it to strings with newlines. + if not isinstance(output, str): + output = output.decode('utf-8') + output = output.replace('\r', '') + + return status, output + class CheckUniqueFilenames(object): """Asserts the uniqueness of filenames passed to a function.""" diff --git a/tests/test_farm.py b/tests/test_farm.py index 31bd4c65..92bd968a 100644 --- a/tests/test_farm.py +++ b/tests/test_farm.py @@ -1,9 +1,17 @@ """Run tests in the farm sub-directory. Designed for nose.""" -import difflib, filecmp, fnmatch, glob, os, re, shutil, sys +import difflib +import filecmp +import fnmatch +import glob +import os +import re +import shutil +import sys + from nose.plugins.skip import SkipTest -from tests.backtest import run_command +from tests.helpers import run_command from tests.backtest import execfile # pylint: disable=redefined-builtin from coverage.control import _TEST_NAME_FILE @@ -199,9 +207,10 @@ class FarmTestCase(object): self.cd(cwd) self.restorepath(oldpath) - def compare(self, dir1, dir2, file_pattern=None, size_within=0, - left_extra=False, right_extra=False, scrubs=None - ): + def compare( + self, dir1, dir2, file_pattern=None, size_within=0, + 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 |