2008-05-15 23:24:49 -03:00
|
|
|
import sys
|
2008-05-18 19:07:42 -03:00
|
|
|
import os
|
2005-11-21 13:48:12 -04:00
|
|
|
import unittest
|
|
|
|
import platform
|
2008-10-05 22:57:03 -03:00
|
|
|
import subprocess
|
2005-11-21 13:48:12 -04:00
|
|
|
|
2008-05-15 23:24:49 -03:00
|
|
|
from test import test_support
|
|
|
|
|
2005-11-21 13:48:12 -04:00
|
|
|
class PlatformTest(unittest.TestCase):
|
|
|
|
def test_architecture(self):
|
|
|
|
res = platform.architecture()
|
|
|
|
|
2008-10-05 22:57:03 -03:00
|
|
|
if hasattr(os, "symlink"):
|
|
|
|
def test_architecture_via_symlink(self): # issue3762
|
|
|
|
def get(python):
|
|
|
|
cmd = [python, '-c',
|
|
|
|
'import platform; print platform.architecture()']
|
|
|
|
p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
|
|
|
|
return p.communicate()
|
2008-10-05 23:41:59 -03:00
|
|
|
real = os.path.realpath(sys.executable)
|
|
|
|
link = os.path.abspath(test_support.TESTFN)
|
|
|
|
os.symlink(real, link)
|
2008-10-05 22:57:03 -03:00
|
|
|
try:
|
2008-10-05 23:41:59 -03:00
|
|
|
self.assertEqual(get(real), get(link))
|
2008-10-05 22:57:03 -03:00
|
|
|
finally:
|
2008-10-05 23:41:59 -03:00
|
|
|
os.remove(link)
|
2008-10-05 22:57:03 -03:00
|
|
|
|
2005-11-21 13:48:12 -04:00
|
|
|
def test_platform(self):
|
|
|
|
for aliased in (False, True):
|
|
|
|
for terse in (False, True):
|
|
|
|
res = platform.platform(aliased, terse)
|
|
|
|
|
2009-03-25 16:44:58 -03:00
|
|
|
def test_system(self):
|
|
|
|
res = platform.system()
|
2005-11-21 13:48:12 -04:00
|
|
|
|
2009-03-25 16:44:58 -03:00
|
|
|
def test_node(self):
|
|
|
|
res = platform.node()
|
2005-11-21 13:48:12 -04:00
|
|
|
|
2009-03-25 16:44:58 -03:00
|
|
|
def test_release(self):
|
|
|
|
res = platform.release()
|
2005-11-21 13:48:12 -04:00
|
|
|
|
|
|
|
def test_version(self):
|
2009-03-25 16:44:58 -03:00
|
|
|
res = platform.version()
|
|
|
|
|
|
|
|
def test_machine(self):
|
|
|
|
res = platform.machine()
|
|
|
|
|
|
|
|
def test_processor(self):
|
|
|
|
res = platform.processor()
|
|
|
|
|
2009-03-26 15:35:37 -03:00
|
|
|
def setUp(self):
|
|
|
|
self.save_version = sys.version
|
|
|
|
self.save_subversion = sys.subversion
|
|
|
|
self.save_platform = sys.platform
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
sys.version = self.save_version
|
|
|
|
sys.subversion = self.save_subversion
|
|
|
|
sys.platform = self.save_platform
|
|
|
|
|
2009-03-26 15:58:30 -03:00
|
|
|
def test_sys_version(self):
|
|
|
|
# Old test.
|
|
|
|
for input, output in (
|
|
|
|
('2.4.3 (#1, Jun 21 2006, 13:54:21) \n[GCC 3.3.4 (pre 3.3.5 20040809)]',
|
|
|
|
('CPython', '2.4.3', '', '', '1', 'Jun 21 2006 13:54:21', 'GCC 3.3.4 (pre 3.3.5 20040809)')),
|
|
|
|
('IronPython 1.0.60816 on .NET 2.0.50727.42',
|
|
|
|
('IronPython', '1.0.60816', '', '', '', '', '.NET 2.0.50727.42')),
|
|
|
|
('IronPython 1.0 (1.0.61005.1977) on .NET 2.0.50727.42',
|
|
|
|
('IronPython', '1.0.0', '', '', '', '', '.NET 2.0.50727.42')),
|
|
|
|
):
|
|
|
|
# branch and revision are not "parsed", but fetched
|
|
|
|
# from sys.subversion. Ignore them
|
|
|
|
(name, version, branch, revision, buildno, builddate, compiler) \
|
|
|
|
= platform._sys_version(input)
|
|
|
|
self.assertEqual(
|
|
|
|
(name, version, '', '', buildno, builddate, compiler), output)
|
|
|
|
|
2009-03-26 15:35:37 -03:00
|
|
|
# Tests for python_implementation(), python_version(), python_branch(),
|
|
|
|
# python_revision(), python_build(), and python_compiler().
|
|
|
|
sys_versions = {
|
|
|
|
("2.6.1 (r261:67515, Dec 6 2008, 15:26:00) \n[GCC 4.0.1 (Apple Computer, Inc. build 5370)]",
|
|
|
|
('CPython', 'tags/r261', '67515'), self.save_platform)
|
|
|
|
:
|
|
|
|
("CPython", "2.6.1", "tags/r261", "67515",
|
|
|
|
('r261:67515', 'Dec 6 2008 15:26:00'),
|
|
|
|
'GCC 4.0.1 (Apple Computer, Inc. build 5370)'),
|
|
|
|
("IronPython 2.0 (2.0.0.0) on .NET 2.0.50727.3053", None, "cli")
|
|
|
|
:
|
|
|
|
("IronPython", "2.0.0", "", "", ("", ""),
|
|
|
|
".NET 2.0.50727.3053"),
|
|
|
|
("2.5 (trunk:6107, Mar 26 2009, 13:02:18) \n[Java HotSpot(TM) Client VM (\"Apple Computer, Inc.\")]",
|
2009-03-26 15:55:48 -03:00
|
|
|
('Jython', 'trunk', '6107'), "java1.5.0_16")
|
2009-03-26 15:35:37 -03:00
|
|
|
:
|
2009-03-26 15:55:48 -03:00
|
|
|
("Jython", "2.5.0", "trunk", "6107",
|
|
|
|
('trunk:6107', 'Mar 26 2009'), "java1.5.0_16"),
|
2009-03-26 16:09:21 -03:00
|
|
|
("2.5.2 (63378, Mar 26 2009, 18:03:29)\n[PyPy 1.0.0]",
|
|
|
|
('PyPy', 'trunk', '63378'), self.save_platform)
|
|
|
|
:
|
|
|
|
("PyPy", "2.5.2", "trunk", "63378", ('63378', 'Mar 26 2009'),
|
|
|
|
"")
|
2009-03-26 15:35:37 -03:00
|
|
|
}
|
|
|
|
for (version_tag, subversion, sys_platform), info in \
|
|
|
|
sys_versions.iteritems():
|
|
|
|
sys.version = version_tag
|
|
|
|
if subversion is None:
|
|
|
|
if hasattr(sys, "subversion"):
|
|
|
|
del sys.subversion
|
|
|
|
else:
|
|
|
|
sys.subversion = subversion
|
|
|
|
if sys_platform is not None:
|
|
|
|
sys.platform = sys_platform
|
|
|
|
self.assertEqual(platform.python_implementation(), info[0])
|
|
|
|
self.assertEqual(platform.python_version(), info[1])
|
|
|
|
self.assertEqual(platform.python_branch(), info[2])
|
|
|
|
self.assertEqual(platform.python_revision(), info[3])
|
|
|
|
self.assertEqual(platform.python_build(), info[4])
|
|
|
|
self.assertEqual(platform.python_compiler(), info[5])
|
2005-11-21 13:48:12 -04:00
|
|
|
|
|
|
|
def test_system_alias(self):
|
|
|
|
res = platform.system_alias(
|
|
|
|
platform.system(),
|
|
|
|
platform.release(),
|
|
|
|
platform.version(),
|
|
|
|
)
|
|
|
|
|
|
|
|
def test_uname(self):
|
|
|
|
res = platform.uname()
|
2009-06-30 19:57:08 -03:00
|
|
|
self.assertTrue(any(res))
|
2005-11-21 13:48:12 -04:00
|
|
|
|
|
|
|
def test_java_ver(self):
|
|
|
|
res = platform.java_ver()
|
2008-05-15 23:24:49 -03:00
|
|
|
if sys.platform == 'java':
|
2009-06-30 19:57:08 -03:00
|
|
|
self.assertTrue(all(res))
|
2005-11-21 13:48:12 -04:00
|
|
|
|
|
|
|
def test_win32_ver(self):
|
|
|
|
res = platform.win32_ver()
|
|
|
|
|
|
|
|
def test_mac_ver(self):
|
|
|
|
res = platform.mac_ver()
|
2008-05-18 17:54:47 -03:00
|
|
|
|
2008-05-21 19:52:39 -03:00
|
|
|
try:
|
|
|
|
import gestalt
|
|
|
|
except ImportError:
|
|
|
|
have_toolbox_glue = False
|
|
|
|
else:
|
|
|
|
have_toolbox_glue = True
|
|
|
|
|
2008-06-10 19:39:25 -03:00
|
|
|
if have_toolbox_glue and platform.uname()[0] == 'Darwin':
|
2008-05-18 17:54:47 -03:00
|
|
|
# We're on a MacOSX system, check that
|
|
|
|
# the right version information is returned
|
|
|
|
fd = os.popen('sw_vers', 'r')
|
|
|
|
real_ver = None
|
|
|
|
for ln in fd:
|
|
|
|
if ln.startswith('ProductVersion:'):
|
|
|
|
real_ver = ln.strip().split()[-1]
|
|
|
|
break
|
|
|
|
fd.close()
|
2009-06-30 19:57:08 -03:00
|
|
|
self.assertFalse(real_ver is None)
|
2009-09-03 18:25:21 -03:00
|
|
|
result_list = res[0].split('.')
|
|
|
|
expect_list = real_ver.split('.')
|
|
|
|
len_diff = len(result_list) - len(expect_list)
|
|
|
|
# On Snow Leopard, sw_vers reports 10.6.0 as 10.6
|
|
|
|
if len_diff > 0:
|
|
|
|
expect_list.extend(['0'] * len_diff)
|
|
|
|
self.assertEquals(result_list, expect_list)
|
2008-05-18 17:54:47 -03:00
|
|
|
|
|
|
|
# res[1] claims to contain
|
|
|
|
# (version, dev_stage, non_release_version)
|
|
|
|
# That information is no longer available
|
|
|
|
self.assertEquals(res[1], ('', '', ''))
|
|
|
|
|
|
|
|
if sys.byteorder == 'little':
|
|
|
|
self.assertEquals(res[2], 'i386')
|
|
|
|
else:
|
|
|
|
self.assertEquals(res[2], 'PowerPC')
|
2005-11-21 13:48:12 -04:00
|
|
|
|
|
|
|
def test_dist(self):
|
|
|
|
res = platform.dist()
|
|
|
|
|
|
|
|
def test_libc_ver(self):
|
2006-04-04 12:52:00 -03:00
|
|
|
import os
|
2008-05-15 23:24:49 -03:00
|
|
|
if os.path.isdir(sys.executable) and \
|
|
|
|
os.path.exists(sys.executable+'.exe'):
|
2006-04-04 12:52:00 -03:00
|
|
|
# Cygwin horror
|
|
|
|
executable = executable + '.exe'
|
2008-05-15 23:24:49 -03:00
|
|
|
res = platform.libc_ver(sys.executable)
|
2005-11-21 13:48:12 -04:00
|
|
|
|
2008-10-21 19:01:38 -03:00
|
|
|
def test_parse_release_file(self):
|
|
|
|
|
|
|
|
for input, output in (
|
|
|
|
# Examples of release file contents:
|
|
|
|
('SuSE Linux 9.3 (x86-64)', ('SuSE Linux ', '9.3', 'x86-64')),
|
|
|
|
('SUSE LINUX 10.1 (X86-64)', ('SUSE LINUX ', '10.1', 'X86-64')),
|
|
|
|
('SUSE LINUX 10.1 (i586)', ('SUSE LINUX ', '10.1', 'i586')),
|
|
|
|
('Fedora Core release 5 (Bordeaux)', ('Fedora Core', '5', 'Bordeaux')),
|
|
|
|
('Red Hat Linux release 8.0 (Psyche)', ('Red Hat Linux', '8.0', 'Psyche')),
|
|
|
|
('Red Hat Linux release 9 (Shrike)', ('Red Hat Linux', '9', 'Shrike')),
|
|
|
|
('Red Hat Enterprise Linux release 4 (Nahant)', ('Red Hat Enterprise Linux', '4', 'Nahant')),
|
|
|
|
('CentOS release 4', ('CentOS', '4', None)),
|
|
|
|
('Rocks release 4.2.1 (Cydonia)', ('Rocks', '4.2.1', 'Cydonia')),
|
2010-01-24 23:31:13 -04:00
|
|
|
('', ('', '', '')), # If there's nothing there.
|
2008-10-21 19:01:38 -03:00
|
|
|
):
|
|
|
|
self.assertEqual(platform._parse_release_file(input), output)
|
|
|
|
|
|
|
|
|
2005-11-21 13:48:12 -04:00
|
|
|
def test_main():
|
|
|
|
test_support.run_unittest(
|
|
|
|
PlatformTest
|
|
|
|
)
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
test_main()
|