mirror of https://github.com/python/cpython
add much better tests for python version information parsing
This commit is contained in:
parent
c9301355d8
commit
f521b8c6d2
|
@ -1264,9 +1264,6 @@ _sys_version_parser = re.compile(
|
|||
'\(#?([^,]+),\s*([\w ]+),\s*([\w :]+)\)\s*'
|
||||
'\[([^\]]+)\]?')
|
||||
|
||||
_jython_sys_version_parser = re.compile(
|
||||
r'([\d\.]+)')
|
||||
|
||||
_ironpython_sys_version_parser = re.compile(
|
||||
r'IronPython\s*'
|
||||
'([\d\.]+)'
|
||||
|
@ -1322,12 +1319,12 @@ def _sys_version(sys_version=None):
|
|||
elif sys.platform[:4] == 'java':
|
||||
# Jython
|
||||
name = 'Jython'
|
||||
match = _jython_sys_version_parser.match(sys_version)
|
||||
match = _sys_version_parser.match(sys_version)
|
||||
if match is None:
|
||||
raise ValueError(
|
||||
'failed to parse Jython sys.version: %s' %
|
||||
repr(sys_version))
|
||||
version, = match.groups()
|
||||
version, buildno, builddate, buildtime, _ = match.groups()
|
||||
branch = ''
|
||||
revision = ''
|
||||
compiler = sys.platform
|
||||
|
|
|
@ -48,25 +48,52 @@ class PlatformTest(unittest.TestCase):
|
|||
def test_processor(self):
|
||||
res = platform.processor()
|
||||
|
||||
def test_python_implementation(self):
|
||||
res = platform.python_implementation()
|
||||
def setUp(self):
|
||||
self.save_version = sys.version
|
||||
self.save_subversion = sys.subversion
|
||||
self.save_platform = sys.platform
|
||||
|
||||
def test_python_version(self):
|
||||
res1 = platform.python_version()
|
||||
res2 = platform.python_version_tuple()
|
||||
self.assertEqual(res1, ".".join(res2))
|
||||
def tearDown(self):
|
||||
sys.version = self.save_version
|
||||
sys.subversion = self.save_subversion
|
||||
sys.platform = self.save_platform
|
||||
|
||||
def test_python_branch(self):
|
||||
res = platform.python_branch()
|
||||
|
||||
def test_python_revision(self):
|
||||
res = platform.python_revision()
|
||||
|
||||
def test_python_build(self):
|
||||
res = platform.python_build()
|
||||
|
||||
def test_python_compiler(self):
|
||||
res = platform.python_compiler()
|
||||
def test_python_info(self):
|
||||
# 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.\")]",
|
||||
None, "java1.5.0_16")
|
||||
:
|
||||
("Jython", "2.5.0", "", "", ("", ""),
|
||||
"java1.5.0_16"),
|
||||
}
|
||||
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])
|
||||
|
||||
def test_system_alias(self):
|
||||
res = platform.system_alias(
|
||||
|
|
Loading…
Reference in New Issue