1from __future__ import with_statement
2from PyObjCTools.TestSupport import *
3
4from Foundation import *
5
6
7
8class TestNSProcessInfo (TestCase):
9    def testConstants(self):
10        self.assertEqual(NSWindowsNTOperatingSystem, 1)
11        self.assertEqual(NSWindows95OperatingSystem, 2)
12        self.assertEqual(NSSolarisOperatingSystem, 3)
13        self.assertEqual(NSHPUXOperatingSystem, 4)
14        self.assertEqual(NSMACHOperatingSystem, 5)
15        self.assertEqual(NSSunOSOperatingSystem, 6)
16        self.assertEqual(NSOSF1OperatingSystem, 7)
17
18    @min_os_level('10.6')
19    def testNSDisabledSuddenTermination(self):
20        # annoyingly we cannot easily test if this has an effect, but
21        # this at least guards against typos.
22        with NSDisabledSuddenTermination():
23            pass
24
25        class TestException (Exception):
26            pass
27        try:
28            with NSDisabledSuddenTermination():
29                raise TestException(1)
30
31        except TestException:
32            pass
33
34
35    @min_os_level('10.7')
36    def testMethods10_7(self):
37        self.assertArgIsBOOL(NSProcessInfo.setAutomaticTerminationSupportEnabled_, 0)
38        self.assertResultIsBOOL(NSProcessInfo.automaticTerminationSupportEnabled)
39
40        with NSDisabledAutomaticTermination("reason"):
41            pass
42
43        class TestException (Exception):
44            pass
45        try:
46            with NSDisabledAutomaticTermination("reason"):
47                raise TestException(1)
48
49        except TestException:
50            pass
51
52if __name__ == "__main__":
53    main()
54