summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2009-03-26 18:35:37 (GMT)
committerBenjamin Peterson <benjamin@python.org>2009-03-26 18:35:37 (GMT)
commitf521b8c6d25544456394e5cd172b6a24d5d958a6 (patch)
treeec3b805d300d3e658f90a72e233379869199ce1d
parentc9301355d8e176a4ec9952a44a7728d8663bf21b (diff)
downloadcpython-f521b8c6d25544456394e5cd172b6a24d5d958a6.zip
cpython-f521b8c6d25544456394e5cd172b6a24d5d958a6.tar.gz
cpython-f521b8c6d25544456394e5cd172b6a24d5d958a6.tar.bz2
add much better tests for python version information parsing
-rwxr-xr-xLib/platform.py7
-rw-r--r--Lib/test/test_platform.py65
2 files changed, 48 insertions, 24 deletions
diff --git a/Lib/platform.py b/Lib/platform.py
index 35cf8bd..2559798 100755
--- a/Lib/platform.py
+++ b/Lib/platform.py
@@ -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
diff --git a/Lib/test/test_platform.py b/Lib/test/test_platform.py
index cc1a0a9..342d7bc 100644
--- a/Lib/test/test_platform.py
+++ b/Lib/test/test_platform.py
@@ -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 test_python_version(self):
- res1 = platform.python_version()
- res2 = platform.python_version_tuple()
- self.assertEqual(res1, ".".join(res2))
-
- 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 setUp(self):
+ self.save_version = sys.version
+ self.save_subversion = sys.subversion
+ self.save_platform = sys.platform
+
+ def tearDown(self):
+ sys.version = self.save_version
+ sys.subversion = self.save_subversion
+ sys.platform = self.save_platform
+
+ 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(