1 # Copyright (c) Twisted Matrix Laboratories.
2 # See LICENSE for details.
5 Tests for runtime checks.
10 from twisted.python.runtime import Platform
11 from twisted.trial.unittest import TestCase
15 class PlatformTests(TestCase):
17 Tests for the default L{Platform} initializer.
20 def test_isVistaConsistency(self):
22 Verify consistency of L{Platform.isVista}: it can only be C{True} if
23 L{Platform.isWinNT} and L{Platform.isWindows} are C{True}.
26 if platform.isVista():
27 self.assertTrue(platform.isWinNT())
28 self.assertTrue(platform.isWindows())
29 self.assertFalse(platform.isMacOSX())
32 def test_isMacOSXConsistency(self):
34 L{Platform.isMacOSX} can only return C{True} if L{Platform.getType}
38 if platform.isMacOSX():
39 self.assertEqual(platform.getType(), 'posix')
42 def test_isLinuxConsistency(self):
44 L{Platform.isLinux} can only return C{True} if L{Platform.getType}
45 returns C{'posix'} and L{sys.platform} starts with C{"linux"}.
48 if platform.isLinux():
49 self.assertTrue(sys.platform.startswith("linux"))
53 class ForeignPlatformTests(TestCase):
55 Tests for L{Platform} based overridden initializer values.
58 def test_getType(self):
60 If an operating system name is supplied to L{Platform}'s initializer,
61 L{Platform.getType} returns the platform type which corresponds to that
64 self.assertEqual(Platform('nt').getType(), 'win32')
65 self.assertEqual(Platform('ce').getType(), 'win32')
66 self.assertEqual(Platform('posix').getType(), 'posix')
67 self.assertEqual(Platform('java').getType(), 'java')
70 def test_isMacOSX(self):
72 If a system platform name is supplied to L{Platform}'s initializer, it
73 is used to determine the result of L{Platform.isMacOSX}, which returns
74 C{True} for C{"darwin"}, C{False} otherwise.
76 self.assertTrue(Platform(None, 'darwin').isMacOSX())
77 self.assertFalse(Platform(None, 'linux2').isMacOSX())
78 self.assertFalse(Platform(None, 'win32').isMacOSX())
81 def test_isLinux(self):
83 If a system platform name is supplied to L{Platform}'s initializer, it
84 is used to determine the result of L{Platform.isLinux}, which returns
85 C{True} for values beginning with C{"linux"}, C{False} otherwise.
87 self.assertFalse(Platform(None, 'darwin').isLinux())
88 self.assertTrue(Platform(None, 'linux').isLinux())
89 self.assertTrue(Platform(None, 'linux2').isLinux())
90 self.assertTrue(Platform(None, 'linux3').isLinux())
91 self.assertFalse(Platform(None, 'win32').isLinux())