Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(37)

Side by Side Diff: bootstrap/virtualenv/tests/test_virtualenv.py

Issue 2043213002: Roll virtualenv 12.0->15.0.2 (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: vendor virtualenv and exclude from gender check Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « bootstrap/virtualenv/tests/test_cmdline.py ('k') | bootstrap/virtualenv/tox.ini » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 import virtualenv
2 import optparse
3 import os
4 import shutil
5 import sys
6 import tempfile
7 import pytest
8 import platform # noqa
9
10 from mock import patch, Mock
11
12
13 def test_version():
14 """Should have a version string"""
15 assert virtualenv.virtualenv_version, "Should have version"
16
17
18 @patch('os.path.exists')
19 def test_resolve_interpreter_with_absolute_path(mock_exists):
20 """Should return absolute path if given and exists"""
21 mock_exists.return_value = True
22 virtualenv.is_executable = Mock(return_value=True)
23 test_abs_path = os.path.abspath("/usr/bin/python53")
24
25 exe = virtualenv.resolve_interpreter(test_abs_path)
26
27 assert exe == test_abs_path, "Absolute path should return as is"
28 mock_exists.assert_called_with(test_abs_path)
29 virtualenv.is_executable.assert_called_with(test_abs_path)
30
31
32 @patch('os.path.exists')
33 def test_resolve_interpreter_with_nonexistent_interpreter(mock_exists):
34 """Should SystemExit with an nonexistent python interpreter path"""
35 mock_exists.return_value = False
36
37 with pytest.raises(SystemExit):
38 virtualenv.resolve_interpreter("/usr/bin/python53")
39
40 mock_exists.assert_called_with("/usr/bin/python53")
41
42
43 @patch('os.path.exists')
44 def test_resolve_interpreter_with_invalid_interpreter(mock_exists):
45 """Should exit when with absolute path if not exists"""
46 mock_exists.return_value = True
47 virtualenv.is_executable = Mock(return_value=False)
48 invalid = os.path.abspath("/usr/bin/pyt_hon53")
49
50 with pytest.raises(SystemExit):
51 virtualenv.resolve_interpreter(invalid)
52
53 mock_exists.assert_called_with(invalid)
54 virtualenv.is_executable.assert_called_with(invalid)
55
56
57 def test_activate_after_future_statements():
58 """Should insert activation line after last future statement"""
59 script = [
60 '#!/usr/bin/env python',
61 'from __future__ import with_statement',
62 'from __future__ import print_function',
63 'print("Hello, world!")'
64 ]
65 assert virtualenv.relative_script(script) == [
66 '#!/usr/bin/env python',
67 'from __future__ import with_statement',
68 'from __future__ import print_function',
69 '',
70 "import os; activate_this=os.path.join(os.path.dirname(os.path.realpath( __file__)), 'activate_this.py'); exec(compile(open(activate_this).read(), activa te_this, 'exec'), dict(__file__=activate_this)); del os, activate_this",
71 '',
72 'print("Hello, world!")'
73 ]
74
75
76 def test_cop_update_defaults_with_store_false():
77 """store_false options need reverted logic"""
78 class MyConfigOptionParser(virtualenv.ConfigOptionParser):
79 def __init__(self, *args, **kwargs):
80 self.config = virtualenv.ConfigParser.RawConfigParser()
81 self.files = []
82 optparse.OptionParser.__init__(self, *args, **kwargs)
83
84 def get_environ_vars(self, prefix='VIRTUALENV_'):
85 yield ("no_site_packages", "1")
86
87 cop = MyConfigOptionParser()
88 cop.add_option(
89 '--no-site-packages',
90 dest='system_site_packages',
91 action='store_false',
92 help="Don't give access to the global site-packages dir to the "
93 "virtual environment (default)")
94
95 defaults = {}
96 cop.update_defaults(defaults)
97 assert defaults == {'system_site_packages': 0}
98
99 def test_install_python_bin():
100 """Should create the right python executables and links"""
101 tmp_virtualenv = tempfile.mkdtemp()
102 try:
103 home_dir, lib_dir, inc_dir, bin_dir = \
104 virtualenv.path_locations(tmp_virtualenv)
105 virtualenv.install_python(home_dir, lib_dir, inc_dir, bin_dir, False,
106 False)
107
108 if virtualenv.is_win:
109 required_executables = [ 'python.exe', 'pythonw.exe']
110 else:
111 py_exe_no_version = 'python'
112 py_exe_version_major = 'python%s' % sys.version_info[0]
113 py_exe_version_major_minor = 'python%s.%s' % (
114 sys.version_info[0], sys.version_info[1])
115 required_executables = [ py_exe_no_version, py_exe_version_major,
116 py_exe_version_major_minor ]
117
118 for pth in required_executables:
119 assert os.path.exists(os.path.join(bin_dir, pth)), ("%s should "
120 "exist in bin_dir" % pth)
121 finally:
122 shutil.rmtree(tmp_virtualenv)
123
124
125 @pytest.mark.skipif("platform.python_implementation() == 'PyPy'")
126 def test_always_copy_option():
127 """Should be no symlinks in directory tree"""
128 tmp_virtualenv = tempfile.mkdtemp()
129 ve_path = os.path.join(tmp_virtualenv, 'venv')
130 try:
131 virtualenv.create_environment(ve_path, symlink=False)
132
133 for root, dirs, files in os.walk(tmp_virtualenv):
134 for f in files + dirs:
135 full_name = os.path.join(root, f)
136 assert not os.path.islink(full_name), "%s should not be a" \
137 " symlink (to %s)" % (full_name, os.readlink(full_name))
138 finally:
139 shutil.rmtree(tmp_virtualenv)
OLDNEW
« no previous file with comments | « bootstrap/virtualenv/tests/test_cmdline.py ('k') | bootstrap/virtualenv/tox.ini » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698