Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes
test.test_platform.PlatformTest Class Reference

List of all members.

Public Member Functions

def test_architecture
def test_architecture_via_symlink
def test_platform
def test_system
def test_node
def test_release
def test_version
def test_machine
def test_processor
def setUp
def tearDown
def test_sys_version
def test_system_alias
def test_uname
def test_uname_win32_ARCHITEW6432
def test_java_ver
def test_win32_ver
def test_mac_ver
def test_mac_ver_with_fork
def test_dist
def test_libc_ver
def test_parse_release_file

Public Attributes

 save_version
 save_subversion
 save_mercurial
 save_platform

Detailed Description

Definition at line 9 of file test_platform.py.


Member Function Documentation

Definition at line 57 of file test_platform.py.

00057 
00058     def setUp(self):
00059         self.save_version = sys.version
00060         self.save_subversion = sys.subversion
00061         self.save_mercurial = sys._mercurial
00062         self.save_platform = sys.platform

Here is the caller graph for this function:

Definition at line 63 of file test_platform.py.

00063 
00064     def tearDown(self):
00065         sys.version = self.save_version
00066         sys.subversion = self.save_subversion
00067         sys._mercurial = self.save_mercurial
00068         sys.platform = self.save_platform

Here is the caller graph for this function:

Definition at line 10 of file test_platform.py.

00010 
00011     def test_architecture(self):
00012         res = platform.architecture()

Definition at line 14 of file test_platform.py.

00014 
00015     def test_architecture_via_symlink(self): # issue3762
00016         # On Windows, the EXE needs to know where pythonXY.dll is at so we have
00017         # to add the directory to the path.
00018         if sys.platform == "win32":
00019             os.environ["Path"] = "{};{}".format(
00020                 os.path.dirname(sys.executable), os.environ["Path"])
00021 
00022         def get(python):
00023             cmd = [python, '-c',
00024                 'import platform; print(platform.architecture())']
00025             p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
00026             return p.communicate()
00027         real = os.path.realpath(sys.executable)
00028         link = os.path.abspath(support.TESTFN)
00029         os.symlink(real, link)
00030         try:
00031             self.assertEqual(get(real), get(link))
00032         finally:
00033             os.remove(link)

Here is the call graph for this function:

Definition at line 220 of file test_platform.py.

00220 
00221     def test_dist(self):
00222         res = platform.dist()

Definition at line 161 of file test_platform.py.

00161 
00162     def test_java_ver(self):
00163         res = platform.java_ver()
00164         if sys.platform == 'java':
00165             self.assertTrue(all(res))

Here is the call graph for this function:

Definition at line 223 of file test_platform.py.

00223 
00224     def test_libc_ver(self):
00225         import os
00226         if os.path.isdir(sys.executable) and \
00227            os.path.exists(sys.executable+'.exe'):
00228             # Cygwin horror
00229             executable = sys.executable + '.exe'
00230         else:
00231             executable = sys.executable
00232         res = platform.libc_ver(executable)

Here is the call graph for this function:

Definition at line 169 of file test_platform.py.

00169 
00170     def test_mac_ver(self):
00171         res = platform.mac_ver()
00172 
00173         if platform.uname()[0] == 'Darwin':
00174             # We're on a MacOSX system, check that
00175             # the right version information is returned
00176             fd = os.popen('sw_vers', 'r')
00177             real_ver = None
00178             for ln in fd:
00179                 if ln.startswith('ProductVersion:'):
00180                     real_ver = ln.strip().split()[-1]
00181                     break
00182             fd.close()
00183             self.assertFalse(real_ver is None)
00184             result_list = res[0].split('.')
00185             expect_list = real_ver.split('.')
00186             len_diff = len(result_list) - len(expect_list)
00187             # On Snow Leopard, sw_vers reports 10.6.0 as 10.6
00188             if len_diff > 0:
00189                 expect_list.extend(['0'] * len_diff)
00190             self.assertEqual(result_list, expect_list)
00191 
00192             # res[1] claims to contain
00193             # (version, dev_stage, non_release_version)
00194             # That information is no longer available
00195             self.assertEqual(res[1], ('', '', ''))
00196 
00197             if sys.byteorder == 'little':
00198                 self.assertIn(res[2], ('i386', 'x86_64'))
00199             else:
00200                 self.assertEqual(res[2], 'PowerPC')
00201 

