def test_download_pip_installer(self): mgr = PipManager('/usr/bin', pip_installed=False) with tempfile.NamedTemporaryFile() as temp_file: mgr.pip_installer_fname = temp_file.name with patch('fades.pipmanager.request.urlopen') as urlopen: urlopen.return_value = io.BytesIO(b'hola') mgr._download_pip_installer() self.assertTrue(os.path.exists(mgr.pip_installer_fname)) urlopen.assert_called_once_with(pipmanager.PIP_INSTALLER)
def test_download_pip_installer(mocker, tmp_path): tmp_file = str(tmp_path / "hello.txt") mgr = PipManager(BIN_PATH, pip_installed=False) mgr.pip_installer_fname = tmp_file urlopen = mocker.patch("fades.pipmanager.request.urlopen", return_value=io.BytesIO(b"hola")) mgr._download_pip_installer() assert os.path.exists(mgr.pip_installer_fname) urlopen.assert_called_once_with(pipmanager.PIP_INSTALLER)
def test_download_pip_installer(self): mgr = PipManager(BIN_PATH, pip_installed=False) # get a tempfile and remove it, so later the installer is downloaded there tempfile = get_tempfile(self) os.remove(tempfile) mgr.pip_installer_fname = tempfile with patch('fades.pipmanager.request.urlopen') as urlopen: urlopen.return_value = io.BytesIO(b'hola') mgr._download_pip_installer() self.assertTrue(os.path.exists(mgr.pip_installer_fname)) urlopen.assert_called_once_with(pipmanager.PIP_INSTALLER)
def test_brute_force_install_pip_installer_exists(self): mgr = PipManager(BIN_PATH, pip_installed=False) python_path = os.path.join(BIN_PATH, 'python') with patch.object(helpers, 'logged_exec') as mocked_exec, \ patch.object(mgr, '_download_pip_installer') as download_installer: # get the tempfile but leave it there to be found mgr.pip_installer_fname = get_tempfile(self) mgr._brute_force_install_pip() self.assertEqual(download_installer.call_count, 0) mocked_exec.assert_called_with([python_path, mgr.pip_installer_fname, '-I']) self.assertTrue(mgr.pip_installed)
def test_brute_force_install_pip_no_installer(mocker, tmp_path): tmp_file = str(tmp_path / "hello.txt") mgr = PipManager(BIN_PATH, pip_installed=False) python_path = os.path.join(BIN_PATH, "python") mocked_exec = mocker.patch.object(helpers, "logged_exec") download_installer = mocker.patch.object(mgr, "_download_pip_installer") mgr.pip_installer_fname = tmp_file mgr._brute_force_install_pip() download_installer.assert_called_once_with() mocked_exec.assert_called_with( [python_path, mgr.pip_installer_fname, "-I"]) assert mgr.pip_installed
def test_brute_force_install_pip_no_installer(self): mgr = PipManager('/usr/bin', pip_installed=False) with patch.object(helpers, 'logged_exec') as mocked_exec, \ patch.object(mgr, '_download_pip_installer') as download_installer: with tempfile.NamedTemporaryFile() as temp_file: mgr.pip_installer_fname = temp_file.name temp_file.close( ) # Without this the file does not gets created mgr._brute_force_install_pip() download_installer.assert_called_once_with() mocked_exec.assert_called_with( ['/usr/bin/python', mgr.pip_installer_fname, '-I']) self.assertTrue(mgr.pip_installed)
def test_brute_force_install_pip_installer_exists(mocker, tmp_path): tmp_file = str(tmp_path / "hello.txt") mgr = PipManager(BIN_PATH, pip_installed=False) python_path = os.path.join(BIN_PATH, "python") mocked_exec = mocker.patch.object(helpers, "logged_exec") download_installer = mocker.patch.object(mgr, "_download_pip_installer") # get the tempfile but leave it there to be found open(tmp_file, 'wt', encoding='utf8').close() mgr.pip_installer_fname = tmp_file mgr._brute_force_install_pip() assert not download_installer.called mocked_exec.assert_called_with( [python_path, mgr.pip_installer_fname, "-I"]) assert mgr.pip_installed
def test_brute_force_install_pip_no_installer(self): mgr = PipManager(BIN_PATH, pip_installed=False) python_path = os.path.join(BIN_PATH, 'python') with patch.object(helpers, 'logged_exec') as mocked_exec, \ patch.object(mgr, '_download_pip_installer') as download_installer: # get the tempfile and remove it so then it's not found tempfile = get_tempfile(self) os.remove(tempfile) mgr.pip_installer_fname = tempfile mgr._brute_force_install_pip() download_installer.assert_called_once_with() mocked_exec.assert_called_with([python_path, mgr.pip_installer_fname, '-I']) self.assertTrue(mgr.pip_installed)
def test_brute_force_install_pip_installer_exists(self): mgr = PipManager('/usr/bin', pip_installed=False) with patch.object(helpers, 'logged_exec') as mocked_exec, \ patch.object(mgr, '_download_pip_installer') as download_installer: # Create empty file with tempfile.NamedTemporaryFile(delete=False) as f: mgr.pip_installer_fname = f.name try: mgr._brute_force_install_pip() finally: os.remove(mgr.pip_installer_fname) self.assertEqual(download_installer.call_count, 0) mocked_exec.assert_called_with( ['/usr/bin/python', mgr.pip_installer_fname, '-I']) self.assertTrue(mgr.pip_installed)