nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at python-updates 60 lines 1.9 kB view raw
1""" 2Python interpreter and environment tests. 3 4These need to be executed with the standard library unittest. 5Third party test runners such as pytest cannot be used because 6that would interfere with the tests. 7""" 8 9import platform 10import sys 11import sysconfig 12import unittest 13import site 14 15 16ENV = "@environment@" 17INTERPRETER = "@interpreter@" 18PYTHON_VERSION = "@pythonVersion@" 19 20IS_VIRTUALENV = @is_virtualenv@ 21IS_VENV = @is_venv@ 22IS_NIXENV = @is_nixenv@ 23IS_PYPY = platform.python_implementation() == "PyPy" 24 25 26class TestCasePython(unittest.TestCase): 27 28 @unittest.skipIf(IS_PYPY, "Executable is incorrect and needs to be fixed.") 29 def test_interpreter(self): 30 self.assertEqual(sys.executable, INTERPRETER) 31 32 @unittest.skipIf(IS_PYPY, "Prefix is incorrect and needs to be fixed.") 33 def test_prefix(self): 34 self.assertEqual(sys.prefix, ENV) 35 self.assertEqual(sys.prefix, sys.exec_prefix) 36 37 def test_site_prefix(self): 38 self.assertTrue(sys.prefix in site.PREFIXES) 39 40 @unittest.skipIf(IS_PYPY or sys.version_info.major==2, "Python 2 does not have base_prefix") 41 def test_base_prefix(self): 42 if IS_VENV or IS_VIRTUALENV: 43 self.assertNotEqual(sys.prefix, sys.base_prefix) 44 else: 45 self.assertEqual(sys.prefix, sys.base_prefix) 46 if IS_NIXENV: 47 self.assertNotEqual(sys.base_prefix, sysconfig.get_config_var('prefix')) 48 else: 49 self.assertEqual(sys.base_prefix, sysconfig.get_config_var('prefix')) 50 51 @unittest.skipIf(sys.version_info.major==3, "sys.real_prefix is only set by virtualenv in case of Python 2.") 52 def test_real_prefix(self): 53 self.assertTrue(hasattr(sys, "real_prefix") == IS_VIRTUALENV) 54 55 def test_python_version(self): 56 self.assertTrue(platform.python_version().startswith(PYTHON_VERSION)) 57 58 59if __name__ == "__main__": 60 unittest.main()