def test_get_virtualenv_path_non_existent(self):
     with TemporaryDirectory(), TemporaryDirectory(
             change_directory=False) as virtualenv_dir:
         with TemporaryEnvironment(VENV_DIR=virtualenv_dir.path):
             venv, matching = get_virtualenv_path('2.7')
             self.assertIsNone(venv)
             self.assertIsNone(matching)
 def test_check_input_path_without_version(self):
     with TemporaryDirectory() as t, TemporaryDirectory(
             change_directory=False) as virtualenv_dir:
         with TemporaryEnvironment(VENV_DIR=virtualenv_dir.path):
             os.mkdir('.venv')
             env_path = check_input_path('.venv', '2.7')
             self.assertEqual(os.path.join(t.path, '.venv'), env_path)
 def test_check_input_path_with_version_none_virtualenv_dir(self):
     with TemporaryDirectory(), TemporaryDirectory(
             change_directory=False) as virtualenv_dir:
         with TemporaryEnvironment(VENV_DIR=virtualenv_dir.path):
             os.mkdir(os.path.join(virtualenv_dir.path, 'test-2.7'))
             env_path = check_input_path('test', '3.6')
             self.assertIsNone(env_path)
 def test_get_virtualenv_path_existent(self):
     with TemporaryDirectory() as t, TemporaryDirectory(
             change_directory=False) as virtualenv_dir:
         with TemporaryEnvironment(VENV_DIR=virtualenv_dir.path):
             os.mkdir(os.path.join(t.path, 'test_path'))
             env_path, matched_path = get_virtualenv_path(
                 '2.7', os.path.join(t.path, 'test_path'))
             self.assertEqual(os.path.join(t.path, 'test_path'), env_path)
             self.assertIsNone(matched_path)
 def test_check_input_path_none(self):
     # Max depth = 2
     with TemporaryDirectory(), TemporaryDirectory(
             change_directory=False) as virtualenv_dir:
         with TemporaryEnvironment(VENV_DIR=virtualenv_dir.path):
             env_path = check_input_path(None, 2)
             self.assertIsNone(env_path)
             env_path = check_input_path('3.6', 2)
             self.assertIsNone(env_path)
 def test_find_venv_dir_env_none(self):
     with TemporaryDirectory(), TemporaryDirectory(
             change_directory=False) as virtualenv_dir:
         with TemporaryEnvironment(VENV_DIR=virtualenv_dir.path):
             os.mkdir(os.path.join(virtualenv_dir.path, 'abc-2.7'))
             os.makedirs(os.path.join('ghi', 'def'))
             os.chdir(os.path.join('ghi', 'def'))
             path, matching = find_venv_dir_env('2.7', os.getcwd())
             self.assertIsNone(path)
             self.assertIsNone(matching)
 def test_find_recursive_path_venv(self):
     with TemporaryDirectory() as t, TemporaryDirectory(
             change_directory=False) as virtualenv_dir:
         with TemporaryEnvironment(VENV_DIR=virtualenv_dir.path):
             os.mkdir(os.path.join(virtualenv_dir.path, 'abc-2.7'))
             os.makedirs(os.path.join('abc', 'def'))
             os.chdir(os.path.join('abc', 'def'))
             path, matching = find_recursive_path_venv('2.7')
             self.assertEqual(path,
                              os.path.join(virtualenv_dir.path, 'abc-2.7'))
             self.assertEqual(matching, os.path.join(t.path, 'abc'))
 def test_get_virtualenv_path_virtualenv_dir_version(self):
     with TemporaryDirectory() as t, TemporaryDirectory(
             change_directory=False) as virtualenv_dir:
         with TemporaryEnvironment(VENV_DIR=virtualenv_dir.path):
             os.mkdir(os.path.join(virtualenv_dir.path, 'test_path'))
             os.mkdir('test_path')
             os.chdir('test_path')
             env_path, matched_path = get_virtualenv_path('2.7')
             self.assertEqual(
                 os.path.join(virtualenv_dir.path, 'test_path'), env_path)
             self.assertEqual(os.path.join(t.path, 'test_path'),
                              matched_path)
 def test_find_local_env_with_version(self):
     with TemporaryDirectory() as t:
         os.makedirs(os.path.join('abc', '.venv-2.7'))
         os.chdir('abc')
         path, matching = find_local_env('2.7')
         self.assertEqual(path, os.path.join(t.path, 'abc', '.venv-2.7'))
         self.assertEqual(matching, os.path.join(t.path, 'abc'))
 def test_find_local_env_none(self):
     with TemporaryDirectory():
         os.makedirs(os.path.join('abc', 'def'))
         os.chdir(os.path.join('abc', 'def'))
         path, matching = find_local_env('2.7')
         self.assertIsNone(path)
         self.assertIsNone(matching)
 def test_activate_fail(self):
     # This needs a virtual environment setup to install from
     with Quiet(), TemporaryEnvironment(), TemporaryDirectory(
             change_directory=False) as virtualenv_dir:
         os.environ['VIRTUALENV_DIR'] = virtualenv_dir.path
         old_path = sys.path
         activate()
         self.assertEqual(old_path, sys.path)
 def test_find_virtualenv_recursive_path_local_dir(self):
     with TemporaryDirectory() as t:
         os.makedirs(os.path.join('abc', 'def'))
         os.makedirs(os.path.join('abc', '.venv'))
         os.chdir(os.path.join('abc', 'def'))
         path, matching = find_virtualenv('2.7')
         self.assertEqual(path, os.path.join(t.path, 'abc', '.venv'))
         self.assertEqual(matching, os.path.join(t.path, 'abc'))
