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