Ejemplo n.º 1
0
def test_resolve_interpreter_with_nonexistent_interpreter(
        mock_exists, mock_get_installed_pythons):
    """Should SystemExit with an nonexistent python interpreter path"""
    with pytest.raises(SystemExit):
        virtualenv.resolve_interpreter("/usr/bin/python53")

    mock_exists.assert_called_with("/usr/bin/python53")
Ejemplo n.º 2
0
def test_resolve_interpreter_with_nonexistent_interpreter(mock_exists):
    """Should SystemExit with an nonexistent python interpreter path"""
    mock_exists.return_value = False

    with pytest.raises(SystemExit):
        virtualenv.resolve_interpreter("/usr/bin/python53")

    mock_exists.assert_called_with("/usr/bin/python53")
Ejemplo n.º 3
0
def test_resolve_interpreter_with_invalid_interpreter(mock_exists, mock_is_executable):
    """Should exit when with absolute path if not exists"""
    invalid = os.path.abspath("/usr/bin/pyt_hon53")

    with pytest.raises(SystemExit):
        virtualenv.resolve_interpreter(invalid)

    mock_exists.assert_called_with(invalid)
    mock_is_executable.assert_called_with(invalid)
Ejemplo n.º 4
0
def test_resolve_interpreter_with_invalid_interpreter(mock_exists, mock_is_executable):
    """Should exit when with absolute path if not exists"""
    invalid = os.path.abspath("/usr/bin/pyt_hon53")

    with pytest.raises(SystemExit):
        virtualenv.resolve_interpreter(invalid)

    mock_exists.assert_called_with(invalid)
    mock_is_executable.assert_called_with(invalid)
Ejemplo n.º 5
0
def test_resolve_interpreter_with_nonexistent_interpreter(mock_exists):
    """Should exit when with absolute path if not exists"""
    mock_exists.return_value = False

    try:
        virtualenv.resolve_interpreter("/usr/bin/python42")
        assert False, "Should raise exception"
    except SystemExit:
        pass

    mock_exists.assert_called_with("/usr/bin/python42")
Ejemplo n.º 6
0
def test_resolve_intepreter_with_nonexistant_interpreter(mock_exists):
    """Should exit when with absolute path if not exists"""
    mock_exists.return_value = False

    try:
        virtualenv.resolve_interpreter("/usr/bin/python42")
        assert False, "Should raise exception"
    except SystemExit:
        pass

    mock_exists.assert_called_with("/usr/bin/python42")
Ejemplo n.º 7
0
def test_resolve_interpreter_with_invalid_interpreter(mock_exists):
    """Should exit when with absolute path if not exists"""
    mock_exists.return_value = True
    virtualenv.is_executable = Mock(return_value=False)

    try:
        virtualenv.resolve_interpreter("/usr/bin/python42")
        assert False, "Should raise exception"
    except SystemExit:
        pass

    mock_exists.assert_called_with("/usr/bin/python42")
    virtualenv.is_executable.assert_called_with("/usr/bin/python42")
Ejemplo n.º 8
0
def test_resolve_intepreter_with_invalid_interpreter(mock_exists):
    """Should exit when with absolute path if not exists"""
    mock_exists.return_value = True
    virtualenv.is_executable = Mock(return_value=False)

    try:
        virtualenv.resolve_interpreter("/usr/bin/python42")
        assert False, "Should raise exception"
    except SystemExit:
        pass

    mock_exists.assert_called_with("/usr/bin/python42")
    virtualenv.is_executable.assert_called_with("/usr/bin/python42")
Ejemplo n.º 9
0
def test_resolve_interpreter_with_absolute_path(mock_exists, mock_get_installed_pythons, mock_is_executable):
    """Should return absolute path if given and exists"""
    test_abs_path = os.path.abspath("/usr/bin/python53")

    exe = virtualenv.resolve_interpreter(test_abs_path)

    assert exe == test_abs_path, "Absolute path should return as is"

    mock_exists.assert_called_with(test_abs_path)
    mock_is_executable.assert_called_with(test_abs_path)
Ejemplo n.º 10
0
def test_resolve_interpreter_with_absolute_path(mock_exists, mock_get_installed_pythons, mock_is_executable):
    """Should return absolute path if given and exists"""
    test_abs_path = os.path.abspath("/usr/bin/python53")

    exe = virtualenv.resolve_interpreter(test_abs_path)

    assert exe == test_abs_path, "Absolute path should return as is"

    mock_exists.assert_called_with(test_abs_path)
    mock_is_executable.assert_called_with(test_abs_path)
Ejemplo n.º 11
0
def test_resolve_interpreter_with_absolute_path(mock_exists):
    """Should return absolute path if given and exists"""
    mock_exists.return_value = True
    virtualenv.is_executable = Mock(return_value=True)

    exe = virtualenv.resolve_interpreter("/usr/bin/python42")

    assert exe == "/usr/bin/python42", "Absolute path should return as is"
    mock_exists.assert_called_with("/usr/bin/python42")
    virtualenv.is_executable.assert_called_with("/usr/bin/python42")
