Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: sjkingo/virtualenv-api
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 2.1.15
Choose a base ref
...
head repository: sjkingo/virtualenv-api
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Loading
Showing with 99 additions and 130 deletions.
  1. +4 −6 .travis.yml
  2. +1 −0 AUTHORS
  3. +18 −0 CHANGES.md
  4. +2 −2 README.rst
  5. +3 −6 setup.py
  6. +47 −95 tests.py
  7. +1 −1 virtualenvapi/__init__.py
  8. +23 −20 virtualenvapi/manage.py
10 changes: 4 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
language: python
python:
- "2.7"
- "3.3"
- "3.4"
- "3.5"
- "3.6"
- "3.7"
- "3.8"
install:
- pip install --upgrade pip
- pip install -q six
- pip install virtualenv
- pip install -U pip six virtualenv
- pip freeze
script: python tests.py
branches:
only:
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
@@ -11,3 +11,4 @@
* Eoghan Cunneen / eoghancunneen - https://github.com/eoghancunneen
* Dave Evans / evansde77 - https://github.com/evansde77
* Jeremy Zafran / jzafran - https://github.com/jzafran
* Irvin Lim / irvinlim - https://github.com/irvinlim
18 changes: 18 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
# Changes

## 2.1.18 - 2020-02-03

* #46: Blacklist env var in subprocess calls to fix bug in MacOS/Homebrew installs (@irvinlim)
* Change build versions to match supported Python versions (@sjkingo)

## 2.1.17 - 2018-11-15

* #40: Fix for test cases failing (@irvinlim)
* #39: Fix for `is_installed` not handling capitilized names properly (@irvinlim)
* Support Python 3.7 (@sjkingo)

## 2.1.16 - 2017-03-17

* Fix bug in test script where temporary directories were not being removed (@sjkingo)
* #35: Don't pass unsupported argument to old versions of pip (@sjkingo)
* Always call pip through the Python interpreter to avoid a too-long shebang error (@sjkingo)
* #26: Fix incorrect subclassing of base test class that was causing extreme test durations (@sjkingo)

## 2.1.15 - 2017-03-17

* #34: Add support for `pip -r` requirements files (@jzafran and @sjkingo)
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ the form of a wrapper around virtualenv.
It can be used to create and delete environments and perform package management
inside the environment.

Full support is provided for Python 2.7 and Python 3.3+.
Full support is provided for all supported versions of Python.

.. _virtualenv: http://www.virtualenv.org/
.. |Build Status| image:: https://travis-ci.org/sjkingo/virtualenv-api.svg
@@ -177,6 +177,6 @@ pip’s package syntax (e.g. ``django==1.4``) or as a tuple of ``('name',
>>> list(env.search('requests').items())
[('virtualenv-api', 'An API for virtualenv/pip')]
Verbose output from each command is available in the environments
Verbose output from each command is available in the environment's
``build.log`` file, which is appended to with each operation. Any errors are
logged to ``build.err``.
9 changes: 3 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
@@ -11,9 +11,7 @@
description='An API for virtualenv/pip',
long_description=open('README.rst', 'r').read(),
url='https://github.com/sjkingo/virtualenv-api',
install_requires=['six',
'virtualenv'
],
install_requires=['six'],
packages=find_packages(),
classifiers=[
'Development Status :: 5 - Production/Stable',
@@ -24,10 +22,9 @@
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Topic :: Software Development :: Libraries :: Python Modules',
],
)
142 changes: 47 additions & 95 deletions tests.py
Original file line number Diff line number Diff line change
@@ -2,20 +2,17 @@
import random
import shutil
import string
import sys
import tempfile
from unittest import TestCase
import unittest
import sys
import six
from virtualenvapi.manage import VirtualEnvironment

from virtualenvapi.manage import VirtualEnvironment

packages_for_pre_install = ['pep8', 'wheel']
packages_for_tests = ['flask', 'git+git://github.com/sjkingo/django_auth_ldap3.git']

packages_for_tests = ['pep8']
non_lowercase_packages_for_test = ['Pillow']
all_packages_for_tests = packages_for_tests + non_lowercase_packages_for_test

def which(program):

def is_exe(fpath):
return os.path.isfile(fpath) and os.access(fpath, os.X_OK)

@@ -30,27 +27,24 @@ def is_exe(fpath):
exe_file = os.path.join(path, program)
if is_exe(exe_file):
return exe_file

return None


class BaseTest(TestCase):
class TestBase(unittest.TestCase):
"""
Base class for test cases to inherit from.
"""

env_path = None

def setUp(self):
self.env_path = self.setup_env()
self.env_path = tempfile.mkdtemp()
self.virtual_env_obj = VirtualEnvironment(self.env_path)

def setup_env(self):
env_path = self.env_path
if env_path is None:
env_path = tempfile.mkdtemp('test_env')
virt_env = VirtualEnvironment(env_path)
virt_env._create()
for pack in packages_for_pre_install:
virt_env.install(pack)

return env_path
def tearDown(self):
if os.path.exists(self.env_path):
shutil.rmtree(self.env_path)

def _install_packages(self, packages):
for pack in packages:
@@ -60,20 +54,22 @@ def _uninstall_packages(self, packages):
for pack in packages:
self.virtual_env_obj.uninstall(pack)


class InstalledTestCase(TestBase):
"""
Test install/uninstall operations.
"""