Exemple #13
0
 def test_create(self):
     with TemporaryDirectory() as virtualenv_dir, Quiet():
         with TemporaryEnvironment(VENV_DIR=virtualenv_dir.path):
             current_version = '{}.{}'.format(sys.version_info.major,
                                              sys.version_info.minor)
             create(['test_virtual_env'])
             self.assertTrue(
                 os.path.exists(
                     os.path.join(
                         virtualenv_dir.path,
                         'test_virtual_env-{}'.format(current_version))))
    def test_recursive_check(self):

        with TemporaryDirectory() as t:
            os.makedirs('abc/def/ghi')
            os.chdir('abc/def/ghi')

            def check_function(version, current_directory):
                match = current_directory == os.path.join(t.path, 'abc', 'def')
                if match:
                    return match, 'abcdefghi'
                else:
                    return None, None

            venv_path, matching_path = recursive_check(check_function, '2.3',
                                                       None)
            self.assertTrue(venv_path)
            self.assertEqual(matching_path, 'abcdefghi')
Exemple #15
0
 def test_install_default_wheels(self):
     if sys.platform.startswith('win32'):
         lib_path = ('Lib', 'site-packages')
     else:
         lib_path = ('lib', 'python*', 'site-packages')
     wheel_dir = pkg_resources.resource_filename(
         'virtualenv_helpers.tests.functional', 'test_wheels')
     with TemporaryEnvironment(VENV_DEFAULT_WHEELS_DIR=wheel_dir
                               ), TemporaryDirectory() as t, Quiet():
         current_version = '{}.{}'.format(sys.version_info.major,
                                          sys.version_info.minor)
         virtualenv.create_environment(t.path)
         self.assertFalse(
             len(
                 glob.glob(
                     os.path.join(os.path.join(t.path, *lib_path),
                                  'test_package'))))
         install_default_wheels(current_version, t.path)
         self.assertTrue(
             len(
                 glob.glob(
                     os.path.join(os.path.join(t.path, *lib_path),
                                  'test_package*'))))
 def test_activate_ok(self):
     # This needs a virtual environment setup to install from
     # This also creates a shell, so requires user input
     with TemporaryDirectory() as t, Quiet(), TemporaryEnvironment():
         virtualenv.create_environment(t.path)
         activate(['--path', t.path])
 def test_check_input_path_with_version(self):
     with TemporaryDirectory() as t:
         os.mkdir('.venv-2.7')
         env_path = check_input_path('.venv', '2.7')
         self.assertEqual(os.path.join(t.path, '.venv-2.7'), env_path)