Example #1
0
 def test_timeout(self) -> None:
     # FakeCommand intentionally returns the wrong type.
     options1, args1 = cast(Tuple[Values, List[str]],
                            main(["--timeout", "-1", "fake"]))
     options2, args2 = cast(Tuple[Values, List[str]],
                            main(["fake", "--timeout", "-1"]))
     assert options1.timeout == options2.timeout == -1
Example #2
0
 def test_exists_action(self) -> None:
     # FakeCommand intentionally returns the wrong type.
     options1, args1 = cast(Tuple[Values, List[str]],
                            main(["--exists-action", "w", "fake"]))
     options2, args2 = cast(Tuple[Values, List[str]],
                            main(["fake", "--exists-action", "w"]))
     assert options1.exists_action == options2.exists_action == ["w"]
Example #3
0
 def test_local_log(self) -> None:
     # FakeCommand intentionally returns the wrong type.
     options1, args1 = cast(Tuple[Values, List[str]],
                            main(["--local-log", "path", "fake"]))
     options2, args2 = cast(Tuple[Values, List[str]],
                            main(["fake", "--local-log", "path"]))
     assert options1.log == options2.log == "path"
Example #4
0
def pip():
    cmd = sys.argv[2]
    args = [cmd, '--target', sys._MEIPASS,]
    args.extend(sys.argv[3:])
    parser = ['pip'] + args
    sys.argv = parser
    main(args)
Example #5
0
 def test_client_cert(self) -> None:
     # FakeCommand intentionally returns the wrong type.
     options1, args1 = cast(Tuple[Values, List[str]],
                            main(["--client-cert", "path", "fake"]))
     options2, args2 = cast(Tuple[Values, List[str]],
                            main(["fake", "--client-cert", "path"]))
     assert options1.client_cert == options2.client_cert == "path"
Example #6
0
 def test_no_input(self) -> None:
     # FakeCommand intentionally returns the wrong type.
     options1, args1 = cast(Tuple[Values, List[str]],
                            main(["--no-input", "fake"]))
     options2, args2 = cast(Tuple[Values, List[str]],
                            main(["fake", "--no-input"]))
     assert options1.no_input
     assert options2.no_input
Example #7
0
 def test_require_virtualenv(self) -> None:
     # FakeCommand intentionally returns the wrong type.
     options1, args1 = cast(Tuple[Values, List[str]],
                            main(["--require-virtualenv", "fake"]))
     options2, args2 = cast(Tuple[Values, List[str]],
                            main(["fake", "--require-virtualenv"]))
     assert options1.require_venv
     assert options2.require_venv
Example #8
0
 def test_env_var_invalid(
     self,
     option: str,
     value: Any,
     monkeypatch: pytest.MonkeyPatch,
     capsys: pytest.CaptureFixture[str],
 ) -> None:
     monkeypatch.setenv("PIP_" + option.upper(), str(value))
     with assert_option_error(capsys, expected="a non-negative integer"):
         main(["fake"])
Example #9
0
    def test_env_override_default_choice(self):
        """
        Test that environment variable overrides a choice option default.
        """
        os.environ['PIP_EXISTS_ACTION'] = 'w'
        options, args = main(['fake'])
        assert options.exists_action == ['w']

        os.environ['PIP_EXISTS_ACTION'] = 's w'
        options, args = main(['fake'])
        assert options.exists_action == ['s', 'w']
Example #10
0
    def test_env_override_default_append(self):
        """
        Test that environment variable overrides an append option default.
        """
        os.environ['PIP_FIND_LINKS'] = 'F1'
        options, args = main(['fake'])
        assert options.find_links == ['F1']

        os.environ['PIP_FIND_LINKS'] = 'F1 F2'
        options, args = main(['fake'])
        assert options.find_links == ['F1', 'F2']
Example #11
0
 def test_config_file_invalid(
     self,
     option: str,
     value: Any,
     monkeypatch: pytest.MonkeyPatch,
     capsys: pytest.CaptureFixture[str],
 ) -> None:
     with tmpconfig(option, value) as name:
         monkeypatch.setenv("PIP_CONFIG_FILE", name)
         with assert_option_error(capsys, expected="non-negative integer"):
             main(["fake"])
