Exemplo n.º 1
0
    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)
Exemplo n.º 2
0
    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)
Exemplo n.º 3
0
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
Exemplo n.º 4
0
    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)
Exemplo n.º 5
0
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
Exemplo n.º 6
0
    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)
Exemplo n.º 7
0
    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)
Exemplo n.º 8
0
    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)