[Python-checkins] cpython (2.7): Fixed full Tcl version parsing in tests for pre-final versions.

serhiy.storchaka python-checkins at python.org
Wed Apr 22 10:02:31 CEST 2015


https://hg.python.org/cpython/rev/cebe15821a0c
changeset:   95759:cebe15821a0c
branch:      2.7
parent:      95755:5116916e4f7f
user:        Serhiy Storchaka <storchaka at gmail.com>
date:        Wed Apr 22 08:35:53 2015 +0300
summary:
  Fixed full Tcl version parsing in tests for pre-final versions.

files:
  Lib/lib-tk/test/test_ttk/support.py      |  18 ++++---
  Lib/lib-tk/test/test_ttk/test_widgets.py |   4 +-
  Lib/test/test_tcl.py                     |  26 +++++------
  3 files changed, 23 insertions(+), 25 deletions(-)


diff --git a/Lib/lib-tk/test/test_ttk/support.py b/Lib/lib-tk/test/test_ttk/support.py
--- a/Lib/lib-tk/test/test_ttk/support.py
+++ b/Lib/lib-tk/test/test_ttk/support.py
@@ -1,3 +1,4 @@
+import re
 import unittest
 import Tkinter as tkinter
 
@@ -61,14 +62,15 @@
     global _tk_patchlevel
     if _tk_patchlevel is None:
         tcl = tkinter.Tcl()
-        patchlevel = []
-        for x in tcl.call('info', 'patchlevel').split('.'):
-            try:
-                x = int(x, 10)
-            except ValueError:
-                x = -1
-            patchlevel.append(x)
-        _tk_patchlevel = tuple(patchlevel)
+        patchlevel = tcl.call('info', 'patchlevel')
+        m = re.match(r'(\d+)\.(\d+)([ab.])(\d+)$', patchlevel)
+        major, minor, releaselevel, serial = m.groups()
+        major, minor, serial = int(major), int(minor), int(serial)
+        releaselevel = {'a': 'alpha', 'b': 'beta', '.': 'final'}[releaselevel]
+        if releaselevel == 'final':
+            _tk_patchlevel = major, minor, serial, releaselevel, 0
+        else:
+            _tk_patchlevel = major, minor, 0, releaselevel, serial
     return _tk_patchlevel
 
 units = {
diff --git a/Lib/lib-tk/test/test_ttk/test_widgets.py b/Lib/lib-tk/test/test_ttk/test_widgets.py
--- a/Lib/lib-tk/test/test_ttk/test_widgets.py
+++ b/Lib/lib-tk/test/test_ttk/test_widgets.py
@@ -22,7 +22,7 @@
         widget = self.create()
         self.assertEqual(widget['class'], '')
         errmsg='attempt to change read-only option'
-        if get_tk_patchlevel() < (8, 6, 0): # actually this was changed in 8.6b3
+        if get_tk_patchlevel() < (8, 6, 0, 'beta', 3):
             errmsg='Attempt to change read-only option'
         self.checkInvalidParam(widget, 'class', 'Foo', errmsg=errmsg)
         widget2 = self.create(class_='Foo')
@@ -553,7 +553,7 @@
         widget = self.create()
         self.assertEqual(str(widget['orient']), 'vertical')
         errmsg='attempt to change read-only option'
-        if get_tk_patchlevel() < (8, 6, 0): # actually this was changed in 8.6b3
+        if get_tk_patchlevel() < (8, 6, 0, 'beta', 3):
             errmsg='Attempt to change read-only option'
         self.checkInvalidParam(widget, 'orient', 'horizontal',
                 errmsg=errmsg)
diff --git a/Lib/test/test_tcl.py b/Lib/test/test_tcl.py
--- a/Lib/test/test_tcl.py
+++ b/Lib/test/test_tcl.py
@@ -1,4 +1,5 @@
 import unittest
+import re
 import sys
 import os
 from test import test_support
@@ -18,27 +19,22 @@
 except ImportError:
     INT_MAX = PY_SSIZE_T_MAX = sys.maxsize
 
-tcl_version = _tkinter.TCL_VERSION.split('.')
-try:
-    for i in range(len(tcl_version)):
-        tcl_version[i] = int(tcl_version[i])
-except ValueError:
-    pass
-tcl_version = tuple(tcl_version)
+tcl_version = tuple(map(int, _tkinter.TCL_VERSION.split('.')))
 
 _tk_patchlevel = None
 def get_tk_patchlevel():
     global _tk_patchlevel
     if _tk_patchlevel is None:
         tcl = Tcl()
-        patchlevel = []
-        for x in tcl.call('info', 'patchlevel').split('.'):
-            try:
-                x = int(x, 10)
-            except ValueError:
-                x = -1
-            patchlevel.append(x)
-        _tk_patchlevel = tuple(patchlevel)
+        patchlevel = tcl.call('info', 'patchlevel')
+        m = re.match(r'(\d+)\.(\d+)([ab.])(\d+)$', patchlevel)
+        major, minor, releaselevel, serial = m.groups()
+        major, minor, serial = int(major), int(minor), int(serial)
+        releaselevel = {'a': 'alpha', 'b': 'beta', '.': 'final'}[releaselevel]
+        if releaselevel == 'final':
+            _tk_patchlevel = major, minor, serial, releaselevel, 0
+        else:
+            _tk_patchlevel = major, minor, 0, releaselevel, serial
     return _tk_patchlevel
 
 

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list