예제 #1
0
def test_builtin_discovery_class_preferred(mocker):
    mocker.patch(
        "virtualenv.run.plugin.discovery._get_default_discovery",
        return_value=["pluginA", "pluginX", "builtin", "Aplugin", "Xplugin"],
    )

    options = VirtualEnvOptions()
    session_via_cli(["venv"], options=options)
    assert options.discovery == "builtin"
예제 #2
0
def run_with_catch(args=None):
    options = VirtualEnvOptions()
    try:
        run(args, options)
    except (KeyboardInterrupt, Exception) as exception:
        if getattr(options, "with_traceback", False):
            logging.shutdown()  # force flush of log messages before the trace is printed
            raise
        else:
            logging.error("%s: %s", type(exception).__name__, exception)
            sys.exit(1)
def run_with_catch(args=None):
    from virtualenv.config.cli.parser import VirtualEnvOptions

    options = VirtualEnvOptions()
    try:
        run(args, options)
    except (KeyboardInterrupt, SystemExit, Exception) as exception:
        try:
            if getattr(options, "with_traceback", False):
                raise
            else:
                if not (isinstance(exception, SystemExit) and exception.code == 0):
                    logging.error("%s: %s", type(exception).__name__, exception)
                code = exception.code if isinstance(exception, SystemExit) else 1
                sys.exit(code)
        finally:
            logging.shutdown()  # force flush of log messages before the trace is printed
def test_python_activator_cross(session_app_data, cross_python,
                                special_name_dir):
    options = VirtualEnvOptions()
    cli_args = [
        str(special_name_dir),
        "-p",
        str(cross_python.executable),
        "--app-data",
        str(session_app_data.lock.path),
        "--without-pip",
        "--activators",
        "",
    ]
    session = session_via_cli(cli_args, options)
    activator = PythonActivator(options)
    session.creator.bin_dir.mkdir(parents=True)
    results = activator.generate(session.creator)
    assert len(results) == 1
    result = results[0]
    content = result.read_text()
    # check that the repr strings have been correctly stripped
    assert "\"'" not in content
def test_python_multi_value_prefer_newline_via_env_var(monkeypatch):
    options = VirtualEnvOptions()
    monkeypatch.setenv(str("VIRTUALENV_PYTHON"),
                       str("python3\npython2,python27"))
    session_via_cli(["venv"], options=options)
    assert options.python == ["python3", "python2,python27"]
def test_python_via_env_var(monkeypatch):
    options = VirtualEnvOptions()
    monkeypatch.setenv(str("VIRTUALENV_PYTHON"), str("python3"))
    session_via_cli(["venv"], options=options)
    assert options.python == ["python3"]
예제 #7
0
def test_python_multi_value_via_env_var(monkeypatch):
    options = VirtualEnvOptions()
    monkeypatch.setenv("VIRTUALENV_PYTHON", "python3,python2")
    session_via_cli(["venv"], options=options)
    assert options.python == ["python3", "python2"]
예제 #8
0
def test_reset_app_data_does_not_conflict_clear():
    options = VirtualEnvOptions()
    session_via_cli(["--clear", "venv"], options=options)
    assert options.clear is True
    assert options.reset_app_data is False