Here is the call graph for this function:

Definition at line 203 of file test_platform.py.

00203 
00204     def test_mac_ver_with_fork(self):
00205         # Issue7895: platform.mac_ver() crashes when using fork without exec
00206         #
00207         # This test checks that the fix for that issue works.
00208         #
00209         pid = os.fork()
00210         if pid == 0:
00211             # child
00212             info = platform.mac_ver()
00213             os._exit(0)
00214 
00215         else:
00216             # parent
00217             cpid, sts = os.waitpid(pid, 0)
00218             self.assertEqual(cpid, pid)
00219             self.assertEqual(sts, 0)

Here is the call graph for this function:

Definition at line 51 of file test_platform.py.

00051 
00052     def test_machine(self):
00053         res = platform.machine()

Definition at line 42 of file test_platform.py.

00042 
00043     def test_node(self):
00044         res = platform.node()

Definition at line 233 of file test_platform.py.

00233 
00234     def test_parse_release_file(self):
00235 
00236         for input, output in (
00237             # Examples of release file contents:
00238             ('SuSE Linux 9.3 (x86-64)', ('SuSE Linux ', '9.3', 'x86-64')),
00239             ('SUSE LINUX 10.1 (X86-64)', ('SUSE LINUX ', '10.1', 'X86-64')),
00240             ('SUSE LINUX 10.1 (i586)', ('SUSE LINUX ', '10.1', 'i586')),
00241             ('Fedora Core release 5 (Bordeaux)', ('Fedora Core', '5', 'Bordeaux')),
00242             ('Red Hat Linux release 8.0 (Psyche)', ('Red Hat Linux', '8.0', 'Psyche')),
00243             ('Red Hat Linux release 9 (Shrike)', ('Red Hat Linux', '9', 'Shrike')),
00244             ('Red Hat Enterprise Linux release 4 (Nahant)', ('Red Hat Enterprise Linux', '4', 'Nahant')),
00245             ('CentOS release 4', ('CentOS', '4', None)),
00246             ('Rocks release 4.2.1 (Cydonia)', ('Rocks', '4.2.1', 'Cydonia')),
00247             ('', ('', '', '')), # If there's nothing there.
00248             ):
00249             self.assertEqual(platform._parse_release_file(input), output)
00250 

Here is the call graph for this function:

Definition at line 34 of file test_platform.py.

00034 
00035     def test_platform(self):
00036         for aliased in (False, True):
00037             for terse in (False, True):
00038                 res = platform.platform(aliased, terse)

Definition at line 54 of file test_platform.py.

00054 
00055     def test_processor(self):
00056         res = platform.processor()

Definition at line 45 of file test_platform.py.

00045 
00046     def test_release(self):
00047         res = platform.release()

Definition at line 69 of file test_platform.py.

