~ubuntu-branches/ubuntu/maverick/python3.1/maverick

« back to all changes in this revision

Viewing changes to Lib/test/test_osx_env.py

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2009-03-23 00:01:27 UTC
  • Revision ID: james.westby@ubuntu.com-20090323000127-5fstfxju4ufrhthq
Tags: upstream-3.1~a1+20090322
ImportĀ upstreamĀ versionĀ 3.1~a1+20090322

Show diffs side-by-side

added added

removed removed

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