Ejemplo n.º 12
0
def test_resolve_interpreter_with_absolute_path(mock_exists):
    """Should return absolute path if given and exists"""
    mock_exists.return_value = True
    virtualenv.is_executable = Mock(return_value=True)

    exe = virtualenv.resolve_interpreter("/usr/bin/python42")

    assert exe == "/usr/bin/python42", "Absolute path should return as is"
    mock_exists.assert_called_with("/usr/bin/python42")
    virtualenv.is_executable.assert_called_with("/usr/bin/python42")
Ejemplo n.º 13
0
def test_resolve_interpreter_with_installed_python(
    mock_abspath, mock_exists, mock_get_installed_pythons, mock_is_executable, mock_find_executable
):
    test_tag = "foo"
    test_path = "/path/to/foo/python.exe"
    test_abs_path = "some-abs-path"
    test_found_path = "some-found-path"
    mock_get_installed_pythons.return_value = {test_tag: test_path, test_tag + "2": test_path + "2"}
    mock_abspath.return_value = test_abs_path
    mock_find_executable.return_value = test_found_path

    exe = virtualenv.resolve_interpreter("foo")

    assert exe == test_found_path, "installed python should be accessible by key"

    mock_get_installed_pythons.assert_called_once_with()
    mock_abspath.assert_called_once_with(test_path)
    mock_find_executable.assert_called_once_with(test_path)
    mock_exists.assert_called_once_with(test_found_path)
    mock_is_executable.assert_called_once_with(test_found_path)
Ejemplo n.º 14
0
def test_resolve_interpreter_with_installed_python(
    mock_abspath, mock_exists, mock_get_installed_pythons, mock_is_executable, mock_find_executable
):
    test_tag = "foo"
    test_path = "/path/to/foo/python.exe"
    test_abs_path = "some-abs-path"
    test_found_path = "some-found-path"
    mock_get_installed_pythons.return_value = {test_tag: test_path, test_tag + "2": test_path + "2"}
    mock_abspath.return_value = test_abs_path
    mock_find_executable.return_value = test_found_path

    exe = virtualenv.resolve_interpreter("foo")

    assert exe == test_found_path, "installed python should be accessible by key"

    mock_get_installed_pythons.assert_called_once_with()
    mock_abspath.assert_called_once_with(test_path)
    mock_find_executable.assert_called_once_with(test_path)
    mock_exists.assert_called_once_with(test_found_path)
    mock_is_executable.assert_called_once_with(test_found_path)
Ejemplo n.º 15
0
def test_create_environment_with_exec_prefix_pointing_to_prefix(tmpdir):
    """Create virtual environment for Python with ``sys.exec_prefix`` pointing
    to ``sys.prefix`` or ``sys.base_prefix`` or ``sys.real_prefix`` under a
    different name
    """
    venvdir = str(tmpdir / "venv")
    python_dir = tmpdir / "python"
    python_dir.mkdir()
    path_key = str("PATH")
    old_path = os.environ[path_key]
    if hasattr(sys, "real_prefix"):
        os.environ[path_key] = os.pathsep.join(
            p for p in os.environ[path_key].split(os.pathsep) if not p.startswith(sys.prefix)
        )
    python = virtualenv.resolve_interpreter(os.path.basename(sys.executable))
    try:
        subprocess.check_call([sys.executable, "-m", "virtualenv", "-p", python, venvdir])
        home_dir, lib_dir, inc_dir, bin_dir = virtualenv.path_locations(venvdir)
        assert not os.path.islink(os.path.join(lib_dir, "distutils"))
    finally:
        os.environ[path_key] = old_path
Ejemplo n.º 16
0
def test_create_environment_with_exec_prefix_pointing_to_prefix(tmpdir):
    """Create virtual environment for Python with ``sys.exec_prefix`` pointing
    to ``sys.prefix`` or ``sys.base_prefix`` or ``sys.real_prefix`` under a
    different name
    """
    venvdir = str(tmpdir / "venv")
    python_dir = tmpdir / "python"
    python_dir.mkdir()
    path_key = str("PATH")
    old_path = os.environ[path_key]
    if hasattr(sys, "real_prefix"):
        os.environ[path_key] = os.pathsep.join(
            p for p in os.environ[path_key].split(os.pathsep) if not p.startswith(sys.prefix)
        )
    python = virtualenv.resolve_interpreter(os.path.basename(sys.executable))
    try:
        subprocess.check_call([sys.executable, "-m", "virtualenv", "-p", python, venvdir])
        home_dir, lib_dir, inc_dir, bin_dir = virtualenv.path_locations(venvdir)
        assert not os.path.islink(os.path.join(lib_dir, "distutils"))
    finally:
        os.environ[path_key] = old_path