|
19 | 19 | from test.support.os_helper import (can_symlink, EnvironmentVarGuard, rmtree)
|
20 | 20 | import unittest
|
21 | 21 | import venv
|
22 |
| -from unittest.mock import patch |
| 22 | +from unittest.mock import patch, Mock |
23 | 23 |
|
24 | 24 | try:
|
25 | 25 | import ctypes
|
@@ -114,13 +114,49 @@ def test_defaults(self):
|
114 | 114 | executable = sys._base_executable
|
115 | 115 | path = os.path.dirname(executable)
|
116 | 116 | self.assertIn('home = %s' % path, data)
|
| 117 | + self.assertIn('executable = %s' % |
| 118 | + os.path.realpath(sys.executable), data) |
| 119 | + copies = '' if os.name=='nt' else ' --copies' |
| 120 | + cmd = f'command = {sys.executable} -m venv{copies} --without-pip {self.env_dir}' |
| 121 | + self.assertIn(cmd, data) |
117 | 122 | fn = self.get_env_file(self.bindir, self.exe)
|
118 | 123 | if not os.path.exists(fn): # diagnostics for Windows buildbot failures
|
119 | 124 | bd = self.get_env_file(self.bindir)
|
120 | 125 | print('Contents of %r:' % bd)
|
121 | 126 | print(' %r' % os.listdir(bd))
|
122 | 127 | self.assertTrue(os.path.exists(fn), 'File %r should exist.' % fn)
|
123 | 128 |
|
| 129 | + def test_config_file_command_key(self): |
| 130 | + attrs = [ |
| 131 | + (None, None), |
| 132 | + ('symlinks', '--copies'), |
| 133 | + ('with_pip', '--without-pip'), |
| 134 | + ('system_site_packages', '--system-site-packages'), |
| 135 | + ('clear', '--clear'), |
| 136 | + ('upgrade', '--upgrade'), |
| 137 | + ('upgrade_deps', '--upgrade-deps'), |
| 138 | + ('prompt', '--prompt'), |
| 139 | + ] |
| 140 | + for attr, opt in attrs: |
| 141 | + rmtree(self.env_dir) |
| 142 | + if not attr: |
| 143 | + b = venv.EnvBuilder() |
| 144 | + else: |
| 145 | + b = venv.EnvBuilder( |
| 146 | + **{attr: False if attr in ('with_pip', 'symlinks') else True}) |
| 147 | + b.upgrade_dependencies = Mock() # avoid pip command to upgrade deps |
| 148 | + b._setup_pip = Mock() # avoid pip setup |
| 149 | + self.run_with_capture(b.create, self.env_dir) |
| 150 | + data = self.get_text_file_contents('pyvenv.cfg') |
| 151 | + if not attr: |
| 152 | + for opt in ('--system-site-packages', '--clear', '--upgrade', |
| 153 | + '--upgrade-deps', '--prompt'): |
| 154 | + self.assertNotRegex(data, rf'command = .* {opt}') |
| 155 | + elif os.name=='nt' and attr=='symlinks': |
| 156 | + pass |
| 157 | + else: |
| 158 | + self.assertRegex(data, rf'command = .* {opt}') |
| 159 | + |
124 | 160 | def test_prompt(self):
|
125 | 161 | env_name = os.path.split(self.env_dir)[1]
|
126 | 162 |
|
|
0 commit comments