git.iko.soy/typeable/nixpkgs
on master help sign in
python.tests: also test virtualenv

Test whether creating a virtualenv functions.

commit2de446e0b89681ac9896c03530ca7b69d966a3e9 authorFrederik Rietdijk <fridh@fridh.nl> dateSat 23 May 2020, 18:10 (6 years ago) parentdc80e07
2 files changed+20−1
pkgs/development/interpreters/python/tests.nix+18 pkgs/development/interpreters/python/tests/test_python.py+2−1
pkgs/development/interpreters/python/tests.nix+18
@@ -9,6 +9,7 @@ let
99 envs = let
1010 inherit python;
1111 pythonEnv = python.withPackages(ps: with ps; [ ]);
12+ pythonVirtualEnv = python.withPackages(ps: with ps; [ virtualenv ]);
1213 in {
1314 # Plain Python interpreter
1415 plain = rec {
@@ -16,6 +17,20 @@ let
1617 interpreter = env.interpreter;
1718 is_venv = "False";
1819 is_nixenv = "False";
20+ is_virtualenv = "False";
21+ };
22+ } // lib.optionalAttrs (python.isPy3k && !python.isPyPy) {
23+ # Use virtualenv from a Nix env.
24+ # Does not function with Python 2
25+ # ValueError: source and destination is the same /nix/store/38kz3j1a87cq5y59k5w7k9yk4cqgc5b2-python-2.7.18/lib/python2.7/os.py
26+ nixenv-virtualenv = rec {
27+ env = runCommand "${python.name}-virtualenv" {} ''
28+ ${pythonVirtualEnv.interpreter} -m virtualenv $out
29+ '';
30+ interpreter = "${env}/bin/${python.executable}";
31+ is_venv = "False";
32+ is_nixenv = "True";
33+ is_virtualenv = "True";
1934 };
2035 } // lib.optionalAttrs (python.implementation != "graal") {
2136 # Python Nix environment (python.buildEnv)
@@ -24,6 +39,7 @@ let
2439 interpreter = env.interpreter;
2540 is_venv = "False";
2641 is_nixenv = "True";
42+ is_virtualenv = "True";
2743 };
2844 } // lib.optionalAttrs (python.isPy3k && (!python.isPyPy)) rec {
2945 # Venv built using plain Python
@@ -36,6 +52,7 @@ let
3652 interpreter = "${env}/bin/${python.executable}";
3753 is_venv = "True";
3854 is_nixenv = "False";
55+ is_virtualenv = "True";
3956 };
4057
4158 } // lib.optionalAttrs (python.pythonAtLeast "3.8") {
@@ -49,6 +66,7 @@ let
4966 interpreter = "${env}/bin/${pythonEnv.executable}";
5067 is_venv = "True";
5168 is_nixenv = "True";
69+ is_virtualenv = "True";
5270 };
5371 };
5472
pkgs/development/interpreters/python/tests/test_python.py+2−1
@@ -16,6 +16,7 @@ ENV = "@env@"
1616INTERPRETER = "@interpreter@"
1717PYTHON_VERSION = "@pythonVersion@"
1818
19+IS_VIRTUALENV = @is_virtualenv@
1920IS_VENV = @is_venv@
2021IS_NIXENV = @is_nixenv@
2122IS_PYPY = platform.python_implementation() == "PyPy"
@@ -37,7 +38,7 @@ class TestCasePython(unittest.TestCase):
3738
3839 @unittest.skipIf(IS_PYPY or sys.version_info.major==2, "Python 2 does not have base_prefix")
3940 def test_base_prefix(self):
40− if IS_VENV or IS_NIXENV:
41+ if IS_VENV or IS_NIXENV or IS_VIRTUALENV:
4142 self.assertNotEqual(sys.prefix, sys.base_prefix)
4243 else:
4344 self.assertEqual(sys.prefix, sys.base_prefix)