|
|
c9614cd |
diff --git a/LICENSE b/LICENSE
|
|
|
c9614cd |
new file mode 100644
|
|
|
c9614cd |
index 0000000..4c9bdaf
|
|
|
c9614cd |
--- /dev/null
|
|
|
c9614cd |
+++ b/LICENSE
|
|
|
c9614cd |
@@ -0,0 +1,22 @@
|
|
|
c9614cd |
+Copyright (c) 2013-2015 Sam Kingston <sam@sjkwi.com.au> and AUTHORS.
|
|
|
c9614cd |
+All rights reserved.
|
|
|
c9614cd |
+
|
|
|
c9614cd |
+Redistribution and use in source and binary forms, with or without
|
|
|
c9614cd |
+modification, are permitted provided that the following conditions are met:
|
|
|
c9614cd |
+
|
|
|
c9614cd |
+1. Redistributions of source code must retain the above copyright notice, this
|
|
|
c9614cd |
+ list of conditions and the following disclaimer.
|
|
|
c9614cd |
+2. Redistributions in binary form must reproduce the above copyright notice,
|
|
|
c9614cd |
+ this list of conditions and the following disclaimer in the documentation
|
|
|
c9614cd |
+ and/or other materials provided with the distribution.
|
|
|
c9614cd |
+
|
|
|
c9614cd |
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
|
c9614cd |
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
c9614cd |
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
c9614cd |
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
|
|
c9614cd |
+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
c9614cd |
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
|
c9614cd |
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
|
c9614cd |
+ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
c9614cd |
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
c9614cd |
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
c9614cd |
diff --git a/tests.py b/tests.py
|
|
|
c9614cd |
new file mode 100644
|
|
|
c9614cd |
index 0000000..add5c06
|
|
|
c9614cd |
--- /dev/null
|
|
|
c9614cd |
+++ b/tests.py
|
|
|
c9614cd |
@@ -0,0 +1,146 @@
|
|
|
c9614cd |
+import os
|
|
|
c9614cd |
+import random
|
|
|
c9614cd |
+import shutil
|
|
|
c9614cd |
+import string
|
|
|
c9614cd |
+import tempfile
|
|
|
c9614cd |
+from unittest import TestCase
|
|
|
c9614cd |
+import unittest
|
|
|
c9614cd |
+import sys
|
|
|
c9614cd |
+import six
|
|
|
c9614cd |
+from virtualenvapi.manage import VirtualEnvironment
|
|
|
c9614cd |
+
|
|
|
c9614cd |
+
|
|
|
c9614cd |
+packages_for_pre_install = ['pep8', 'wheel']
|
|
|
c9614cd |
+packages_for_tests = ['flask', 'git+git://github.com/sjkingo/django_auth_ldap3.git']
|
|
|
c9614cd |
+
|
|
|
c9614cd |
+
|
|
|
c9614cd |
+def which(program):
|
|
|
c9614cd |
+
|
|
|
c9614cd |
+ def is_exe(fpath):
|
|
|
c9614cd |
+ return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
|
|
|
c9614cd |
+
|
|
|
c9614cd |
+ fpath, fname = os.path.split(program)
|
|
|
c9614cd |
+
|
|
|
c9614cd |
+ if fpath:
|
|
|
c9614cd |
+ if is_exe(program):
|
|
|
c9614cd |
+ return program
|
|
|
c9614cd |
+ else:
|
|
|
c9614cd |
+ for path in os.environ["PATH"].split(os.pathsep):
|
|
|
c9614cd |
+ path = path.strip('"')
|
|
|
c9614cd |
+ exe_file = os.path.join(path, program)
|
|
|
c9614cd |
+ if is_exe(exe_file):
|
|
|
c9614cd |
+ return exe_file
|
|
|
c9614cd |
+ return None
|
|
|
c9614cd |
+
|
|
|
c9614cd |
+
|
|
|
c9614cd |
+class BaseTest(TestCase):
|
|
|
c9614cd |
+
|
|
|
c9614cd |
+ env_path = None
|
|
|
c9614cd |
+
|
|
|
c9614cd |
+ def setUp(self):
|
|
|
c9614cd |
+ self.env_path = self.setup_env()
|
|
|
c9614cd |
+ self.virtual_env_obj = VirtualEnvironment(self.env_path)
|
|
|
c9614cd |
+
|
|
|
c9614cd |
+ def setup_env(self):
|
|
|
c9614cd |
+ env_path = self.env_path
|
|
|
c9614cd |
+ if env_path is None:
|
|
|
c9614cd |
+ env_path = tempfile.mkdtemp('test_env')
|
|
|
c9614cd |
+ virt_env = VirtualEnvironment(env_path)
|
|
|
c9614cd |
+ virt_env._create()
|
|
|
c9614cd |
+ for pack in packages_for_pre_install:
|
|
|
c9614cd |
+ virt_env.install(pack)
|
|
|
c9614cd |
+
|
|
|
c9614cd |
+ return env_path
|
|
|
c9614cd |
+
|
|
|
c9614cd |
+ def _install_packages(self, packages):
|
|
|
c9614cd |
+ for pack in packages:
|
|
|
c9614cd |
+ self.virtual_env_obj.install(pack)
|
|
|
c9614cd |
+
|
|
|
c9614cd |
+ def _uninstall_packages(self, packages):
|
|
|
c9614cd |
+ for pack in packages:
|
|
|
c9614cd |
+ self.virtual_env_obj.uninstall(pack)
|
|
|
c9614cd |
+
|
|
|
c9614cd |
+ def test_installed(self):
|
|
|
c9614cd |
+ for pack in packages_for_pre_install:
|
|
|
c9614cd |
+ self.assertTrue(self.virtual_env_obj.is_installed(pack))
|
|
|
c9614cd |
+ self.assertFalse(self.virtual_env_obj.is_installed(''.join(random.sample(string.ascii_letters, 30))))
|
|
|
c9614cd |
+
|
|
|
c9614cd |
+ def test_install(self):
|
|
|
c9614cd |
+ self._uninstall_packages(packages_for_tests)
|
|
|
c9614cd |
+ for pack in packages_for_tests:
|
|
|
c9614cd |
+ self.virtual_env_obj.install(pack)
|
|
|
c9614cd |
+ self.assertTrue(self.virtual_env_obj.is_installed(pack))
|
|
|
c9614cd |
+
|
|
|
c9614cd |
+ def test_uninstall(self):
|
|
|
c9614cd |
+ self._install_packages(packages_for_tests)
|
|
|
c9614cd |
+ for pack in packages_for_tests:
|
|
|
c9614cd |
+ if pack.endswith('.git'):
|
|
|
c9614cd |
+ pack = pack.split('/')[-1].replace('.git', '')
|
|
|
c9614cd |
+ self.virtual_env_obj.uninstall(pack)
|
|
|
c9614cd |
+ self.assertFalse(self.virtual_env_obj.is_installed(pack))
|
|
|
c9614cd |
+
|
|
|
c9614cd |
+ def test_wheel(self):
|
|
|
c9614cd |
+ for pack in packages_for_tests:
|
|
|
c9614cd |
+ self.virtual_env_obj.wheel(pack, options=['--wheel-dir=/tmp/wheelhouse'])
|
|
|
c9614cd |
+ self.virtual_env_obj.install(pack, options=['--no-index', '--find-links=/tmp/wheelhouse', '--use-wheel'])
|
|
|
c9614cd |
+ self.assertTrue(self.virtual_env_obj.is_installed(pack))
|
|
|
c9614cd |
+
|
|
|
c9614cd |
+ def test_search(self):
|
|
|
c9614cd |
+ pack = packages_for_tests[0].lower()
|
|
|
c9614cd |
+ result = self.virtual_env_obj.search(pack)
|
|
|
c9614cd |
+ self.assertIsInstance(result, dict)
|
|
|
c9614cd |
+ self.assertTrue(bool(result))
|
|
|
c9614cd |
+ if result:
|
|
|
c9614cd |
+ self.assertIn(pack, [k.split(' (')[0].lower() for k in result.keys()])
|
|
|
c9614cd |
+
|
|
|
c9614cd |
+ def test_search_names(self):
|
|
|
c9614cd |
+ pack = packages_for_tests[0].lower()
|
|
|
c9614cd |
+ result = self.virtual_env_obj.search_names(pack)
|
|
|
c9614cd |
+ self.assertIsInstance(result, list)
|
|
|
c9614cd |
+ self.assertIn(pack, [k.split(' (')[0].lower() for k in result])
|
|
|
c9614cd |
+
|
|
|
c9614cd |
+ def tearDown(self):
|
|
|
c9614cd |
+ if os.path.exists(self.env_path) and self.__class__.env_path is None:
|
|
|
c9614cd |
+ shutil.rmtree(self.env_path)
|
|
|
c9614cd |
+
|
|
|
c9614cd |
+
|
|
|
c9614cd |
+class Python3TestCase(BaseTest):
|
|
|
c9614cd |
+
|
|
|
c9614cd |
+ def setUp(self):
|
|
|
c9614cd |
+ self.env_path = self.setup_env()
|
|
|
c9614cd |
+ self.python = which('python')
|
|
|
c9614cd |
+ self.assertIsNotNone(self.python)
|
|
|
c9614cd |
+ self.virtual_env_obj = VirtualEnvironment(self.env_path, python=self.python)
|
|
|
c9614cd |
+
|
|
|
c9614cd |
+ def test_python_version(self):
|
|
|
c9614cd |
+ self.assertEqual(self.virtual_env_obj.python, self.python)
|
|
|
c9614cd |
+ self.assertEqual(
|
|
|
c9614cd |
+ os.path.dirname(self.python),
|
|
|
c9614cd |
+ os.path.dirname(which('pip'))
|
|
|
c9614cd |
+ )
|
|
|
c9614cd |
+
|
|
|
c9614cd |
+
|
|
|
c9614cd |
+class EnvironmentTest(BaseTest):
|
|
|
c9614cd |
+
|
|
|
c9614cd |
+ def setup_env(self):
|
|
|
c9614cd |
+ act_filename = 'activate_this.py'
|
|
|
c9614cd |
+ env_path = super(EnvironmentTest, self).setup_env()
|
|
|
c9614cd |
+ act_path = os.path.join(env_path, 'bin', act_filename)
|
|
|
c9614cd |
+ if six.PY2:
|
|
|
c9614cd |
+ execfile(act_path, dict(__file__=act_path))
|
|
|
c9614cd |
+ elif six.PY3:
|
|
|
c9614cd |
+ with open(act_path, "r") as fh:
|
|
|
c9614cd |
+ exec(fh.read())
|
|
|
c9614cd |
+ else:
|
|
|
c9614cd |
+ raise EnvironmentError('Unknown version of python')
|
|
|
c9614cd |
+ return env_path
|
|
|
c9614cd |
+
|
|
|
c9614cd |
+
|
|
|
c9614cd |
+if __name__ == '__main__':
|
|
|
c9614cd |
+ # ToDo refactoring
|
|
|
c9614cd |
+ if len(sys.argv) == 2 and sys.argv[1].startswith('--env='):
|
|
|
c9614cd |
+ env_path = sys.argv[1].split('=', 1)[-1]
|
|
|
c9614cd |
+ BaseTest.env_path = env_path
|
|
|
c9614cd |
+ sys.argv = sys.argv[:1]
|
|
|
c9614cd |
+
|
|
|
c9614cd |
+ unittest.main()
|