python.tests: also test virtualenv

Test whether creating a virtualenv functions.
This commit is contained in:
Frederik Rietdijk 2020-05-23 18:10:54 +02:00
parent dc80e0724c
commit 2de446e0b8
2 changed files with 20 additions and 1 deletions

View file

@ -9,6 +9,7 @@ let
envs = let
inherit python;
pythonEnv = python.withPackages(ps: with ps; [ ]);
pythonVirtualEnv = python.withPackages(ps: with ps; [ virtualenv ]);
in {
# Plain Python interpreter
plain = rec {
@ -16,6 +17,20 @@ let
interpreter = env.interpreter;
is_venv = "False";
is_nixenv = "False";
is_virtualenv = "False";
};
} // lib.optionalAttrs (python.isPy3k && !python.isPyPy) {
# Use virtualenv from a Nix env.
# Does not function with Python 2
# ValueError: source and destination is the same /nix/store/38kz3j1a87cq5y59k5w7k9yk4cqgc5b2-python-2.7.18/lib/python2.7/os.py
nixenv-virtualenv = rec {
env = runCommand "${python.name}-virtualenv" {} ''
${pythonVirtualEnv.interpreter} -m virtualenv $out
'';
interpreter = "${env}/bin/${python.executable}";
is_venv = "False";
is_nixenv = "True";
is_virtualenv = "True";
};
} // lib.optionalAttrs (python.implementation != "graal") {
# Python Nix environment (python.buildEnv)
@ -24,6 +39,7 @@ let
interpreter = env.interpreter;
is_venv = "False";
is_nixenv = "True";
is_virtualenv = "True";
};
} // lib.optionalAttrs (python.isPy3k && (!python.isPyPy)) rec {
# Venv built using plain Python
@ -36,6 +52,7 @@ let
interpreter = "${env}/bin/${python.executable}";
is_venv = "True";
is_nixenv = "False";
is_virtualenv = "True";
};
} // lib.optionalAttrs (python.pythonAtLeast "3.8") {
@ -49,6 +66,7 @@ let
interpreter = "${env}/bin/${pythonEnv.executable}";
is_venv = "True";
is_nixenv = "True";
is_virtualenv = "True";
};
};

View file

@ -16,6 +16,7 @@ ENV = "@env@"
INTERPRETER = "@interpreter@"
PYTHON_VERSION = "@pythonVersion@"
IS_VIRTUALENV = @is_virtualenv@
IS_VENV = @is_venv@
IS_NIXENV = @is_nixenv@
IS_PYPY = platform.python_implementation() == "PyPy"
@ -37,7 +38,7 @@ class TestCasePython(unittest.TestCase):
@unittest.skipIf(IS_PYPY or sys.version_info.major==2, "Python 2 does not have base_prefix")
def test_base_prefix(self):
if IS_VENV or IS_NIXENV:
if IS_VENV or IS_NIXENV or IS_VIRTUALENV:
self.assertNotEqual(sys.prefix, sys.base_prefix)
else:
self.assertEqual(sys.prefix, sys.base_prefix)