summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2014-06-03 22:09:58 -0400
committerNed Batchelder <ned@nedbatchelder.com>2014-06-03 22:09:58 -0400
commitcc2b678e7452395e58e3df43116b06c3410bec06 (patch)
tree026b8754fac71ac4a50d112ff566de0ab356b506
parentdfe2fa5e5db2cf29a1b43b0abf61be3b545db270 (diff)
downloadpython-coveragepy-git-cc2b678e7452395e58e3df43116b06c3410bec06.tar.gz
Remove old stuff for old Pythons
-rw-r--r--tests/backtest.py46
-rw-r--r--tests/coveragetest.py7
-rw-r--r--tests/test_process.py34
3 files changed, 37 insertions, 50 deletions
diff --git a/tests/backtest.py b/tests/backtest.py
index 7b47ff19..439493d1 100644
--- a/tests/backtest.py
+++ b/tests/backtest.py
@@ -4,41 +4,31 @@
# (Redefining built-in blah)
# The whole point of this file is to redefine built-ins, so shut up about it.
-import os
+import subprocess
-# Py2 and Py3 don't agree on how to run commands in a subprocess.
-try:
- import subprocess
-except ImportError:
- def run_command(cmd, status=0):
- """Run a command in a subprocess.
-
- Returns the exit status code and the combined stdout and stderr.
- """
- _, stdouterr = os.popen4(cmd)
- return status, stdouterr.read()
+# 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 subprocess.
-else:
- def run_command(cmd, status=0):
- """Run a command in a subprocess.
+ Returns the exit status code and the combined stdout and stderr.
- 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 # pylint: disable=E1101
- """
- proc = subprocess.Popen(cmd, shell=True,
- stdin=subprocess.PIPE, stdout=subprocess.PIPE,
- stderr=subprocess.STDOUT
- )
- output, _ = proc.communicate()
- status = proc.returncode # pylint: disable=E1101
+ # Get the output, and canonicalize it to strings with newlines.
+ if not isinstance(output, str):
+ output = output.decode('utf-8')
+ output = output.replace('\r', '')
- # 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
- return status, output
# No more execfile in Py3
try:
diff --git a/tests/coveragetest.py b/tests/coveragetest.py
index fa55dec3..0171ec14 100644
--- a/tests/coveragetest.py
+++ b/tests/coveragetest.py
@@ -458,7 +458,7 @@ class CoverageTest(TestCase):
_, output = self.run_command_status(cmd)
return output
- def run_command_status(self, cmd, status=0):
+ def run_command_status(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.
@@ -467,9 +467,6 @@ class CoverageTest(TestCase):
Returns a pair: the process' exit status and stdout text.
- The `status` argument is returned as the status on older Pythons where
- we can't get the actual exit status of the process.
-
"""
# Add our test modules directory to PYTHONPATH. I'm sure there's too
# much path munging here, but...
@@ -482,7 +479,7 @@ class CoverageTest(TestCase):
pypath += testmods + os.pathsep + zipfile
self.set_environ('PYTHONPATH', pypath)
- status, output = run_command(cmd, status=status)
+ status, output = run_command(cmd)
print(output)
return status, output
diff --git a/tests/test_process.py b/tests/test_process.py
index b9203e3e..d8314982 100644
--- a/tests/test_process.py
+++ b/tests/test_process.py
@@ -240,13 +240,13 @@ class ProcessTest(CoverageTest):
self.run_command("coverage run fleeting")
os.remove("fleeting")
- status, out = self.run_command_status("coverage html -d htmlcov", 1)
+ status, out = self.run_command_status("coverage html -d htmlcov")
self.assertRegex(out, "No source for code: '.*fleeting'")
self.assertNotIn("Traceback", out)
self.assertEqual(status, 1)
def test_running_missing_file(self):
- status, out = self.run_command_status("coverage run xyzzy.py", 1)
+ status, out = self.run_command_status("coverage run xyzzy.py")
self.assertRegex(out, "No file to run: .*xyzzy.py")
self.assertNotIn("raceback", out)
self.assertNotIn("rror", out)
@@ -265,7 +265,7 @@ class ProcessTest(CoverageTest):
# The important thing is for "coverage run" and "python" to report the
# same traceback.
- status, out = self.run_command_status("coverage run throw.py", 1)
+ status, out = self.run_command_status("coverage run throw.py")
out2 = self.run_command("python throw.py")
if '__pypy__' in sys.builtin_module_names:
# Pypy has an extra frame in the traceback for some reason
@@ -294,8 +294,8 @@ class ProcessTest(CoverageTest):
# The important thing is for "coverage run" and "python" to have the
# same output. No traceback.
- status, out = self.run_command_status("coverage run exit.py", 17)
- status2, out2 = self.run_command_status("python exit.py", 17)
+ status, out = self.run_command_status("coverage run exit.py")
+ status2, out2 = self.run_command_status("python exit.py")
self.assertMultiLineEqual(out, out2)
self.assertMultiLineEqual(out, "about to exit..\n")
self.assertEqual(status, status2)
@@ -310,8 +310,8 @@ class ProcessTest(CoverageTest):
f1()
""")
- status, out = self.run_command_status("coverage run exit_none.py", 0)
- status2, out2 = self.run_command_status("python exit_none.py", 0)
+ status, out = self.run_command_status("coverage run exit_none.py")
+ status2, out2 = self.run_command_status("python exit_none.py")
self.assertMultiLineEqual(out, out2)
self.assertMultiLineEqual(out, "about to exit quietly..\n")
self.assertEqual(status, status2)
@@ -578,7 +578,7 @@ class FailUnderTest(CoverageTest):
d = 6
e = 7
""")
- st, _ = self.run_command_status("coverage run forty_two_plus.py", 0)
+ st, _ = self.run_command_status("coverage run forty_two_plus.py")
self.assertEqual(st, 0)
st, out = self.run_command_status("coverage report")
self.assertEqual(st, 0)
@@ -588,27 +588,27 @@ class FailUnderTest(CoverageTest):
)
def test_report(self):
- st, _ = self.run_command_status("coverage report --fail-under=42", 0)
+ st, _ = self.run_command_status("coverage report --fail-under=42")
self.assertEqual(st, 0)
- st, _ = self.run_command_status("coverage report --fail-under=43", 0)
+ st, _ = self.run_command_status("coverage report --fail-under=43")
self.assertEqual(st, 0)
- st, _ = self.run_command_status("coverage report --fail-under=44", 2)
+ st, _ = self.run_command_status("coverage report --fail-under=44")
self.assertEqual(st, 2)
def test_html_report(self):
- st, _ = self.run_command_status("coverage html --fail-under=42", 0)
+ st, _ = self.run_command_status("coverage html --fail-under=42")
self.assertEqual(st, 0)
- st, _ = self.run_command_status("coverage html --fail-under=43", 0)
+ st, _ = self.run_command_status("coverage html --fail-under=43")
self.assertEqual(st, 0)
- st, _ = self.run_command_status("coverage html --fail-under=44", 2)
+ st, _ = self.run_command_status("coverage html --fail-under=44")
self.assertEqual(st, 2)
def test_xml_report(self):
- st, _ = self.run_command_status("coverage xml --fail-under=42", 0)
+ st, _ = self.run_command_status("coverage xml --fail-under=42")
self.assertEqual(st, 0)
- st, _ = self.run_command_status("coverage xml --fail-under=43", 0)
+ st, _ = self.run_command_status("coverage xml --fail-under=43")
self.assertEqual(st, 0)
- st, _ = self.run_command_status("coverage xml --fail-under=44", 2)
+ st, _ = self.run_command_status("coverage xml --fail-under=44")
self.assertEqual(st, 2)