diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2013-02-02 11:15:11 -0500 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2013-02-02 11:15:11 -0500 |
commit | d5f8295256d04ba8cb5b42a16ce741a34c9bb3c5 (patch) | |
tree | ff8c6d6310bb3865411d40198c07f26eb5709959 /tests/backtest.py | |
parent | b5a466fc3d7a71fc811b2430f04e6fc270858935 (diff) | |
download | python-coveragepy-d5f8295256d04ba8cb5b42a16ce741a34c9bb3c5.tar.gz |
Move the test directory to tests to avoid conflicts with the stdlib test package.
Diffstat (limited to 'tests/backtest.py')
-rw-r--r-- | tests/backtest.py | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/tests/backtest.py b/tests/backtest.py new file mode 100644 index 0000000..b17aa24 --- /dev/null +++ b/tests/backtest.py @@ -0,0 +1,49 @@ +"""Add things to old Pythons so I can pretend they are newer, for tests.""" + +# pylint: disable=W0622 +# (Redefining built-in blah) +# The whole point of this file is to redefine built-ins, so shut up about it. + +import os + +# Py2k and 3k 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() + +else: + def run_command(cmd, status=0): + """Run a command in a subprocess. + + 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 + + # 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 Py3k +try: + execfile = execfile +except NameError: + def execfile(filename, globs): + """A Python 3 implementation of execfile.""" + exec(compile(open(filename).read(), filename, 'exec'), globs) |