コード例 #1
0
 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)
コード例 #2
0
 def test_parse_options_defaults_no_editor(self):
     with TemporaryEnvironment():
         os.environ.pop('VENV_EDITOR', None)
         os.environ.pop('VENV_EDITOR_SHOW', None)
         options, version = parse_options([])
         self.assertIsNone(options.editor)
         self.assertFalse(options.show_editor)
コード例 #3
0
 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)
コード例 #4
0
 def test_parse_options_defaults_wrong_editor(self):
     with TemporaryEnvironment(
             VENV_EDITOR='random_fail_editor_xyzdadsdasffaf',
             VENV_EDITOR_SHOW='TRUE'):
         options, version = parse_options([])
         self.assertIsNone(options.editor)
         self.assertFalse(options.show_editor)
コード例 #5
0
 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)
コード例 #6
0
 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)
コード例 #7
0
 def test_get_shell_bash(self):
     if 'win' not in sys.platform:
         raise unittest.SkipTest('*nix based test')
     with TemporaryEnvironment(SHELL=os.path.join('bin', 'bash')):
         shell, args, script_name = get_shell()
         self.assertEqual(shell, os.path.join('bin', 'bash'))
         self.assertEqual(args, ['--init-file'])
         self.assertEqual(script_name, 'activate')
コード例 #8
0
 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)
コード例 #9
0
 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)
コード例 #10
0
 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)
コード例 #11
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))))
コード例 #12
0
 def test_parse_options_defaults_editor_no_show(self):
     with TemporaryEnvironment(VENV_EDITOR='sublimetext3',
                               VENV_EDITOR_SHOW='False'):
         options, version = parse_options([])
         self.assertIsNone(options.virtualenv_path)
         self.assertIsNone(options.python_version)
         current_version = '{}.{}'.format(sys.version_info.major,
                                          sys.version_info.minor)
         self.assertEqual(version, current_version)
         self.assertTrue(options.editor is not None)
         self.assertTrue(options.show_editor)
コード例 #13
0
 def test_parse_options_directory(self):
     with TemporaryEnvironment(VENV_DIR='abc'):
         options, unknown = parse_options([])
         self.assertIsNone(options.name)
         self.assertEqual(options.virtualenv_dir, 'abc')
     options, unknown = parse_options(['-d', 'def'])
     self.assertIsNone(options.name)
     self.assertEqual(options.virtualenv_dir, 'def')
     options, unknown = parse_options(['--directory', 'ghi'])
     self.assertIsNone(options.name)
     self.assertEqual(options.virtualenv_dir, 'ghi')
コード例 #14
0
 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'))
コード例 #15
0
 def test_get_shell_cmd(self):
     if 'win32' not in sys.platform:
         raise unittest.SkipTest('Windows based test')
     with TemporaryEnvironment(PROMPT='True'):
         try:
             os.environ.pop('SHELL')
         except Exception:
             pass
         shell, args, script_name = get_shell()
         self.assertEqual(shell, 'cmd.exe')
         self.assertEqual(args, ['/K'])
         self.assertEqual(script_name, 'activate.bat')
コード例 #16
0
 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)
コード例 #17
0
 def test_get_shell_powershell(self):
     if 'win32' not in sys.platform:
         raise unittest.SkipTest('Windows based test')
     with TemporaryEnvironment():
         try:
             os.environ.pop('SHELL')
         except Exception:
             pass
         try:
             os.environ.pop('PROMPT')
         except Exception:
             pass
         shell, args, script_name = get_shell()
         self.assertEqual(shell, 'powershell.exe')
         self.assertEqual(args, ['-NoLogo', '-NoExit', '.'])
         self.assertEqual(script_name, 'activate.ps1')
コード例 #18
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*'))))
コード例 #19
0
 def test_get_virtualenv_dir_default(self):
     with TemporaryEnvironment():
         os.environ.pop('VENV_DIR')
         self.assertEqual(
             get_virtualenv_dir(),
             os.path.join(os.path.expanduser('~'), 'virtualenvs'))
コード例 #20
0
 def test_get_virtualenv_dir(self):
     with TemporaryEnvironment(VENV_DIR='abc'):
         self.assertEqual(get_virtualenv_dir(), 'abc')
コード例 #21
0
 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])