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-09 15:06:58 -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-09 15:06:58 -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()
|
|
|
|
real = os.path.realpath(sys.executable)
|
|
|
|
link = os.path.abspath(test_support.TESTFN)
|
|
|
|
os.symlink(real, link)
|
|
|
|
try:
|
|
|
|
self.assertEqual(get(real), get(link))
|
|
|
|
finally:
|
|
|
|
os.remove(link)
|
|
|
|
|
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:52:04 -03:00
|
|
|
def test_system(self):
|
|
|
|
res = platform.system()
|
2005-11-21 13:48:12 -04:00
|
|
|
|
2009-03-25 16:52:04 -03:00
|
|
|
def test_node(self):
|
|
|
|
res = platform.node()
|
2005-11-21 13:48:12 -04:00
|
|
|
|
2009-03-25 16:52:04 -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:52:04 -03:00
|
|
|
res = platform.version()
|
|
|
|
|
|
|
|
def test_machine(self):
|
|
|
|
res = platform.machine()
|
|
|
|
|
|
|
|
def test_processor(self):
|
|
|
|
res = platform.processor()
|
|
|
|
|
|
|
|
def test_python_implementation(self):
|
|
|
|
res = platform.python_implementation()
|
|
|
|
|
|
|
|
def test_python_version(self):
|
|
|
|
res1 = platform.python_version()
|
|
|
|
res2 = platform.python_version_tuple()
|
2005-11-21 13:48:12 -04:00
|
|
|
self.assertEqual(res1, ".".join(res2))
|
|
|
|
|
2009-03-25 16:52:04 -03:00
|
|
|
def test_python_branch(self):
|
|
|
|
res = platform.python_branch()
|
2005-11-21 13:48:12 -04:00
|
|
|
|
2009-03-25 16:52:04 -03:00
|
|
|
def test_python_revision(self):
|
|
|
|
res = platform.python_revision()
|
2005-11-21 13:48:12 -04:00
|
|
|
|
2009-03-25 16:52:04 -03:00
|
|
|
def test_python_build(self):
|
|
|
|
res = platform.python_build()
|
|
|
|
|
|
|
|
def test_python_compiler(self):
|
|
|
|
res = platform.python_compiler()
|
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()
|
2008-05-15 23:24:49 -03:00
|
|
|
self.assert_(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':
|
|
|
|
self.assert_(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()
|
|
|
|
self.failIf(real_ver is None)
|
|
|
|
self.assertEquals(res[0], real_ver)
|
|
|
|
|
|
|
|
# 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
|
Merged revisions 78035,78040,78043,78049-78050,78052-78054 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r78035 | georg.brandl | 2010-02-06 23:44:17 +0100 (Sa, 06 Feb 2010) | 1 line
Fix duplicate import.
........
r78040 | georg.brandl | 2010-02-07 00:08:00 +0100 (So, 07 Feb 2010) | 1 line
Fix a few UnboundLocalErrors in test_long.
........
r78043 | georg.brandl | 2010-02-07 00:12:19 +0100 (So, 07 Feb 2010) | 1 line
Remove duplicate test method.
........
r78049 | georg.brandl | 2010-02-07 00:33:33 +0100 (So, 07 Feb 2010) | 1 line
Fix import/access for some identifiers. _TestSharedCTypes does not seem to be executed?
........
r78050 | georg.brandl | 2010-02-07 00:34:10 +0100 (So, 07 Feb 2010) | 1 line
Fix more unbound locals in code paths that do not seem to be used.
........
r78052 | georg.brandl | 2010-02-07 00:54:04 +0100 (So, 07 Feb 2010) | 1 line
Add missing import when running these tests standalone.
........
r78053 | georg.brandl | 2010-02-07 00:54:43 +0100 (So, 07 Feb 2010) | 1 line
Fix some name errors in Mac modules.
........
r78054 | georg.brandl | 2010-02-07 00:58:25 +0100 (So, 07 Feb 2010) | 1 line
Add missing import.
........
2010-02-07 08:01:19 -04:00
|
|
|
executable = sys.executable + '.exe'
|
|
|
|
else:
|
|
|
|
executable = sys.executable
|
|
|
|
res = platform.libc_ver(executable)
|
2005-11-21 13:48:12 -04:00
|
|
|
|
2010-01-24 23:35:04 -04: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')),
|
|
|
|
('', ('', '', '')), # If there's nothing there.
|
|
|
|
):
|
|
|
|
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()
|