home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2011 June / maximum-cd-2011-06.iso / DiscContents / LibO_3.3.1_Win_x86_install_multi.exe / libreoffice1.cab / test_platform.py < prev    next >
Encoding:
Python Source  |  2011-02-15  |  3.6 KB  |  132 lines

  1. import sys
  2. import os
  3. import unittest
  4. import platform
  5. import subprocess
  6.  
  7. from test import test_support
  8.  
  9. class 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_machine(self):
  29.         res = platform.machine()
  30.  
  31.     def test_node(self):
  32.         res = platform.node()
  33.  
  34.     def test_platform(self):
  35.         for aliased in (False, True):
  36.             for terse in (False, True):
  37.                 res = platform.platform(aliased, terse)
  38.  
  39.     def test_processor(self):
  40.         res = platform.processor()
  41.  
  42.     def test_python_build(self):
  43.         res = platform.python_build()
  44.  
  45.     def test_python_compiler(self):
  46.         res = platform.python_compiler()
  47.  
  48.     def test_version(self):
  49.         res1 = platform.version()
  50.         res2 = platform.version_tuple()
  51.         self.assertEqual(res1, ".".join(res2))
  52.  
  53.     def test_release(self):
  54.         res = platform.release()
  55.  
  56.     def test_system(self):
  57.         res = platform.system()
  58.  
  59.     def test_version(self):
  60.         res = platform.version()
  61.  
  62.     def test_system_alias(self):
  63.         res = platform.system_alias(
  64.             platform.system(),
  65.             platform.release(),
  66.             platform.version(),
  67.         )
  68.  
  69.     def test_uname(self):
  70.         res = platform.uname()
  71.         self.assert_(any(res))
  72.  
  73.     def test_java_ver(self):
  74.         res = platform.java_ver()
  75.         if sys.platform == 'java':
  76.             self.assert_(all(res))
  77.  
  78.     def test_win32_ver(self):
  79.         res = platform.win32_ver()
  80.  
  81.     def test_mac_ver(self):
  82.         res = platform.mac_ver()
  83.  
  84.         try:
  85.             import gestalt
  86.         except ImportError:
  87.             have_toolbox_glue = False
  88.         else:
  89.             have_toolbox_glue = True
  90.  
  91.         if have_toolbox_glue and platform.uname()[0] == 'Darwin':
  92.             # We're on a MacOSX system, check that
  93.             # the right version information is returned
  94.             fd = os.popen('sw_vers', 'r')
  95.             real_ver = None
  96.             for ln in fd:
  97.                 if ln.startswith('ProductVersion:'):
  98.                     real_ver = ln.strip().split()[-1]
  99.                     break
  100.             fd.close()
  101.             self.failIf(real_ver is None)
  102.             self.assertEquals(res[0], real_ver)
  103.  
  104.             # res[1] claims to contain
  105.             # (version, dev_stage, non_release_version)
  106.             # That information is no longer available
  107.             self.assertEquals(res[1], ('', '', ''))
  108.  
  109.             if sys.byteorder == 'little':
  110.                 self.assertEquals(res[2], 'i386')
  111.             else:
  112.                 self.assertEquals(res[2], 'PowerPC')
  113.  
  114.     def test_dist(self):
  115.         res = platform.dist()
  116.  
  117.     def test_libc_ver(self):
  118.         import os
  119.         if os.path.isdir(sys.executable) and \
  120.            os.path.exists(sys.executable+'.exe'):
  121.             # Cygwin horror
  122.             executable = executable + '.exe'
  123.         res = platform.libc_ver(sys.executable)
  124.  
  125. def test_main():
  126.     test_support.run_unittest(
  127.         PlatformTest
  128.     )
  129.  
  130. if __name__ == '__main__':
  131.     test_main()
  132.