From 2de446e0b89681ac9896c03530ca7b69d966a3e9 Mon Sep 17 00:00:00 2001 From: Frederik Rietdijk Date: Sat, 23 May 2020 18:10:54 +0200 Subject: python.tests: also test virtualenv Test whether creating a virtualenv functions. --- pkgs/development/interpreters/python/tests.nix | 18 ++++++++++++++++++ .../interpreters/python/tests/test_python.py | 3 ++- 2 files changed, 20 insertions(+), 1 deletion(-) (limited to 'pkgs/development/interpreters') 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) -- cgit 1.4.1