def test_on_windows_with_no_installations(self, monkeypatch): assert virtualenv.IS_WIN mock_winreg = self.mock_virtualenv_winreg(monkeypatch, {}) installed_pythons = virtualenv.get_installed_pythons() assert installed_pythons == {} assert mock_winreg.mock_calls == [ call.OpenKey(mock_winreg.HKEY_LOCAL_MACHINE, "Software\\Python\\PythonCore", 0, 0x11), call.EnumKey(self.key_local_machine, 0), call.CloseKey(self.key_local_machine), call.OpenKey(mock_winreg.HKEY_CURRENT_USER, "Software\\Python\\PythonCore", 0, 0x11), call.EnumKey(self.key_current_user, 0), call.CloseKey(self.key_current_user), call.OpenKey(mock_winreg.HKEY_LOCAL_MACHINE, "Software\\Python\\PythonCore", 0, 0x12), call.EnumKey(self.key_local_machine_64, 0), call.CloseKey(self.key_local_machine_64), call.OpenKey(mock_winreg.HKEY_CURRENT_USER, "Software\\Python\\PythonCore", 0, 0x12), call.EnumKey(self.key_current_user_64, 0), call.CloseKey(self.key_current_user_64), ]
def test_on_windows_with_no_installations(self, monkeypatch): assert virtualenv.is_win mock_winreg = self.mock_virtualenv_winreg(monkeypatch, {}) installed_pythons = virtualenv.get_installed_pythons() assert installed_pythons == {} assert mock_winreg.mock_calls == [ call.CreateKey(mock_winreg.HKEY_LOCAL_MACHINE, "Software\\Python\\PythonCore"), call.EnumKey(self.key_local_machine, 0), call.CloseKey(self.key_local_machine), call.CreateKey(mock_winreg.HKEY_CURRENT_USER, "Software\\Python\\PythonCore"), call.EnumKey(self.key_current_user, 0), call.CloseKey(self.key_current_user), ]
def test_on_windows(self, monkeypatch): assert virtualenv.is_win mock_winreg = self.mock_virtualenv_winreg( monkeypatch, { self.key_local_machine: ( "2.4", "2.7", "3.2", "3.4", "3.5", # 64-bit only "3.6-32", # 32-bit only "3.7", "3.7-32", # both 32 & 64-bit with a 64-bit user install "3.8", ), # 64-bit with a 32-bit user install self.key_current_user: ("2.5", "2.7", "3.7", "3.8-32"), }, ) monkeypatch.setattr(virtualenv, "join", "{}\\{}".format) installed_pythons = virtualenv.get_installed_pythons() assert installed_pythons == { "2": self.key_current_user + "-2.7-path\\python.exe", "2.4": self.key_local_machine + "-2.4-path\\python.exe", "2.5": self.key_current_user + "-2.5-path\\python.exe", "2.7": self.key_current_user + "-2.7-path\\python.exe", "3": self.key_local_machine + "-3.8-path\\python.exe", "3.2": self.key_local_machine + "-3.2-path\\python.exe", "3.4": self.key_local_machine + "-3.4-path\\python.exe", "3.5": self.key_local_machine + "-3.5-path\\python.exe", "3.5-64": self.key_local_machine + "-3.5-path\\python.exe", "3.6": self.key_local_machine + "-3.6-32-path\\python.exe", "3.6-32": self.key_local_machine + "-3.6-32-path\\python.exe", "3.7": self.key_current_user + "-3.7-path\\python.exe", "3.7-32": self.key_local_machine + "-3.7-32-path\\python.exe", "3.7-64": self.key_current_user + "-3.7-path\\python.exe", "3.8": self.key_local_machine + "-3.8-path\\python.exe", "3.8-32": self.key_current_user + "-3.8-32-path\\python.exe", "3.8-64": self.key_local_machine + "-3.8-path\\python.exe", } assert mock_winreg.mock_calls == [ call.CreateKey(mock_winreg.HKEY_LOCAL_MACHINE, "Software\\Python\\PythonCore"), call.EnumKey(self.key_local_machine, 0), call.QueryValue(self.key_local_machine, "2.4\\InstallPath"), call.EnumKey(self.key_local_machine, 1), call.QueryValue(self.key_local_machine, "2.7\\InstallPath"), call.EnumKey(self.key_local_machine, 2), call.QueryValue(self.key_local_machine, "3.2\\InstallPath"), call.EnumKey(self.key_local_machine, 3), call.QueryValue(self.key_local_machine, "3.4\\InstallPath"), call.EnumKey(self.key_local_machine, 4), call.QueryValue(self.key_local_machine, "3.5\\InstallPath"), call.EnumKey(self.key_local_machine, 5), call.QueryValue(self.key_local_machine, "3.6-32\\InstallPath"), call.EnumKey(self.key_local_machine, 6), call.QueryValue(self.key_local_machine, "3.7\\InstallPath"), call.EnumKey(self.key_local_machine, 7), call.QueryValue(self.key_local_machine, "3.7-32\\InstallPath"), call.EnumKey(self.key_local_machine, 8), call.QueryValue(self.key_local_machine, "3.8\\InstallPath"), call.EnumKey(self.key_local_machine, 9), call.CloseKey(self.key_local_machine), call.CreateKey(mock_winreg.HKEY_CURRENT_USER, "Software\\Python\\PythonCore"), call.EnumKey(self.key_current_user, 0), call.QueryValue(self.key_current_user, "2.5\\InstallPath"), call.EnumKey(self.key_current_user, 1), call.QueryValue(self.key_current_user, "2.7\\InstallPath"), call.EnumKey(self.key_current_user, 2), call.QueryValue(self.key_current_user, "3.7\\InstallPath"), call.EnumKey(self.key_current_user, 3), call.QueryValue(self.key_current_user, "3.8-32\\InstallPath"), call.EnumKey(self.key_current_user, 4), call.CloseKey(self.key_current_user), ]
def test_on_non_windows(self, monkeypatch): assert not virtualenv.is_win assert not hasattr(virtualenv, "winreg") assert virtualenv.get_installed_pythons() == {}
def test_on_windows(self, monkeypatch): assert virtualenv.IS_WIN mock_winreg = self.mock_virtualenv_winreg( monkeypatch, { self.key_local_machine: ( "2.4", "2.7", "3.2", "3.4", "3.6-32", # 32-bit only "3.7-32", # both 32 & 64-bit with a 64-bit user install ), self.key_current_user: ("2.5", "2.7", "3.8-32"), self.key_local_machine_64: ( "2.6", "3.5", # 64-bit only "3.7", "3.8", # 64-bit with a 32-bit user install ), self.key_current_user_64: ("3.7",), }, ) monkeypatch.setattr(virtualenv, "join", "{}\\{}".format) installed_pythons = virtualenv.get_installed_pythons() assert installed_pythons == { "2": self.key_current_user + "-2.7-path\\python.exe", "2-32": self.key_current_user + "-2.7-path\\python.exe", "2-64": self.key_local_machine_64 + "-2.6-path\\python.exe", "2.4": self.key_local_machine + "-2.4-path\\python.exe", "2.4-32": self.key_local_machine + "-2.4-path\\python.exe", "2.5": self.key_current_user + "-2.5-path\\python.exe", "2.5-32": self.key_current_user + "-2.5-path\\python.exe", "2.6": self.key_local_machine_64 + "-2.6-path\\python.exe", "2.6-64": self.key_local_machine_64 + "-2.6-path\\python.exe", "2.7": self.key_current_user + "-2.7-path\\python.exe", "2.7-32": self.key_current_user + "-2.7-path\\python.exe", "3": self.key_local_machine_64 + "-3.8-path\\python.exe", "3-32": self.key_current_user + "-3.8-32-path\\python.exe", "3-64": self.key_local_machine_64 + "-3.8-path\\python.exe", "3.2": self.key_local_machine + "-3.2-path\\python.exe", "3.2-32": self.key_local_machine + "-3.2-path\\python.exe", "3.4": self.key_local_machine + "-3.4-path\\python.exe", "3.4-32": self.key_local_machine + "-3.4-path\\python.exe", "3.5": self.key_local_machine_64 + "-3.5-path\\python.exe", "3.5-64": self.key_local_machine_64 + "-3.5-path\\python.exe", "3.6": self.key_local_machine + "-3.6-32-path\\python.exe", "3.6-32": self.key_local_machine + "-3.6-32-path\\python.exe", "3.7": self.key_current_user_64 + "-3.7-path\\python.exe", "3.7-32": self.key_local_machine + "-3.7-32-path\\python.exe", "3.7-64": self.key_current_user_64 + "-3.7-path\\python.exe", "3.8": self.key_local_machine_64 + "-3.8-path\\python.exe", "3.8-32": self.key_current_user + "-3.8-32-path\\python.exe", "3.8-64": self.key_local_machine_64 + "-3.8-path\\python.exe", } assert mock_winreg.mock_calls == [ call.OpenKey(mock_winreg.HKEY_LOCAL_MACHINE, "Software\\Python\\PythonCore", 0, 0x11), call.EnumKey(self.key_local_machine, 0), call.QueryValue(self.key_local_machine, "2.4\\InstallPath"), call.EnumKey(self.key_local_machine, 1), call.QueryValue(self.key_local_machine, "2.7\\InstallPath"), call.EnumKey(self.key_local_machine, 2), call.QueryValue(self.key_local_machine, "3.2\\InstallPath"), call.EnumKey(self.key_local_machine, 3), call.QueryValue(self.key_local_machine, "3.4\\InstallPath"), call.EnumKey(self.key_local_machine, 4), call.QueryValue(self.key_local_machine, "3.6-32\\InstallPath"), call.EnumKey(self.key_local_machine, 5), call.QueryValue(self.key_local_machine, "3.7-32\\InstallPath"), call.EnumKey(self.key_local_machine, 6), call.CloseKey(self.key_local_machine), call.OpenKey(mock_winreg.HKEY_CURRENT_USER, "Software\\Python\\PythonCore", 0, 0x11), call.EnumKey(self.key_current_user, 0), call.QueryValue(self.key_current_user, "2.5\\InstallPath"), call.EnumKey(self.key_current_user, 1), call.QueryValue(self.key_current_user, "2.7\\InstallPath"), call.EnumKey(self.key_current_user, 2), call.QueryValue(self.key_current_user, "3.8-32\\InstallPath"), call.EnumKey(self.key_current_user, 3), call.CloseKey(self.key_current_user), call.OpenKey(mock_winreg.HKEY_LOCAL_MACHINE, "Software\\Python\\PythonCore", 0, 0x12), call.EnumKey(self.key_local_machine_64, 0), call.QueryValue(self.key_local_machine_64, "2.6\\InstallPath"), call.EnumKey(self.key_local_machine_64, 1), call.QueryValue(self.key_local_machine_64, "3.5\\InstallPath"), call.EnumKey(self.key_local_machine_64, 2), call.QueryValue(self.key_local_machine_64, "3.7\\InstallPath"), call.EnumKey(self.key_local_machine_64, 3), call.QueryValue(self.key_local_machine_64, "3.8\\InstallPath"), call.EnumKey(self.key_local_machine_64, 4), call.CloseKey(self.key_local_machine_64), call.OpenKey(mock_winreg.HKEY_CURRENT_USER, "Software\\Python\\PythonCore", 0, 0x12), call.EnumKey(self.key_current_user_64, 0), call.QueryValue(self.key_current_user_64, "3.7\\InstallPath"), call.EnumKey(self.key_current_user_64, 1), call.CloseKey(self.key_current_user_64), ]
def test_on_non_windows(self, monkeypatch): assert not virtualenv.IS_WIN assert not hasattr(virtualenv, "winreg") assert virtualenv.get_installed_pythons() == {}
def _python(v): return virtualenv.get_installed_pythons().get(v, "python{}".format(v))
def version_control(): py_versions = {} sys.stdout.write( '\nSelect Python3 global version to use or specifiy path to virtualenv\n' ) pythons = virtualenv.get_installed_pythons() for k, v in pythons.items(): if k.startswith('3.') and not k.__contains__('-'): py_versions.update({len(py_versions): k}) if not py_versions: sys.stdout.write('\nInstall Python 3 to be able to use this framework') exit() while True: options = "" for k, v in py_versions.items(): options += "[%s] %s\n" % (k, v) sys.stdout.write(options) if sys.version_info.major < 3: answer = raw_input() else: answer = input() if answer.isdigit() is False: sys.stdout.write( "\n Option must be numeric value. Please try again...\n") continue selected_option = int(answer) if selected_option not in py_versions.keys(): sys.stdout.write( "\n Option you entered does not exist. Please try again...\n") continue py_version = py_versions.get(selected_option) if py_version is not None: py_data = {'version': py_version} sys.stdout.write('\nSelected Python version is %s\n' % py_version) sys.stdout.write('\nChecking paths for this Python pleas wait..\n') p = Popen( 'py -%s -c "import sys; import os; sys.stdout.write(os.path.dirname(sys.executable))" ' % py_version, stdout=PIPE) lines = p.stdout.readlines() main_path = lines[0] if sys.version_info.major < 3: pycon_path = os.path.join(main_path, 'Scripts', 'config.py') else: pycon_path = os.path.join(main_path.decode(), 'Scripts', 'config.py') if os.path.exists(pycon_path) is False: sys.stdout.write( "\n Can't locate config.py at {0} \n make sure you are using python " "version where you installed this package then try again..." .format(pycon_path)) exit() sys.stdout.write('\nPath find at %s \n' % pycon_path) command = 'py -{0} {1}'.format(py_version, pycon_path) py_data.update({'cmd': command}) with open(python_path, 'wb') as fw: pickle.dump(py_data, fw) call(command) break