Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(85707)

Delta Between Two Patch Sets: Lib/test/test_platform.py

Issue 16510: Using appropriate checks in tests
Left Patch Set: Created 5 years, 11 months ago
Right Patch Set: Created 5 years, 6 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « Lib/test/test_pep380.py ('k') | Lib/test/test_posix.py » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 from unittest import mock
1 import os 2 import os
2 import platform 3 import platform
3 import subprocess 4 import subprocess
4 import sys 5 import sys
6 import tempfile
5 import unittest 7 import unittest
6 import warnings 8 import warnings
7 9
8 from test import support 10 from test import support
9 11
10 class PlatformTest(unittest.TestCase): 12 class PlatformTest(unittest.TestCase):
11 def test_architecture(self): 13 def test_architecture(self):
12 res = platform.architecture() 14 res = platform.architecture()
13 15
14 @support.skip_unless_symlink 16 @support.skip_unless_symlink
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 86
85 # Tests for python_implementation(), python_version(), python_branch(), 87 # Tests for python_implementation(), python_version(), python_branch(),
86 # python_revision(), python_build(), and python_compiler(). 88 # python_revision(), python_build(), and python_compiler().
87 sys_versions = { 89 sys_versions = {
88 ("2.6.1 (r261:67515, Dec 6 2008, 15:26:00) \n[GCC 4.0.1 (Apple Comp uter, Inc. build 5370)]", 90 ("2.6.1 (r261:67515, Dec 6 2008, 15:26:00) \n[GCC 4.0.1 (Apple Comp uter, Inc. build 5370)]",
89 ('CPython', 'tags/r261', '67515'), self.save_platform) 91 ('CPython', 'tags/r261', '67515'), self.save_platform)
90 : 92 :
91 ("CPython", "2.6.1", "tags/r261", "67515", 93 ("CPython", "2.6.1", "tags/r261", "67515",
92 ('r261:67515', 'Dec 6 2008 15:26:00'), 94 ('r261:67515', 'Dec 6 2008 15:26:00'),
93 'GCC 4.0.1 (Apple Computer, Inc. build 5370)'), 95 'GCC 4.0.1 (Apple Computer, Inc. build 5370)'),
96
94 ("IronPython 2.0 (2.0.0.0) on .NET 2.0.50727.3053", None, "cli") 97 ("IronPython 2.0 (2.0.0.0) on .NET 2.0.50727.3053", None, "cli")
95 : 98 :
96 ("IronPython", "2.0.0", "", "", ("", ""), 99 ("IronPython", "2.0.0", "", "", ("", ""),
97 ".NET 2.0.50727.3053"), 100 ".NET 2.0.50727.3053"),
101
102 ("2.6.1 (IronPython 2.6.1 (2.6.10920.0) on .NET 2.0.50727.1433)", No ne, "cli")
103 :
104 ("IronPython", "2.6.1", "", "", ("", ""),
105 ".NET 2.0.50727.1433"),
106
107 ("2.7.4 (IronPython 2.7.4 (2.7.0.40) on Mono 4.0.30319.1 (32-bit))", None, "cli")
108 :
109 ("IronPython", "2.7.4", "", "", ("", ""),
110 "Mono 4.0.30319.1 (32-bit)"),
111
98 ("2.5 (trunk:6107, Mar 26 2009, 13:02:18) \n[Java HotSpot(TM) Client VM (\"Apple Computer, Inc.\")]", 112 ("2.5 (trunk:6107, Mar 26 2009, 13:02:18) \n[Java HotSpot(TM) Client VM (\"Apple Computer, Inc.\")]",
99 ('Jython', 'trunk', '6107'), "java1.5.0_16") 113 ('Jython', 'trunk', '6107'), "java1.5.0_16")
100 : 114 :
101 ("Jython", "2.5.0", "trunk", "6107", 115 ("Jython", "2.5.0", "trunk", "6107",
102 ('trunk:6107', 'Mar 26 2009'), "java1.5.0_16"), 116 ('trunk:6107', 'Mar 26 2009'), "java1.5.0_16"),
117
103 ("2.5.2 (63378, Mar 26 2009, 18:03:29)\n[PyPy 1.0.0]", 118 ("2.5.2 (63378, Mar 26 2009, 18:03:29)\n[PyPy 1.0.0]",
104 ('PyPy', 'trunk', '63378'), self.save_platform) 119 ('PyPy', 'trunk', '63378'), self.save_platform)
105 : 120 :
106 ("PyPy", "2.5.2", "trunk", "63378", ('63378', 'Mar 26 2009'), 121 ("PyPy", "2.5.2", "trunk", "63378", ('63378', 'Mar 26 2009'),
107 "") 122 "")
108 } 123 }
109 for (version_tag, subversion, sys_platform), info in \ 124 for (version_tag, subversion, sys_platform), info in \
110 sys_versions.items(): 125 sys_versions.items():
111 sys.version = version_tag 126 sys.version = version_tag
112 if subversion is None: 127 if subversion is None:
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 with platform.popen(command, 'w') as stdin: 290 with platform.popen(command, 'w') as stdin:
276 stdout = stdin.write(data) 291 stdout = stdin.write(data)
277 ret = stdin.close() 292 ret = stdin.close()
278 self.assertIsNotNone(ret) 293 self.assertIsNotNone(ret)
279 if os.name == 'nt': 294 if os.name == 'nt':
280 returncode = ret 295 returncode = ret
281 else: 296 else:
282 returncode = ret >> 8 297 returncode = ret >> 8
283 self.assertEqual(returncode, len(data)) 298 self.assertEqual(returncode, len(data))
284 299
300 def test_linux_distribution_encoding(self):
301 # Issue #17429
302 with tempfile.TemporaryDirectory() as tempdir:
303 filename = os.path.join(tempdir, 'fedora-release')
304 with open(filename, 'w', encoding='utf-8') as f:
305 f.write('Fedora release 19 (Schr\xf6dinger\u2019s Cat)\n')
306
307 with mock.patch('platform._UNIXCONFDIR', tempdir):
308 distname, version, distid = platform.linux_distribution()
309
310 self.assertEqual(distname, 'Fedora')
311 self.assertEqual(version, '19')
312 self.assertEqual(distid, 'Schr\xf6dinger\u2019s Cat')
285 313
286 def test_main(): 314 def test_main():
287 support.run_unittest( 315 support.run_unittest(
288 PlatformTest 316 PlatformTest
289 ) 317 )
290 318
291 if __name__ == '__main__': 319 if __name__ == '__main__':
292 test_main() 320 test_main()
LEFTRIGHT

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+