ยปCore Development>Code coverage>Lib/test/test_osx_env.py

Python code coverage for Lib/test/test_osx_env.py

#countcontent
1n/a"""
2n/aTest suite for OS X interpreter environment variables.
3n/a"""
4n/a
5n/afrom test.support import EnvironmentVarGuard
6n/aimport subprocess
7n/aimport sys
8n/aimport sysconfig
9n/aimport unittest
10n/a
11n/a@unittest.skipUnless(sys.platform == 'darwin' and
12n/a sysconfig.get_config_var('WITH_NEXT_FRAMEWORK'),
13n/a 'unnecessary on this platform')
14n/aclass OSXEnvironmentVariableTestCase(unittest.TestCase):
15n/a def _check_sys(self, ev, cond, sv, val = sys.executable + 'dummy'):
16n/a with EnvironmentVarGuard() as evg:
17n/a subpc = [str(sys.executable), '-c',
18n/a 'import sys; sys.exit(2 if "%s" %s %s else 3)' % (val, cond, sv)]
19n/a # ensure environment variable does not exist
20n/a evg.unset(ev)
21n/a # test that test on sys.xxx normally fails
22n/a rc = subprocess.call(subpc)
23n/a self.assertEqual(rc, 3, "expected %s not %s %s" % (ev, cond, sv))
24n/a # set environ variable
25n/a evg.set(ev, val)
26n/a # test that sys.xxx has been influenced by the environ value
27n/a rc = subprocess.call(subpc)
28n/a self.assertEqual(rc, 2, "expected %s %s %s" % (ev, cond, sv))
29n/a
30n/a def test_pythonexecutable_sets_sys_executable(self):
31n/a self._check_sys('PYTHONEXECUTABLE', '==', 'sys.executable')
32n/a
33n/aif __name__ == "__main__":
34n/a unittest.main()