This repository has been archived by the owner on Dec 13, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Python 2.6 tested on Windows. No subprocess32.
Using Popen and defining my own check_output() instead of installing subprocess32 which doesn't work on Windows.
- Loading branch information
Showing
7 changed files
with
40 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,37 @@ | ||
"""Non-fixture code shared among test modules.""" | ||
|
||
import os | ||
import subprocess | ||
|
||
try: | ||
from subprocess import check_output, STDOUT | ||
except ImportError: | ||
from subprocess32 import check_output, STDOUT | ||
|
||
def check_output(command, cwd=None, env=None, stdin=None): | ||
"""Basically subprocess.check_output since it doesn't exist in Python 2.6. | ||
assert check_output | ||
assert STDOUT | ||
:raise CalledProcessError: Command exits non-zero. | ||
:param iter command: Command to run. | ||
:param str cwd: Current working directory. | ||
:param dict env: Set environment variables. | ||
:param file stdin: Pipe handle to subprocess' stdin. | ||
:return: Command output. | ||
:rtype: str | ||
""" | ||
stdout = subprocess.STDOUT | ||
pipe = subprocess.PIPE | ||
|
||
# Setup env. | ||
environ = os.environ.copy() | ||
if env: | ||
environ.update(env) | ||
|
||
# Run command. | ||
with open(os.devnull) as null: | ||
proc = subprocess.Popen(command, cwd=cwd, env=environ, stdout=pipe, stderr=stdout, stdin=stdin or null) | ||
output = proc.communicate()[0].decode('utf-8') # Blocks until command exits. | ||
|
||
# Raise if non-zero exit. | ||
if proc.poll() != 0: | ||
raise subprocess.CalledProcessError(proc.poll(), command, output=output) | ||
|
||
return output |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters