annotate Lib/test/test_platform.py @ 58765:2ba7677bfa95 legacy-trunk

testCopysign was defined twice in test_math; combine the definitions
author Mark Dickinson <dickinsm@gmail.com>
date Sat, 06 Feb 2010 23:11:25 +0000
parents 5c1d7a3ba29c
children c58ed2554f5c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
47079
3407bf9dac38 make test_platform a bit more assertive (We'll see what the buildbots say.)
Benjamin Peterson <benjamin@python.org>
parents: 37472
diff changeset
1 import sys
47168
95cb009366dc fix test_platform (os was not imported)
Benjamin Peterson <benjamin@python.org>
parents: 47165
diff changeset
2 import os
35900
e9be9e6188f4 Add a rudimentary test for the platform module that at least calls each
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
3 import unittest
47079
3407bf9dac38 make test_platform a bit more assertive (We'll see what the buildbots say.)
Benjamin Peterson <benjamin@python.org>
parents: 37472
diff changeset
4 import platform
49439
524ac744ae04 Added the test for issue3762.
Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>
parents: 47571
diff changeset
5 import subprocess
47079
3407bf9dac38 make test_platform a bit more assertive (We'll see what the buildbots say.)
Benjamin Peterson <benjamin@python.org>
parents: 37472
diff changeset
6
35900
e9be9e6188f4 Add a rudimentary test for the platform module that at least calls each
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
7 from test import test_support
e9be9e6188f4 Add a rudimentary test for the platform module that at least calls each
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
8
e9be9e6188f4 Add a rudimentary test for the platform module that at least calls each
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
9 class PlatformTest(unittest.TestCase):
e9be9e6188f4 Add a rudimentary test for the platform module that at least calls each
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
10 def test_architecture(self):
e9be9e6188f4 Add a rudimentary test for the platform module that at least calls each
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
11 res = platform.architecture()
e9be9e6188f4 Add a rudimentary test for the platform module that at least calls each
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
12
49439
524ac744ae04 Added the test for issue3762.
Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>
parents: 47571
diff changeset
13 if hasattr(os, "symlink"):
524ac744ae04 Added the test for issue3762.
Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>
parents: 47571
diff changeset
14 def test_architecture_via_symlink(self): # issue3762
524ac744ae04 Added the test for issue3762.
Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>
parents: 47571
diff changeset
15 def get(python):
524ac744ae04 Added the test for issue3762.
Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>
parents: 47571
diff changeset
16 cmd = [python, '-c',
524ac744ae04 Added the test for issue3762.
Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>
parents: 47571
diff changeset
17 'import platform; print platform.architecture()']
524ac744ae04 Added the test for issue3762.
Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>
parents: 47571
diff changeset
18 p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
524ac744ae04 Added the test for issue3762.
Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>
parents: 47571
diff changeset
19 return p.communicate()
49440
dc95e46f1f3e More strict test. Consider the case sys.executable itself is symlink.
Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>
parents: 49439
diff changeset
20 real = os.path.realpath(sys.executable)
dc95e46f1f3e More strict test. Consider the case sys.executable itself is symlink.
Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>
parents: 49439
diff changeset
21 link = os.path.abspath(test_support.TESTFN)
dc95e46f1f3e More strict test. Consider the case sys.executable itself is symlink.
Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>
parents: 49439
diff changeset
22 os.symlink(real, link)
49439
524ac744ae04 Added the test for issue3762.
Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>
parents: 47571
diff changeset
23 try:
49440
dc95e46f1f3e More strict test. Consider the case sys.executable itself is symlink.
Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>
parents: 49439
diff changeset
24 self.assertEqual(get(real), get(link))
49439
524ac744ae04 Added the test for issue3762.
Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>
parents: 47571
diff changeset
25 finally:
49440
dc95e46f1f3e More strict test. Consider the case sys.executable itself is symlink.
Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>
parents: 49439
diff changeset
26 os.remove(link)
49439
524ac744ae04 Added the test for issue3762.
Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>
parents: 47571
diff changeset
27
35900
e9be9e6188f4 Add a rudimentary test for the platform module that at least calls each
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
28 def test_platform(self):
e9be9e6188f4 Add a rudimentary test for the platform module that at least calls each
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
29 for aliased in (False, True):
e9be9e6188f4 Add a rudimentary test for the platform module that at least calls each
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
30 for terse in (False, True):
e9be9e6188f4 Add a rudimentary test for the platform module that at least calls each
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
31 res = platform.platform(aliased, terse)
e9be9e6188f4 Add a rudimentary test for the platform module that at least calls each
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
32
52330
7d0e3a8c2e9e Remove the sys.version_info shortcut, since they cause the APIs
Marc-André Lemburg <mal@egenix.com>
parents: 49565
diff changeset
33 def test_system(self):
7d0e3a8c2e9e Remove the sys.version_info shortcut, since they cause the APIs
Marc-André Lemburg <mal@egenix.com>
parents: 49565
diff changeset
34 res = platform.system()
7d0e3a8c2e9e Remove the sys.version_info shortcut, since they cause the APIs
Marc-André Lemburg <mal@egenix.com>
parents: 49565
diff changeset
35
7d0e3a8c2e9e Remove the sys.version_info shortcut, since they cause the APIs
Marc-André Lemburg <mal@egenix.com>
parents: 49565
diff changeset
36 def test_node(self):
7d0e3a8c2e9e Remove the sys.version_info shortcut, since they cause the APIs
Marc-André Lemburg <mal@egenix.com>
parents: 49565
diff changeset
37 res = platform.node()
7d0e3a8c2e9e Remove the sys.version_info shortcut, since they cause the APIs
Marc-André Lemburg <mal@egenix.com>
parents: 49565
diff changeset
38
7d0e3a8c2e9e Remove the sys.version_info shortcut, since they cause the APIs
Marc-André Lemburg <mal@egenix.com>
parents: 49565
diff changeset
39 def test_release(self):
7d0e3a8c2e9e Remove the sys.version_info shortcut, since they cause the APIs
Marc-André Lemburg <mal@egenix.com>
parents: 49565
diff changeset
40 res = platform.release()
7d0e3a8c2e9e Remove the sys.version_info shortcut, since they cause the APIs
Marc-André Lemburg <mal@egenix.com>
parents: 49565
diff changeset
41
7d0e3a8c2e9e Remove the sys.version_info shortcut, since they cause the APIs
Marc-André Lemburg <mal@egenix.com>
parents: 49565
diff changeset
42 def test_version(self):
7d0e3a8c2e9e Remove the sys.version_info shortcut, since they cause the APIs
Marc-André Lemburg <mal@egenix.com>
parents: 49565
diff changeset
43 res = platform.version()
7d0e3a8c2e9e Remove the sys.version_info shortcut, since they cause the APIs
Marc-André Lemburg <mal@egenix.com>
parents: 49565
diff changeset
44
7d0e3a8c2e9e Remove the sys.version_info shortcut, since they cause the APIs
Marc-André Lemburg <mal@egenix.com>
parents: 49565
diff changeset
45 def test_machine(self):
7d0e3a8c2e9e Remove the sys.version_info shortcut, since they cause the APIs
Marc-André Lemburg <mal@egenix.com>
parents: 49565
diff changeset
46 res = platform.machine()
7d0e3a8c2e9e Remove the sys.version_info shortcut, since they cause the APIs
Marc-André Lemburg <mal@egenix.com>
parents: 49565
diff changeset
47
35900
e9be9e6188f4 Add a rudimentary test for the platform module that at least calls each
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
48 def test_processor(self):
e9be9e6188f4 Add a rudimentary test for the platform module that at least calls each
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
49 res = platform.processor()
e9be9e6188f4 Add a rudimentary test for the platform module that at least calls each
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
50
52346
1e2335962bad add much better tests for python version information parsing
Benjamin Peterson <benjamin@python.org>
parents: 52330
diff changeset
51 def setUp(self):
1e2335962bad add much better tests for python version information parsing
Benjamin Peterson <benjamin@python.org>
parents: 52330
diff changeset
52 self.save_version = sys.version
1e2335962bad add much better tests for python version information parsing
Benjamin Peterson <benjamin@python.org>
parents: 52330
diff changeset
53 self.save_subversion = sys.subversion
1e2335962bad add much better tests for python version information parsing
Benjamin Peterson <benjamin@python.org>
parents: 52330
diff changeset
54 self.save_platform = sys.platform
52330
7d0e3a8c2e9e Remove the sys.version_info shortcut, since they cause the APIs
Marc-André Lemburg <mal@egenix.com>
parents: 49565
diff changeset
55
52346
1e2335962bad add much better tests for python version information parsing
Benjamin Peterson <benjamin@python.org>
parents: 52330
diff changeset
56 def tearDown(self):
1e2335962bad add much better tests for python version information parsing
Benjamin Peterson <benjamin@python.org>
parents: 52330
diff changeset
57 sys.version = self.save_version
1e2335962bad add much better tests for python version information parsing
Benjamin Peterson <benjamin@python.org>
parents: 52330
diff changeset
58 sys.subversion = self.save_subversion
1e2335962bad add much better tests for python version information parsing
Benjamin Peterson <benjamin@python.org>
parents: 52330
diff changeset
59 sys.platform = self.save_platform
52330
7d0e3a8c2e9e Remove the sys.version_info shortcut, since they cause the APIs
Marc-André Lemburg <mal@egenix.com>
parents: 49565
diff changeset
60
52348
0a052a2873b2 roll old test in with new one
Benjamin Peterson <benjamin@python.org>
parents: 52347
diff changeset
61 def test_sys_version(self):
0a052a2873b2 roll old test in with new one
Benjamin Peterson <benjamin@python.org>
parents: 52347
diff changeset
62 # Old test.
0a052a2873b2 roll old test in with new one
Benjamin Peterson <benjamin@python.org>
parents: 52347
diff changeset
63 for input, output in (
0a052a2873b2 roll old test in with new one
Benjamin Peterson <benjamin@python.org>
parents: 52347
diff changeset
64 ('2.4.3 (#1, Jun 21 2006, 13:54:21) \n[GCC 3.3.4 (pre 3.3.5 20040809)]',
0a052a2873b2 roll old test in with new one
Benjamin Peterson <benjamin@python.org>
parents: 52347
diff changeset
65 ('CPython', '2.4.3', '', '', '1', 'Jun 21 2006 13:54:21', 'GCC 3.3.4 (pre 3.3.5 20040809)')),
0a052a2873b2 roll old test in with new one
Benjamin Peterson <benjamin@python.org>
parents: 52347
diff changeset
66 ('IronPython 1.0.60816 on .NET 2.0.50727.42',
0a052a2873b2 roll old test in with new one
Benjamin Peterson <benjamin@python.org>
parents: 52347
diff changeset
67 ('IronPython', '1.0.60816', '', '', '', '', '.NET 2.0.50727.42')),
0a052a2873b2 roll old test in with new one
Benjamin Peterson <benjamin@python.org>
parents: 52347
diff changeset
68 ('IronPython 1.0 (1.0.61005.1977) on .NET 2.0.50727.42',
0a052a2873b2 roll old test in with new one
Benjamin Peterson <benjamin@python.org>
parents: 52347
diff changeset
69 ('IronPython', '1.0.0', '', '', '', '', '.NET 2.0.50727.42')),
0a052a2873b2 roll old test in with new one
Benjamin Peterson <benjamin@python.org>
parents: 52347
diff changeset
70 ):
0a052a2873b2 roll old test in with new one
Benjamin Peterson <benjamin@python.org>
parents: 52347
diff changeset
71 # branch and revision are not "parsed", but fetched
0a052a2873b2 roll old test in with new one
Benjamin Peterson <benjamin@python.org>
parents: 52347
diff changeset
72 # from sys.subversion. Ignore them
0a052a2873b2 roll old test in with new one
Benjamin Peterson <benjamin@python.org>
parents: 52347
diff changeset
73 (name, version, branch, revision, buildno, builddate, compiler) \
0a052a2873b2 roll old test in with new one
Benjamin Peterson <benjamin@python.org>
parents: 52347
diff changeset
74 = platform._sys_version(input)
0a052a2873b2 roll old test in with new one
Benjamin Peterson <benjamin@python.org>
parents: 52347
diff changeset
75 self.assertEqual(
0a052a2873b2 roll old test in with new one
Benjamin Peterson <benjamin@python.org>
parents: 52347
diff changeset
76 (name, version, '', '', buildno, builddate, compiler), output)
0a052a2873b2 roll old test in with new one
Benjamin Peterson <benjamin@python.org>
parents: 52347
diff changeset
77
52346
1e2335962bad add much better tests for python version information parsing
Benjamin Peterson <benjamin@python.org>
parents: 52330
diff changeset
78 # Tests for python_implementation(), python_version(), python_branch(),
1e2335962bad add much better tests for python version information parsing
Benjamin Peterson <benjamin@python.org>
parents: 52330
diff changeset
79 # python_revision(), python_build(), and python_compiler().
1e2335962bad add much better tests for python version information parsing
Benjamin Peterson <benjamin@python.org>
parents: 52330
diff changeset
80 sys_versions = {
1e2335962bad add much better tests for python version information parsing
Benjamin Peterson <benjamin@python.org>
parents: 52330
diff changeset
81 ("2.6.1 (r261:67515, Dec 6 2008, 15:26:00) \n[GCC 4.0.1 (Apple Computer, Inc. build 5370)]",
1e2335962bad add much better tests for python version information parsing
Benjamin Peterson <benjamin@python.org>
parents: 52330
diff changeset
82 ('CPython', 'tags/r261', '67515'), self.save_platform)
1e2335962bad add much better tests for python version information parsing
Benjamin Peterson <benjamin@python.org>
parents: 52330
diff changeset
83 :
1e2335962bad add much better tests for python version information parsing
Benjamin Peterson <benjamin@python.org>
parents: 52330
diff changeset
84 ("CPython", "2.6.1", "tags/r261", "67515",
1e2335962bad add much better tests for python version information parsing
Benjamin Peterson <benjamin@python.org>
parents: 52330
diff changeset
85 ('r261:67515', 'Dec 6 2008 15:26:00'),
1e2335962bad add much better tests for python version information parsing
Benjamin Peterson <benjamin@python.org>
parents: 52330
diff changeset
86 'GCC 4.0.1 (Apple Computer, Inc. build 5370)'),
1e2335962bad add much better tests for python version information parsing
Benjamin Peterson <benjamin@python.org>
parents: 52330
diff changeset
87 ("IronPython 2.0 (2.0.0.0) on .NET 2.0.50727.3053", None, "cli")
1e2335962bad add much better tests for python version information parsing
Benjamin Peterson <benjamin@python.org>
parents: 52330
diff changeset
88 :
1e2335962bad add much better tests for python version information parsing
Benjamin Peterson <benjamin@python.org>
parents: 52330
diff changeset
89 ("IronPython", "2.0.0", "", "", ("", ""),
1e2335962bad add much better tests for python version information parsing
Benjamin Peterson <benjamin@python.org>
parents: 52330
diff changeset
90 ".NET 2.0.50727.3053"),
1e2335962bad add much better tests for python version information parsing
Benjamin Peterson <benjamin@python.org>
parents: 52330
diff changeset
91 ("2.5 (trunk:6107, Mar 26 2009, 13:02:18) \n[Java HotSpot(TM) Client VM (\"Apple Computer, Inc.\")]",
52347
78fedc342a6b more and more implementations now support sys.subversion
Benjamin Peterson <benjamin@python.org>
parents: 52346
diff changeset
92 ('Jython', 'trunk', '6107'), "java1.5.0_16")
52346
1e2335962bad add much better tests for python version information parsing
Benjamin Peterson <benjamin@python.org>
parents: 52330
diff changeset
93 :
52347
78fedc342a6b more and more implementations now support sys.subversion
Benjamin Peterson <benjamin@python.org>
parents: 52346
diff changeset
94 ("Jython", "2.5.0", "trunk", "6107",
78fedc342a6b more and more implementations now support sys.subversion
Benjamin Peterson <benjamin@python.org>
parents: 52346
diff changeset
95 ('trunk:6107', 'Mar 26 2009'), "java1.5.0_16"),
52349
007e9c86fb55 add support for PyPy
Benjamin Peterson <benjamin@python.org>
parents: 52348
diff changeset
96 ("2.5.2 (63378, Mar 26 2009, 18:03:29)\n[PyPy 1.0.0]",
007e9c86fb55 add support for PyPy
Benjamin Peterson <benjamin@python.org>
parents: 52348
diff changeset
97 ('PyPy', 'trunk', '63378'), self.save_platform)
007e9c86fb55 add support for PyPy
Benjamin Peterson <benjamin@python.org>
parents: 52348
diff changeset
98 :
007e9c86fb55 add support for PyPy
Benjamin Peterson <benjamin@python.org>
parents: 52348
diff changeset
99 ("PyPy", "2.5.2", "trunk", "63378", ('63378', 'Mar 26 2009'),
007e9c86fb55 add support for PyPy
Benjamin Peterson <benjamin@python.org>
parents: 52348
diff changeset
100 "")
52346
1e2335962bad add much better tests for python version information parsing
Benjamin Peterson <benjamin@python.org>
parents: 52330
diff changeset
101 }
1e2335962bad add much better tests for python version information parsing
Benjamin Peterson <benjamin@python.org>
parents: 52330
diff changeset
102 for (version_tag, subversion, sys_platform), info in \
1e2335962bad add much better tests for python version information parsing
Benjamin Peterson <benjamin@python.org>
parents: 52330
diff changeset
103 sys_versions.iteritems():
1e2335962bad add much better tests for python version information parsing
Benjamin Peterson <benjamin@python.org>
parents: 52330
diff changeset
104 sys.version = version_tag
1e2335962bad add much better tests for python version information parsing
Benjamin Peterson <benjamin@python.org>
parents: 52330
diff changeset
105 if subversion is None:
1e2335962bad add much better tests for python version information parsing
Benjamin Peterson <benjamin@python.org>
parents: 52330
diff changeset
106 if hasattr(sys, "subversion"):
1e2335962bad add much better tests for python version information parsing
Benjamin Peterson <benjamin@python.org>
parents: 52330
diff changeset
107 del sys.subversion
1e2335962bad add much better tests for python version information parsing
Benjamin Peterson <benjamin@python.org>
parents: 52330
diff changeset
108 else:
1e2335962bad add much better tests for python version information parsing
Benjamin Peterson <benjamin@python.org>
parents: 52330
diff changeset
109 sys.subversion = subversion
1e2335962bad add much better tests for python version information parsing
Benjamin Peterson <benjamin@python.org>
parents: 52330
diff changeset
110 if sys_platform is not None:
1e2335962bad add much better tests for python version information parsing
Benjamin Peterson <benjamin@python.org>
parents: 52330
diff changeset
111 sys.platform = sys_platform
1e2335962bad add much better tests for python version information parsing
Benjamin Peterson <benjamin@python.org>
parents: 52330
diff changeset
112 self.assertEqual(platform.python_implementation(), info[0])
1e2335962bad add much better tests for python version information parsing
Benjamin Peterson <benjamin@python.org>
parents: 52330
diff changeset
113 self.assertEqual(platform.python_version(), info[1])
1e2335962bad add much better tests for python version information parsing
Benjamin Peterson <benjamin@python.org>
parents: 52330
diff changeset
114 self.assertEqual(platform.python_branch(), info[2])
1e2335962bad add much better tests for python version information parsing
Benjamin Peterson <benjamin@python.org>
parents: 52330
diff changeset
115 self.assertEqual(platform.python_revision(), info[3])
1e2335962bad add much better tests for python version information parsing
Benjamin Peterson <benjamin@python.org>
parents: 52330
diff changeset
116 self.assertEqual(platform.python_build(), info[4])
1e2335962bad add much better tests for python version information parsing
Benjamin Peterson <benjamin@python.org>
parents: 52330
diff changeset
117 self.assertEqual(platform.python_compiler(), info[5])
35900
e9be9e6188f4 Add a rudimentary test for the platform module that at least calls each
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
118
e9be9e6188f4 Add a rudimentary test for the platform module that at least calls each
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
119 def test_system_alias(self):
e9be9e6188f4 Add a rudimentary test for the platform module that at least calls each
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
120 res = platform.system_alias(
e9be9e6188f4 Add a rudimentary test for the platform module that at least calls each
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
121 platform.system(),
e9be9e6188f4 Add a rudimentary test for the platform module that at least calls each
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
122 platform.release(),
e9be9e6188f4 Add a rudimentary test for the platform module that at least calls each
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
123 platform.version(),
e9be9e6188f4 Add a rudimentary test for the platform module that at least calls each
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
124 )
e9be9e6188f4 Add a rudimentary test for the platform module that at least calls each
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
125
e9be9e6188f4 Add a rudimentary test for the platform module that at least calls each
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
126 def test_uname(self):
e9be9e6188f4 Add a rudimentary test for the platform module that at least calls each
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
127 res = platform.uname()
55002
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 52349
diff changeset
128 self.assertTrue(any(res))
35900
e9be9e6188f4 Add a rudimentary test for the platform module that at least calls each
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
129
e9be9e6188f4 Add a rudimentary test for the platform module that at least calls each
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
130 def test_java_ver(self):
e9be9e6188f4 Add a rudimentary test for the platform module that at least calls each
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
131 res = platform.java_ver()
47079
3407bf9dac38 make test_platform a bit more assertive (We'll see what the buildbots say.)
Benjamin Peterson <benjamin@python.org>
parents: 37472
diff changeset
132 if sys.platform == 'java':
55002
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 52349
diff changeset
133 self.assertTrue(all(res))
35900
e9be9e6188f4 Add a rudimentary test for the platform module that at least calls each
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
134
e9be9e6188f4 Add a rudimentary test for the platform module that at least calls each
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
135 def test_win32_ver(self):
e9be9e6188f4 Add a rudimentary test for the platform module that at least calls each
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
136 res = platform.win32_ver()
e9be9e6188f4 Add a rudimentary test for the platform module that at least calls each
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
137
e9be9e6188f4 Add a rudimentary test for the platform module that at least calls each
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
138 def test_mac_ver(self):
e9be9e6188f4 Add a rudimentary test for the platform module that at least calls each
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
139 res = platform.mac_ver()
47165
cd91daf0327c - Add unittests for platform.mac_ver (or rather, ensure that the unittest for
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 47079
diff changeset
140
47208
5be2d82ac5ac check for toolbox glue before testing platform.mac_ver intensly
Benjamin Peterson <benjamin@python.org>
parents: 47168
diff changeset
141 try:
5be2d82ac5ac check for toolbox glue before testing platform.mac_ver intensly
Benjamin Peterson <benjamin@python.org>
parents: 47168
diff changeset
142 import gestalt
5be2d82ac5ac check for toolbox glue before testing platform.mac_ver intensly
Benjamin Peterson <benjamin@python.org>
parents: 47168
diff changeset
143 except ImportError:
5be2d82ac5ac check for toolbox glue before testing platform.mac_ver intensly
Benjamin Peterson <benjamin@python.org>
parents: 47168
diff changeset
144 have_toolbox_glue = False
5be2d82ac5ac check for toolbox glue before testing platform.mac_ver intensly
Benjamin Peterson <benjamin@python.org>
parents: 47168
diff changeset
145 else:
5be2d82ac5ac check for toolbox glue before testing platform.mac_ver intensly
Benjamin Peterson <benjamin@python.org>
parents: 47168
diff changeset
146 have_toolbox_glue = True
5be2d82ac5ac check for toolbox glue before testing platform.mac_ver intensly
Benjamin Peterson <benjamin@python.org>
parents: 47168
diff changeset
147
47571
271845f323be backport of 64096
Benjamin Peterson <benjamin@python.org>
parents: 47208
diff changeset
148 if have_toolbox_glue and platform.uname()[0] == 'Darwin':
47165
cd91daf0327c - Add unittests for platform.mac_ver (or rather, ensure that the unittest for
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 47079
diff changeset
149 # We're on a MacOSX system, check that
cd91daf0327c - Add unittests for platform.mac_ver (or rather, ensure that the unittest for
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 47079
diff changeset
150 # the right version information is returned
cd91daf0327c - Add unittests for platform.mac_ver (or rather, ensure that the unittest for
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 47079
diff changeset
151 fd = os.popen('sw_vers', 'r')
cd91daf0327c - Add unittests for platform.mac_ver (or rather, ensure that the unittest for
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 47079
diff changeset
152 real_ver = None
cd91daf0327c - Add unittests for platform.mac_ver (or rather, ensure that the unittest for
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 47079
diff changeset
153 for ln in fd:
cd91daf0327c - Add unittests for platform.mac_ver (or rather, ensure that the unittest for
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 47079
diff changeset
154 if ln.startswith('ProductVersion:'):
cd91daf0327c - Add unittests for platform.mac_ver (or rather, ensure that the unittest for
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 47079
diff changeset
155 real_ver = ln.strip().split()[-1]
cd91daf0327c - Add unittests for platform.mac_ver (or rather, ensure that the unittest for
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 47079
diff changeset
156 break
cd91daf0327c - Add unittests for platform.mac_ver (or rather, ensure that the unittest for
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 47079
diff changeset
157 fd.close()
55002
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 52349
diff changeset
158 self.assertFalse(real_ver is None)
55812
ce7e0038996f test_platform fails on OS X Snow Leopard because the UNIX command to get the
Brett Cannon <bcannon@gmail.com>
parents: 55002
diff changeset
159 result_list = res[0].split('.')
ce7e0038996f test_platform fails on OS X Snow Leopard because the UNIX command to get the
Brett Cannon <bcannon@gmail.com>
parents: 55002
diff changeset
160 expect_list = real_ver.split('.')
ce7e0038996f test_platform fails on OS X Snow Leopard because the UNIX command to get the
Brett Cannon <bcannon@gmail.com>
parents: 55002
diff changeset
161 len_diff = len(result_list) - len(expect_list)
ce7e0038996f test_platform fails on OS X Snow Leopard because the UNIX command to get the
Brett Cannon <bcannon@gmail.com>
parents: 55002
diff changeset
162 # On Snow Leopard, sw_vers reports 10.6.0 as 10.6
ce7e0038996f test_platform fails on OS X Snow Leopard because the UNIX command to get the
Brett Cannon <bcannon@gmail.com>
parents: 55002
diff changeset
163 if len_diff > 0:
ce7e0038996f test_platform fails on OS X Snow Leopard because the UNIX command to get the
Brett Cannon <bcannon@gmail.com>
parents: 55002
diff changeset
164 expect_list.extend(['0'] * len_diff)
ce7e0038996f test_platform fails on OS X Snow Leopard because the UNIX command to get the
Brett Cannon <bcannon@gmail.com>
parents: 55002
diff changeset
165 self.assertEquals(result_list, expect_list)
47165
cd91daf0327c - Add unittests for platform.mac_ver (or rather, ensure that the unittest for
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 47079
diff changeset
166
cd91daf0327c - Add unittests for platform.mac_ver (or rather, ensure that the unittest for
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 47079
diff changeset
167 # res[1] claims to contain
cd91daf0327c - Add unittests for platform.mac_ver (or rather, ensure that the unittest for
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 47079
diff changeset
168 # (version, dev_stage, non_release_version)
cd91daf0327c - Add unittests for platform.mac_ver (or rather, ensure that the unittest for
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 47079
diff changeset
169 # That information is no longer available
cd91daf0327c - Add unittests for platform.mac_ver (or rather, ensure that the unittest for
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 47079
diff changeset
170 self.assertEquals(res[1], ('', '', ''))
cd91daf0327c - Add unittests for platform.mac_ver (or rather, ensure that the unittest for
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 47079
diff changeset
171
cd91daf0327c - Add unittests for platform.mac_ver (or rather, ensure that the unittest for
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 47079
diff changeset
172 if sys.byteorder == 'little':
cd91daf0327c - Add unittests for platform.mac_ver (or rather, ensure that the unittest for
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 47079
diff changeset
173 self.assertEquals(res[2], 'i386')
cd91daf0327c - Add unittests for platform.mac_ver (or rather, ensure that the unittest for
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 47079
diff changeset
174 else:
cd91daf0327c - Add unittests for platform.mac_ver (or rather, ensure that the unittest for
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 47079
diff changeset
175 self.assertEquals(res[2], 'PowerPC')
35900
e9be9e6188f4 Add a rudimentary test for the platform module that at least calls each
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
176
e9be9e6188f4 Add a rudimentary test for the platform module that at least calls each
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
177 def test_dist(self):
e9be9e6188f4 Add a rudimentary test for the platform module that at least calls each
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
178 res = platform.dist()
e9be9e6188f4 Add a rudimentary test for the platform module that at least calls each
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
179
e9be9e6188f4 Add a rudimentary test for the platform module that at least calls each
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
180 def test_libc_ver(self):
37472
f8fc30c0fc7c Fix test_platform on cygwin. When running from build area, sys.executable
Anthony Baxter <anthonybaxter@gmail.com>
parents: 35900
diff changeset
181 import os
47079
3407bf9dac38 make test_platform a bit more assertive (We'll see what the buildbots say.)
Benjamin Peterson <benjamin@python.org>
parents: 37472
diff changeset
182 if os.path.isdir(sys.executable) and \
3407bf9dac38 make test_platform a bit more assertive (We'll see what the buildbots say.)
Benjamin Peterson <benjamin@python.org>
parents: 37472
diff changeset
183 os.path.exists(sys.executable+'.exe'):
37472
f8fc30c0fc7c Fix test_platform on cygwin. When running from build area, sys.executable
Anthony Baxter <anthonybaxter@gmail.com>
parents: 35900
diff changeset
184 # Cygwin horror
f8fc30c0fc7c Fix test_platform on cygwin. When running from build area, sys.executable
Anthony Baxter <anthonybaxter@gmail.com>
parents: 35900
diff changeset
185 executable = executable + '.exe'
47079
3407bf9dac38 make test_platform a bit more assertive (We'll see what the buildbots say.)
Benjamin Peterson <benjamin@python.org>
parents: 37472
diff changeset
186 res = platform.libc_ver(sys.executable)
35900
e9be9e6188f4 Add a rudimentary test for the platform module that at least calls each
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
187
49565
0afa73d4bf99 #4157 move two test functions out of platform.py.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 49440
diff changeset
188 def test_parse_release_file(self):
0afa73d4bf99 #4157 move two test functions out of platform.py.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 49440
diff changeset
189
0afa73d4bf99 #4157 move two test functions out of platform.py.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 49440
diff changeset
190 for input, output in (
0afa73d4bf99 #4157 move two test functions out of platform.py.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 49440
diff changeset
191 # Examples of release file contents:
0afa73d4bf99 #4157 move two test functions out of platform.py.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 49440
diff changeset
192 ('SuSE Linux 9.3 (x86-64)', ('SuSE Linux ', '9.3', 'x86-64')),
0afa73d4bf99 #4157 move two test functions out of platform.py.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 49440
diff changeset
193 ('SUSE LINUX 10.1 (X86-64)', ('SUSE LINUX ', '10.1', 'X86-64')),
0afa73d4bf99 #4157 move two test functions out of platform.py.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 49440
diff changeset
194 ('SUSE LINUX 10.1 (i586)', ('SUSE LINUX ', '10.1', 'i586')),
0afa73d4bf99 #4157 move two test functions out of platform.py.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 49440
diff changeset
195 ('Fedora Core release 5 (Bordeaux)', ('Fedora Core', '5', 'Bordeaux')),
0afa73d4bf99 #4157 move two test functions out of platform.py.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 49440
diff changeset
196 ('Red Hat Linux release 8.0 (Psyche)', ('Red Hat Linux', '8.0', 'Psyche')),
0afa73d4bf99 #4157 move two test functions out of platform.py.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 49440
diff changeset
197 ('Red Hat Linux release 9 (Shrike)', ('Red Hat Linux', '9', 'Shrike')),
0afa73d4bf99 #4157 move two test functions out of platform.py.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 49440
diff changeset
198 ('Red Hat Enterprise Linux release 4 (Nahant)', ('Red Hat Enterprise Linux', '4', 'Nahant')),
0afa73d4bf99 #4157 move two test functions out of platform.py.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 49440
diff changeset
199 ('CentOS release 4', ('CentOS', '4', None)),
0afa73d4bf99 #4157 move two test functions out of platform.py.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 49440
diff changeset
200 ('Rocks release 4.2.1 (Cydonia)', ('Rocks', '4.2.1', 'Cydonia')),
58480
5c1d7a3ba29c fix an UnboundLocalError when the release file is empty #7773
Benjamin Peterson <benjamin@python.org>
parents: 55812
diff changeset
201 ('', ('', '', '')), # If there's nothing there.
49565
0afa73d4bf99 #4157 move two test functions out of platform.py.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 49440
diff changeset
202 ):
0afa73d4bf99 #4157 move two test functions out of platform.py.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 49440
diff changeset
203 self.assertEqual(platform._parse_release_file(input), output)
0afa73d4bf99 #4157 move two test functions out of platform.py.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 49440
diff changeset
204
0afa73d4bf99 #4157 move two test functions out of platform.py.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 49440
diff changeset
205
35900
e9be9e6188f4 Add a rudimentary test for the platform module that at least calls each
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
206 def test_main():
e9be9e6188f4 Add a rudimentary test for the platform module that at least calls each
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
207 test_support.run_unittest(
e9be9e6188f4 Add a rudimentary test for the platform module that at least calls each
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
208 PlatformTest
e9be9e6188f4 Add a rudimentary test for the platform module that at least calls each
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
209 )
e9be9e6188f4 Add a rudimentary test for the platform module that at least calls each
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
210
e9be9e6188f4 Add a rudimentary test for the platform module that at least calls each
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
211 if __name__ == '__main__':
e9be9e6188f4 Add a rudimentary test for the platform module that at least calls each
Walter Dörwald <walter@livinglogic.de>
parents:
diff changeset
212 test_main()