Skip to content
This repository has been archived by the owner on May 23, 2023. It is now read-only.

Commit

Permalink
fix coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
Buck Golemon committed Nov 18, 2014
1 parent e4d4118 commit 3395033
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
7 changes: 5 additions & 2 deletions tests/functional/simple_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def test_second_install_faster(tmpdir):
coverage
pylint
pytest
wsgiref==0.1
''')

from time import time
Expand Down Expand Up @@ -70,15 +71,17 @@ def test_arguments_version(capfd):
assert lasterr == errname + ': [Errno 2] No such file or directory', err

lines = out.split('\n')
assert lines[-3] == ('> virtualenv virtualenv_run --version'), out
assert lines[-4] == ('> virtualenv virtualenv_run --version'), out
assert lines[-2].startswith('> /'), out
assert lines[-2].endswith('/python venv_update.py --stage2 virtualenv_run requirements.txt --version')


def test_arguments_system_packages(tmpdir, capfd):
"""Show that we can pass arguments through to virtualenv"""
tmpdir.chdir()
get_scenario('trivial')

venv_update('--system-site-packages')
venv_update('--system-site-packages', 'virtualenv_run', 'requirements.txt')
out, err = capfd.readouterr() # flush buffers

run('virtualenv_run/bin/python', '-c', '''\
Expand Down
4 changes: 4 additions & 0 deletions tests/functional/stage2_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ def test_trivial(tmpdir):
tmpdir.chdir()
get_scenario('trivial')

with open('requirements.txt', 'w') as requirements:
# An arbitrary small package: mccabe
requirements.write('mccabe\nwsgiref==0.1')

run('virtualenv', 'myvenv')
# need this to get coverage. surely there's a better way...
run(
Expand Down
23 changes: 17 additions & 6 deletions venv_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,18 @@ def parseargs(args):
return stage, virtualenv_dir, tuple(requirements), tuple(remaining)


def timid_relpath(arg):
from os.path import exists, isabs, relpath
if isabs(arg) and exists(arg):
return relpath(arg)
else:
return arg


def shellescape(args):
# TODO: unit test
from pipes import quote
return ' '.join(quote(arg) for arg in args)
return ' '.join(quote(timid_relpath(arg)) for arg in args)


def colorize(cmd):
Expand Down Expand Up @@ -222,6 +230,13 @@ def mark_venv_invalid(venv_path, reqs):
print()


def dotpy(filename):
if filename.endswith('.pyc'):
return filename[:-1]
else:
return filename


def venv_update(stage, venv_path, reqs, venv_args):
from os.path import join, abspath
venv_python = abspath(join(venv_path, 'bin', 'python'))
Expand All @@ -230,11 +245,7 @@ def venv_update(stage, venv_path, reqs, venv_args):
# make a fresh venv at the right spot, and use it to perform stage 2
clean_venv(venv_path, venv_args)

from os import execv
execv(
venv_python,
(venv_python, __file__, '--stage2', venv_path) + reqs + venv_args
) # never returns
run((venv_python, dotpy(__file__), '--stage2', venv_path) + reqs + venv_args)
elif stage == 2:
import sys
assert sys.executable == venv_python, "Executable not in venv: %s != %s" % (sys.executable, venv_python)
Expand Down

0 comments on commit 3395033

Please sign in to comment.