Skip to content

Commit

Permalink
adding more compat functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
toumorokoshi committed Jan 29, 2015
1 parent 6f81411 commit 858b8f6
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
7 changes: 6 additions & 1 deletion uranium/compat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,9 @@
try:
from importlib import import_module
except:
from c_importlib import import_module
from .c_importlib import import_module

try:
from subprocess import check_output
except:
from .check_output import check_output
22 changes: 22 additions & 0 deletions uranium/compat/check_output.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import subprocess


def check_output(*popenargs, **kwargs):
r"""Run command with arguments and return its output as a byte string.
Backported from Python 2.7 as it's implemented as pure python on stdlib.
>>> check_output(['/usr/bin/python', '--version'])
Python 2.6.2
"""
process = subprocess.Popen(stdout=subprocess.PIPE, *popenargs, **kwargs)
output, unused_err = process.communicate()
retcode = process.poll()
if retcode:
cmd = kwargs.get("args")
if cmd is None:
cmd = popenargs[0]
error = subprocess.CalledProcessError(retcode, cmd)
error.output = output
raise error
return output
6 changes: 3 additions & 3 deletions uranium/tests/test_full/test_egg_resolution.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
tests for the warmup script
"""
import os
import subprocess
from uranium.compat import check_output
from uranium.tests.utils import FullUraniumBaseTest
from nose.tools import eq_

Expand All @@ -25,7 +25,7 @@ def test_egg_resolution(self):
"""
ensure that egg version take precedence version specs
"""
output = subprocess.check_output(['./bin/python', '-c', 'import requests; print(requests.__version__)'],
cwd=self.root)
output = check_output(['./bin/python', '-c', 'import requests; print(requests.__version__)'],
cwd=self.root)
output = output.decode('ascii').strip()
eq_(output, '2.3.0')

0 comments on commit 858b8f6

Please sign in to comment.