Skip to content

Commit

Permalink
Update tests for virtualenv
Browse files Browse the repository at this point in the history
  • Loading branch information
frenzymadness committed Sep 1, 2020
1 parent f7bb8a5 commit 78ef0f6
Showing 1 changed file with 1 addition and 55 deletions.
56 changes: 1 addition & 55 deletions tests/unit/test_utils_virtualenv.py
Original file line number Diff line number Diff line change
@@ -1,68 +1,14 @@
import logging
import site
import sys

import pytest

from pip._internal.utils import virtualenv


@pytest.mark.parametrize("real_prefix, base_prefix, expected", [
(None, None, False), # Python 2 base interpreter
(None, sys.prefix, False), # Python 3 base interpreter
(None, "not_sys_prefix", True), # PEP405 venv
(sys.prefix, None, True), # Unknown case
(sys.prefix, sys.prefix, True), # Unknown case
(sys.prefix, "not_sys_prefix", True), # Unknown case
("not_sys_prefix", None, True), # Python 2 virtualenv
("not_sys_prefix", sys.prefix, True), # Python 3 virtualenv
("not_sys_prefix", "not_sys_prefix", True), # Unknown case
])
def test_running_under_virtualenv(
monkeypatch, real_prefix, base_prefix, expected):
# Use raising=False to prevent AttributeError on missing attribute
if real_prefix is None:
monkeypatch.delattr(sys, "real_prefix", raising=False)
else:
monkeypatch.setattr(sys, "real_prefix", real_prefix, raising=False)
if base_prefix is None:
monkeypatch.delattr(sys, "base_prefix", raising=False)
else:
monkeypatch.setattr(sys, "base_prefix", base_prefix, raising=False)
assert virtualenv.running_under_virtualenv() == expected


@pytest.mark.parametrize(
"under_virtualenv, no_global_file, expected", [
(False, False, False),
(False, True, False),
(True, False, False),
(True, True, True),
],
)
def test_virtualenv_no_global_with_regular_virtualenv(
monkeypatch,
tmpdir,
under_virtualenv,
no_global_file,
expected,
):
monkeypatch.setattr(virtualenv, '_running_under_venv', lambda: False)

monkeypatch.setattr(site, '__file__', tmpdir / 'site.py')
monkeypatch.setattr(
virtualenv, '_running_under_regular_virtualenv',
lambda: under_virtualenv,
)
if no_global_file:
(tmpdir / 'no-global-site-packages.txt').touch()

assert virtualenv.virtualenv_no_global() == expected


@pytest.mark.parametrize(
"pyvenv_cfg_lines, under_venv, expected, expect_warning", [
(None, False, False, False),
(None, False, True, True),
(None, True, True, True), # this has a warning.
(
[
Expand Down

0 comments on commit 78ef0f6

Please sign in to comment.