about summary refs log tree commit diff
path: root/pkgs/development/interpreters
diff options
context:
space:
mode:
authorFrederik Rietdijk <fridh@fridh.nl>2020-05-23 18:10:54 +0200
committerFrederik Rietdijk <fridh@fridh.nl>2020-05-23 18:15:45 +0200
commit2de446e0b89681ac9896c03530ca7b69d966a3e9 (patch)
treec6686c4ba9fac0a5b8d51b4717e7033846665dc0 /pkgs/development/interpreters
parentdc80e0724c2d5407dbe3cff2972500065951f888 (diff)
python.tests: also test virtualenv
Test whether creating a virtualenv functions.
Diffstat (limited to 'pkgs/development/interpreters')
-rw-r--r--pkgs/development/interpreters/python/tests.nix18
-rw-r--r--pkgs/development/interpreters/python/tests/test_python.py3
2 files changed, 20 insertions, 1 deletions
diff --git a/pkgs/development/interpreters/python/tests.nix b/pkgs/development/interpreters/python/tests.nix
index f7ec06ce4ff79..6c4a6ae8e21cb 100644
--- a/pkgs/development/interpreters/python/tests.nix
+++ b/pkgs/development/interpreters/python/tests.nix
@@ -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";
     };
   };
 
diff --git a/pkgs/development/interpreters/python/tests/test_python.py b/pkgs/development/interpreters/python/tests/test_python.py
index 011978c625479..41a7e687d2637 100644
--- a/pkgs/development/interpreters/python/tests/test_python.py
+++ b/pkgs/development/interpreters/python/tests/test_python.py
@@ -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)