Example #12
0
 def test_cache_dir__PIP_NO_CACHE_DIR_invalid__with_no_cache_dir(
     self,
     capsys,
 ):
     """
     Test setting PIP_NO_CACHE_DIR to an invalid value while also passing
     --no-cache-dir.
     """
     os.environ['PIP_NO_CACHE_DIR'] = 'maybe'
     expected_err = "--no-cache-dir error: invalid truth value 'maybe'"
     with assert_option_error(capsys, expected=expected_err):
         main(['--no-cache-dir', 'fake'])
Example #13
0
 def test_env_alias_override_default(self):
     """
     When an option has multiple long forms, test that the technique of
     using the env variable, "PIP_<long form>" works for all cases.
     (e.g. PIP_LOG_FILE and PIP_LOCAL_LOG should all work)
     """
     os.environ['PIP_LOG_FILE'] = 'override.log'
     options, args = main(['fake'])
     assert options.log == 'override.log'
     os.environ['PIP_LOCAL_LOG'] = 'override.log'
     options, args = main(['fake'])
     assert options.log == 'override.log'
Example #14
0
 def test_cache_dir__PIP_NO_CACHE_DIR_invalid__with_no_cache_dir(
     self,
     monkeypatch: pytest.MonkeyPatch,
     capsys: pytest.CaptureFixture[str],
 ) -> None:
     """
     Test setting PIP_NO_CACHE_DIR to an invalid value while also passing
     --no-cache-dir.
     """
     monkeypatch.setenv("PIP_NO_CACHE_DIR", "maybe")
     expected_err = "--no-cache-dir error: invalid truth value 'maybe'"
     with assert_option_error(capsys, expected=expected_err):
         main(["--no-cache-dir", "fake"])
Example #15
0
 def test_env_override_default_int(self):
     """
     Test that environment variable overrides an int option default.
     """
     os.environ['PIP_TIMEOUT'] = '-1'
     options, args = main(['fake'])
     assert options.timeout == -1
Example #16
0
def _wrapper(args=None):

    # type: (Optional[List[str]]) -> int
    """Central wrapper for all old entrypoints.



    Historically pip has had several entrypoints defined. Because of issues

    arising from PATH, sys.path, multiple Pythons, their interactions, and most

    of them having a pip installed, users suffer every time an entrypoint gets

    moved.



    To alleviate this pain, and provide a mechanism for warning users and

    directing them to an appropriate place for help, we now define all of

    our old entrypoints as wrappers for the current one.

    """

    sys.stderr.write(
        "WARNING: pip is being invoked by an old script wrapper. This will "
        "fail in a future version of pip.\n"
        "Please see https://github.com/pypa/pip/issues/5599 for advice on "
        "fixing the underlying issue.\n"
        "To avoid this problem you can invoke Python with '-m pip' instead of "
        "running pip directly.\n")

    return main(args)
Example #17
0
 def test_env_override_default_choice(self, choises, monkeypatch):
     """
     Test that environment variable overrides a choice option default.
     """
     monkeypatch.setenv('PIP_EXISTS_ACTION', ' '.join(choises))
     options, args = main(['fake'])
     assert options.exists_action == choises
Example #18
0
 def test_env_var_integrate_cli(self, option: str, value: int,
                                monkeypatch: pytest.MonkeyPatch) -> None:
     monkeypatch.setenv("PIP_" + option.upper(), str(value))
     # FakeCommand intentionally returns the wrong type.
     options, args = cast(Tuple[Values, List[str]],
                          main(["fake", "--" + option]))
     assert getattr(options, option) == value + 1
Example #19
0
 def test_config_file_true(self, option: str, value: str,
                           monkeypatch: pytest.MonkeyPatch) -> None:
     with tmpconfig(option, value) as name:
         monkeypatch.setenv("PIP_CONFIG_FILE", name)
         # FakeCommand intentionally returns the wrong type.
         options, args = cast(Tuple[Values, List[str]], main(["fake"]))
         assert getattr(options, option) == 1