def test_installed(self):
for pack in packages_for_pre_install:
self.assertTrue(self.virtual_env_obj.is_installed(pack))
self.assertFalse(self.virtual_env_obj.is_installed(''.join(random.sample(string.ascii_letters, 30))))

def test_install(self):
self._uninstall_packages(packages_for_tests)
for pack in packages_for_tests:
for pack in all_packages_for_tests:
self.virtual_env_obj.install(pack)
self.assertTrue(self.virtual_env_obj.is_installed(pack))

def test_install_requirements(self):
"""test installing Python packages from a pip requirements file"""
self._uninstall_packages(packages_for_tests)

# create a temporary requirements.txt file with some packages
with tempfile.NamedTemporaryFile('w') as tmp_requirements_file:
@@ -85,42 +81,48 @@ def test_install_requirements(self):
self.assertTrue(self.virtual_env_obj.is_installed(pack))

def test_uninstall(self):
self._install_packages(packages_for_tests)
for pack in packages_for_tests:
self._install_packages(all_packages_for_tests)
for pack in all_packages_for_tests:
if pack.endswith('.git'):
pack = pack.split('/')[-1].replace('.git', '')
self.virtual_env_obj.uninstall(pack)
self.assertFalse(self.virtual_env_obj.is_installed(pack))

def test_wheel(self):
self.virtual_env_obj.install('wheel') # required for this test
for pack in packages_for_tests:
self.virtual_env_obj.wheel(pack, options=['--wheel-dir=/tmp/wheelhouse'])
self.virtual_env_obj.install(pack, options=['--no-index', '--find-links=/tmp/wheelhouse', '--use-wheel'])
self.virtual_env_obj.install(pack, options=['--no-index', '--find-links=/tmp/wheelhouse'])
self.assertTrue(self.virtual_env_obj.is_installed(pack))


class SearchTestCase(TestBase):
"""
Test pip search.
"""

def test_search(self):
pack = packages_for_tests[0].lower()
result = self.virtual_env_obj.search(pack)
self.assertIsInstance(result, dict)
self.assertTrue(bool(result))
if result:
self.assertIn(pack, [k.split(' (')[0].lower() for k in result.keys()])
for pack in all_packages_for_tests:
result = self.virtual_env_obj.search(pack)
self.assertIsInstance(result, dict)
self.assertTrue(bool(result))
if result:
self.assertIn(pack.lower(), [k.split(' (')[0].lower() for k in result.keys()])

def test_search_names(self):
pack = packages_for_tests[0].lower()
result = self.virtual_env_obj.search_names(pack)
self.assertIsInstance(result, list)
self.assertIn(pack, [k.split(' (')[0].lower() for k in result])

def tearDown(self):
if os.path.exists(self.env_path) and self.__class__.env_path is None:
shutil.rmtree(self.env_path)
for pack in all_packages_for_tests:
result = self.virtual_env_obj.search_names(pack)
self.assertIsInstance(result, list)
self.assertIn(pack.lower(), [k.split(' (')[0].lower() for k in result])


class Python3TestCase(BaseTest):
class PythonArgumentTestCase(TestBase):
"""
Test passing a different interpreter path to `VirtualEnvironment` (`virtualenv -p`).
"""

def setUp(self):
self.env_path = self.setup_env()
self.env_path = tempfile.mkdtemp()
self.python = which('python')
self.assertIsNotNone(self.python)
self.virtual_env_obj = VirtualEnvironment(self.env_path, python=self.python)
@@ -133,51 +135,7 @@ def test_python_version(self):
)


class LongPathTestCase(BaseTest):

def setUp(self):
self.env_path = self.setup_env()
self.virtual_env_obj = VirtualEnvironment(self.env_path)

def setup_env(self):
env_path = self.env_path
if env_path is None:
# See: https://github.com/pypa/pip/issues/1773 This test may not be 100% accurate, tips on improving?
# Windows and OSX have their own limits so this may not work 100% of the time
long_path = "".join([random.choice(string.digits) for _ in range(0, 129)])
env_path = tempfile.mkdtemp('test_long_env-'+long_path)
virt_env = VirtualEnvironment(env_path)
virt_env._create()
for pack in packages_for_pre_install:
virt_env.install(pack)

return env_path

def test_pip_error(self):
self.assertRaises(OSError, self.virtual_env_obj._execute_pip, ['-V'], raw_pip=True)
try:
self.virtual_env_obj._execute_pip(['-V'])
except OSError:
self.fail("_execute_pip raised OSError unexpectedly")


class EnvironmentTest(BaseTest):

def setup_env(self):
act_filename = 'activate_this.py'
env_path = super(EnvironmentTest, self).setup_env()
act_path = os.path.join(env_path, 'bin', act_filename)
if six.PY2:
execfile(act_path, dict(__file__=act_path))
elif six.PY3:
with open(act_path, "r") as fh:
exec(fh.read())
else:
raise EnvironmentError('Unknown version of python')
return env_path


class SystemSitePackagesTest(TestCase):
class SystemSitePackagesTest(unittest.TestCase):
"""
test coverage for using system-site-packages flag
@@ -232,10 +190,4 @@ def test_no_system_site_packages(self):


if __name__ == '__main__':
# ToDo refactoring
if len(sys.argv) == 2 and sys.argv[1].startswith('--env='):
env_path = sys.argv[1].split('=', 1)[-1]
BaseTest.env_path = env_path
sys.argv = sys.argv[:1]

unittest.main()
2 changes: 1 addition & 1 deletion virtualenvapi/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '2.1.15'
__version__ = '2.1.18'
Loading