/Lib/test/test_platform.py

http://unladen-swallow.googlecode.com/ · Python · 140 lines · 105 code · 29 blank · 6 comment · 18 complexity · 7163bd457e91033026dc069afd7ac12b MD5 · raw file

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