PageRenderTime 17ms CodeModel.GetById 9ms app.highlight 5ms RepoModel.GetById 2ms app.codeStats 0ms

/Lib/test/test_platform.py

http://unladen-swallow.googlecode.com/
Python | 140 lines | 111 code | 24 blank | 5 comment | 11 complexity | 7163bd457e91033026dc069afd7ac12b MD5 | raw file
  1import sys
  2import os
  3import unittest
  4import platform
  5import subprocess
  6
  7from test import test_support
  8
  9class PlatformTest(unittest.TestCase):
 10    def test_architecture(self):
 11        res = platform.architecture()
 12
 13    if hasattr(os, "symlink"):
 14        def test_architecture_via_symlink(self): # issue3762
 15            def get(python):
 16                cmd = [python, '-c',
 17                    'import platform; print platform.architecture()']
 18                p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
 19                return p.communicate()
 20            real = os.path.realpath(sys.executable)
 21            link = os.path.abspath(test_support.TESTFN)
 22            os.symlink(real, link)
 23            try:
 24                self.assertEqual(get(real), get(link))
 25            finally:
 26                os.remove(link)
 27
 28    def test_platform(self):
 29        for aliased in (False, True):
 30            for terse in (False, True):
 31                res = platform.platform(aliased, terse)
 32
 33    def test_system(self):
 34        res = platform.system()
 35
 36    def test_node(self):
 37        res = platform.node()
 38
 39    def test_release(self):
 40        res = platform.release()
 41
 42    def test_version(self):
 43        res = platform.version()
 44
 45    def test_machine(self):
 46        res = platform.machine()
 47
 48    def test_processor(self):
 49        res = platform.processor()
 50
 51    def test_python_implementation(self):
 52        res = platform.python_implementation()
 53
 54    def test_python_version(self):
 55        res1 = platform.python_version()
 56        res2 = platform.python_version_tuple()
 57        self.assertEqual(res1, ".".join(res2))
 58
 59    def test_python_branch(self):
 60        res = platform.python_branch()
 61
 62    def test_python_revision(self):
 63        res = platform.python_revision()
 64
 65    def test_python_build(self):
 66        res = platform.python_build()
 67
 68    def test_python_compiler(self):
 69        res = platform.python_compiler()
 70
 71    def test_system_alias(self):
 72        res = platform.system_alias(
 73            platform.system(),
 74            platform.release(),
 75            platform.version(),
 76        )
 77
 78    def test_uname(self):
 79        res = platform.uname()
 80        self.assert_(any(res))
 81
 82    def test_java_ver(self):
 83        res = platform.java_ver()
 84        if sys.platform == 'java':
 85            self.assert_(all(res))
 86
 87    def test_win32_ver(self):
 88        res = platform.win32_ver()
 89
 90    def test_mac_ver(self):
 91        res = platform.mac_ver()
 92
 93        try:
 94            import gestalt
 95        except ImportError:
 96            have_toolbox_glue = False
 97        else:
 98            have_toolbox_glue = True
 99
100        if have_toolbox_glue and platform.uname()[0] == 'Darwin':
101            # We're on a MacOSX system, check that
102            # the right version information is returned
103            fd = os.popen('sw_vers', 'r')
104            real_ver = None
105            for ln in fd:
106                if ln.startswith('ProductVersion:'):
107                    real_ver = ln.strip().split()[-1]
108                    break
109            fd.close()
110            self.failIf(real_ver is None)
111            self.assertEquals(res[0], real_ver)
112
113            # res[1] claims to contain
114            # (version, dev_stage, non_release_version)
115            # That information is no longer available
116            self.assertEquals(res[1], ('', '', ''))
117
118            if sys.byteorder == 'little':
119                self.assertEquals(res[2], 'i386')
120            else:
121                self.assertEquals(res[2], 'PowerPC')
122
123    def test_dist(self):
124        res = platform.dist()
125
126    def test_libc_ver(self):
127        import os
128        if os.path.isdir(sys.executable) and \
129           os.path.exists(sys.executable+'.exe'):
130            # Cygwin horror
131            executable = executable + '.exe'
132        res = platform.libc_ver(sys.executable)
133
134def test_main():
135    test_support.run_unittest(
136        PlatformTest
137    )
138
139if __name__ == '__main__':
140    test_main()