Merge pull request #283 from Czaki/test_virtualenv2
change 02_test to check if virtualenv is properly used another version
This commit is contained in:
@@ -145,6 +145,8 @@ def build(project_dir, output_dir, test_command, test_requires, test_extras, bef
|
|||||||
venv_dir=`mktemp -d`/venv
|
venv_dir=`mktemp -d`/venv
|
||||||
python -m virtualenv "$venv_dir"
|
python -m virtualenv "$venv_dir"
|
||||||
|
|
||||||
|
export __CIBW_VIRTUALENV_PATH__=$venv_dir
|
||||||
|
|
||||||
# run the tests in a subshell to keep that `activate`
|
# run the tests in a subshell to keep that `activate`
|
||||||
# script from polluting the env
|
# script from polluting the env
|
||||||
(
|
(
|
||||||
|
|||||||
@@ -209,6 +209,7 @@ def build(project_dir, output_dir, test_command, test_requires, test_extras, bef
|
|||||||
os.path.join(venv_dir, 'bin'),
|
os.path.join(venv_dir, 'bin'),
|
||||||
virtualenv_env['PATH'],
|
virtualenv_env['PATH'],
|
||||||
])
|
])
|
||||||
|
virtualenv_env["__CIBW_VIRTUALENV_PATH__"] = venv_dir
|
||||||
|
|
||||||
# check that we are using the Python from the virtual environment
|
# check that we are using the Python from the virtual environment
|
||||||
call(['which', 'python'], env=virtualenv_env)
|
call(['which', 'python'], env=virtualenv_env)
|
||||||
|
|||||||
@@ -179,10 +179,16 @@ def build(project_dir, output_dir, test_command, test_requires, test_extras, bef
|
|||||||
shell(['python', '-m', 'virtualenv', venv_dir], env=env)
|
shell(['python', '-m', 'virtualenv', venv_dir], env=env)
|
||||||
|
|
||||||
virtualenv_env = env.copy()
|
virtualenv_env = env.copy()
|
||||||
|
|
||||||
|
venv_script_path = os.path.join(venv_dir, 'Scripts')
|
||||||
|
if os.path.exists(os.path.join(venv_dir, 'bin')):
|
||||||
|
# pypy2.7 bugfix
|
||||||
|
venv_script_path = os.pathsep.join([venv_script_path, os.path.join(venv_dir, 'bin')])
|
||||||
virtualenv_env['PATH'] = os.pathsep.join([
|
virtualenv_env['PATH'] = os.pathsep.join([
|
||||||
os.path.join(venv_dir, 'Scripts'),
|
venv_script_path,
|
||||||
virtualenv_env['PATH'],
|
virtualenv_env['PATH'],
|
||||||
])
|
])
|
||||||
|
virtualenv_env["__CIBW_VIRTUALENV_PATH__"] = venv_dir
|
||||||
|
|
||||||
# check that we are using the Python from the virtual environment
|
# check that we are using the Python from the virtual environment
|
||||||
shell(['which', 'python'], env=virtualenv_env)
|
shell(['which', 'python'], env=virtualenv_env)
|
||||||
|
|||||||
@@ -1,9 +1,45 @@
|
|||||||
|
from __future__ import print_function
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
|
|
||||||
import spam
|
import spam
|
||||||
|
|
||||||
|
|
||||||
|
def path_contains(parent, child):
|
||||||
|
''' returns True if `child` is inside `parent`.
|
||||||
|
|
||||||
|
Works around path-comparison bugs caused by short-paths on Windows e.g.
|
||||||
|
vssadm~1 instead of vssadministrator
|
||||||
|
'''
|
||||||
|
parent = os.path.abspath(parent)
|
||||||
|
child = os.path.abspath(child)
|
||||||
|
|
||||||
|
while child != os.path.dirname(child):
|
||||||
|
child = os.path.dirname(child)
|
||||||
|
if os.stat(parent) == os.stat(child):
|
||||||
|
# parent and child refer to the same directory on the filesystem
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
class TestSpam(TestCase):
|
class TestSpam(TestCase):
|
||||||
def test_system(self):
|
def test_system(self):
|
||||||
self.assertEqual(0, spam.system('python -c "exit(0)"'))
|
self.assertEqual(0, spam.system('python -c "exit(0)"'))
|
||||||
self.assertNotEqual(0, spam.system('python -c "exit(1)"'))
|
self.assertNotEqual(0, spam.system('python -c "exit(1)"'))
|
||||||
|
|
||||||
|
def test_virtualenv(self):
|
||||||
|
virtualenv_path = os.environ.get("__CIBW_VIRTUALENV_PATH__")
|
||||||
|
if not virtualenv_path:
|
||||||
|
self.fail("No virtualenv path defined in environment variable __CIBW_VIRTUALENV_PATH__")
|
||||||
|
|
||||||
|
print("=[executable]", sys.executable)
|
||||||
|
print("=[spam location]", spam.__file__)
|
||||||
|
print("=[virtualenv path]", virtualenv_path)
|
||||||
|
print("=[listdir]", os.listdir(virtualenv_path))
|
||||||
|
if os.path.exists(os.path.join(virtualenv_path, 'Scripts')):
|
||||||
|
print("=[listdir]2", os.listdir(os.path.join(virtualenv_path, 'Scripts')))
|
||||||
|
if os.path.exists(os.path.join(virtualenv_path, 'bin')):
|
||||||
|
print("=[listdir]2", os.listdir(os.path.join(virtualenv_path, 'bin')))
|
||||||
|
self.assertTrue(path_contains(virtualenv_path, sys.executable))
|
||||||
|
self.assertTrue(path_contains(virtualenv_path, spam.__file__))
|
||||||
|
|||||||
Reference in New Issue
Block a user