Example #20
0
 def test_env_override_default_append(self, values, monkeypatch):
     """
     Test that environment variable overrides an append option default.
     """
     monkeypatch.setenv('PIP_FIND_LINKS', ' '.join(values))
     options, args = main(['fake'])
     assert options.find_links == values
Example #21
0
 def test_cli_override_environment(self):
     """
     Test the cli overrides and environment variable
     """
     os.environ['PIP_TIMEOUT'] = '-1'
     options, args = main(['fake', '--timeout', '-2'])
     assert options.timeout == -2
Example #22
0
 def test_env_override_default_int(self, monkeypatch):
     """
     Test that environment variable overrides an int option default.
     """
     monkeypatch.setenv('PIP_TIMEOUT', '-1')
     options, args = main(['fake'])
     assert options.timeout == -1
Example #23
0
 def test_cli_override_environment(self, monkeypatch):
     """
     Test the cli overrides and environment variable
     """
     monkeypatch.setenv('PIP_TIMEOUT', '-1')
     options, args = main(['fake', '--timeout', '-2'])
     assert options.timeout == -2
Example #24
0
 def test_cache_dir__PIP_NO_CACHE_DIR(self, pip_no_cache_dir, monkeypatch):
     """
     Test setting the PIP_NO_CACHE_DIR environment variable without
     passing any command-line flags.
     """
     monkeypatch.setenv('PIP_NO_CACHE_DIR', pip_no_cache_dir)
     options, args = main(['fake'])
     assert options.cache_dir is False
Example #25
0
 def test_cache_dir__PIP_NO_CACHE_DIR(self, pip_no_cache_dir):
     """
     Test setting the PIP_NO_CACHE_DIR environment variable without
     passing any command-line flags.
     """
     os.environ['PIP_NO_CACHE_DIR'] = pip_no_cache_dir
     options, args = main(['fake'])
     assert options.cache_dir is False
Example #26
0
def run_pip_cmd(*args):
    with io.StringIO() as stdout_capture, contextlib.redirect_stdout(
            stdout_capture):
        with mock.patch.object(sys, "argv", new=["pip", *args]):
            status_code = PIP_STATUS_CODES(main.main())

        assert status_code == PIP_STATUS_CODES.SUCCESS
        return stdout_capture.getvalue().strip()
Example #27
0
 def test_env_override_default_int(self, monkeypatch: pytest.MonkeyPatch) -> None:
     """
     Test that environment variable overrides an int option default.
     """
     monkeypatch.setenv("PIP_TIMEOUT", "-1")
     # FakeCommand intentionally returns the wrong type.
     options, args = cast(Tuple[Values, List[str]], main(["fake"]))
     assert options.timeout == -1
Example #28
0
def install_packages(package_names):
    """
    Installs all the packages in the package_names
    :param package_names: list of all the packages
    """
    for package in package_names:
        ret=main.main(["install", package])
        if ret != 0:
            raise Exception("Installation failed.Check logs")
Example #29
0
 def test_env_override_default_choice(
         self, choices: List[str], monkeypatch: pytest.MonkeyPatch) -> None:
     """
     Test that environment variable overrides a choice option default.
     """
     monkeypatch.setenv("PIP_EXISTS_ACTION", " ".join(choices))
     # FakeCommand intentionally returns the wrong type.
     options, args = cast(Tuple[Values, List[str]], main(["fake"]))
     assert options.exists_action == choices
Example #30
0
 def test_env_alias_override_default(self, name, monkeypatch):
     """
     When an option has multiple long forms, test that the technique of
     using the env variable, "PIP_<long form>" works for all cases.
     (e.g. PIP_LOG_FILE and PIP_LOCAL_LOG should all work)
     """
     monkeypatch.setenv(name, 'override.log')
     options, args = main(['fake'])
     assert options.log == 'override.log'