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