00069 
00070     def test_sys_version(self):
00071         # Old test.
00072         for input, output in (
00073             ('2.4.3 (#1, Jun 21 2006, 13:54:21) \n[GCC 3.3.4 (pre 3.3.5 20040809)]',
00074              ('CPython', '2.4.3', '', '', '1', 'Jun 21 2006 13:54:21', 'GCC 3.3.4 (pre 3.3.5 20040809)')),
00075             ('IronPython 1.0.60816 on .NET 2.0.50727.42',
00076              ('IronPython', '1.0.60816', '', '', '', '', '.NET 2.0.50727.42')),
00077             ('IronPython 1.0 (1.0.61005.1977) on .NET 2.0.50727.42',
00078              ('IronPython', '1.0.0', '', '', '', '', '.NET 2.0.50727.42')),
00079             ):
00080             # branch and revision are not "parsed", but fetched
00081             # from sys.subversion.  Ignore them
00082             (name, version, branch, revision, buildno, builddate, compiler) \
00083                    = platform._sys_version(input)
00084             self.assertEqual(
00085                 (name, version, '', '', buildno, builddate, compiler), output)
00086 
00087         # Tests for python_implementation(), python_version(), python_branch(),
00088         # python_revision(), python_build(), and python_compiler().
00089         sys_versions = {
00090             ("2.6.1 (r261:67515, Dec  6 2008, 15:26:00) \n[GCC 4.0.1 (Apple Computer, Inc. build 5370)]",
00091              ('CPython', 'tags/r261', '67515'), self.save_platform)
00092             :
00093                 ("CPython", "2.6.1", "tags/r261", "67515",
00094                  ('r261:67515', 'Dec  6 2008 15:26:00'),
00095                  'GCC 4.0.1 (Apple Computer, Inc. build 5370)'),
00096             ("IronPython 2.0 (2.0.0.0) on .NET 2.0.50727.3053", None, "cli")
00097             :
00098                 ("IronPython", "2.0.0", "", "", ("", ""),
00099                  ".NET 2.0.50727.3053"),
00100             ("2.5 (trunk:6107, Mar 26 2009, 13:02:18) \n[Java HotSpot(TM) Client VM (\"Apple Computer, Inc.\")]",
00101             ('Jython', 'trunk', '6107'), "java1.5.0_16")
00102             :
00103                 ("Jython", "2.5.0", "trunk", "6107",
00104                  ('trunk:6107', 'Mar 26 2009'), "java1.5.0_16"),
00105             ("2.5.2 (63378, Mar 26 2009, 18:03:29)\n[PyPy 1.0.0]",
00106              ('PyPy', 'trunk', '63378'), self.save_platform)
00107             :
00108                 ("PyPy", "2.5.2", "trunk", "63378", ('63378', 'Mar 26 2009'),
00109                  "")
00110             }
00111         for (version_tag, subversion, sys_platform), info in \
00112                 sys_versions.items():
00113             sys.version = version_tag
00114             if subversion is None:
00115                 if hasattr(sys, "_mercurial"):
00116                     del sys._mercurial
00117                 if hasattr(sys, "subversion"):
00118                     del sys.subversion
00119             else:
00120                 sys._mercurial = subversion
00121             if sys_platform is not None:
00122                 sys.platform = sys_platform
00123             self.assertEqual(platform.python_implementation(), info[0])
00124             self.assertEqual(platform.python_version(), info[1])
00125             self.assertEqual(platform.python_branch(), info[2])
00126             self.assertEqual(platform.python_revision(), info[3])
00127             self.assertEqual(platform.python_build(), info[4])
00128             self.assertEqual(platform.python_compiler(), info[5])

Here is the call graph for this function:

Definition at line 39 of file test_platform.py.

00039 
00040     def test_system(self):
00041         res = platform.system()

Definition at line 129 of file test_platform.py.

00129 
00130     def test_system_alias(self):
00131         res = platform.system_alias(
00132             platform.system(),
00133             platform.release(),
00134             platform.version(),
00135         )

Definition at line 136 of file test_platform.py.

00136 
00137     def test_uname(self):
00138         res = platform.uname()
00139         self.assertTrue(any(res))

Here is the call graph for this function:

Definition at line 141 of file test_platform.py.

00141 
00142     def test_uname_win32_ARCHITEW6432(self):
00143         # Issue 7860: make sure we get architecture from the correct variable
00144         # on 64 bit Windows: if PROCESSOR_ARCHITEW6432 exists we should be
00145         # using it, per
00146         # http://blogs.msdn.com/david.wang/archive/2006/03/26/HOWTO-Detect-Process-Bitness.aspx
00147         try:
00148             with support.EnvironmentVarGuard() as environ:
00149                 if 'PROCESSOR_ARCHITEW6432' in environ:
00150                     del environ['PROCESSOR_ARCHITEW6432']
00151                 environ['PROCESSOR_ARCHITECTURE'] = 'foo'
00152                 platform._uname_cache = None
00153                 system, node, release, version, machine, processor = platform.uname()
00154                 self.assertEqual(machine, 'foo')
00155                 environ['PROCESSOR_ARCHITEW6432'] = 'bar'
00156                 platform._uname_cache = None
00157                 system, node, release, version, machine, processor = platform.uname()
00158                 self.assertEqual(machine, 'bar')
00159         finally:
00160             platform._uname_cache = None

Here is the call graph for this function:

Definition at line 48 of file test_platform.py.

00048 
00049     def test_version(self):
00050         res = platform.version()

Definition at line 166 of file test_platform.py.

00166 
00167     def test_win32_ver(self):
00168         res = platform.win32_ver()


Member Data Documentation

Definition at line 60 of file test_platform.py.

Definition at line 61 of file test_platform.py.

Definition at line 59 of file test_platform.py.

Definition at line 58 of file test_platform.py.


The documentation for this class was generated from the following file: