File tree Expand file tree Collapse file tree 2 files changed +39
-3
lines changed Expand file tree Collapse file tree 2 files changed +39
-3
lines changed Original file line number Diff line number Diff line change @@ -193,15 +193,20 @@ def _parse_int(value):
193193
194194
195195def _parse_version (version ):
196- """Parse a version string into a tuple of ints """
196+ """Parse a version into a comparable object """
197197 try :
198198 from packaging .version import parse as _packaging_version_parse
199199 except ImportError :
200- return tuple ( _parse_int ( x ) for x in version . split ( "." ) )
200+ return _parse_version_internal ( version )
201201 else :
202202 return _packaging_version_parse (version )
203203
204204
205+ def _parse_version_internal (version ):
206+ """Parse a version string into a tuple of ints"""
207+ return tuple (_parse_int (x ) for x in version .split ("." ))
208+
209+
205210# Unless `FORCE_QT_API` is set, use previously imported Qt Python bindings
206211if not os .environ .get ("FORCE_QT_API" ):
207212 if "PyQt5" in sys .modules :
Original file line number Diff line number Diff line change 55
66import pytest
77
8- from qtpy import API_NAMES , QtCore , QtGui , QtWidgets
8+ from qtpy import (
9+ API_NAMES ,
10+ QtCore ,
11+ QtGui ,
12+ QtWidgets ,
13+ _parse_version ,
14+ _parse_version_internal ,
15+ )
916from qtpy .tests .utils import pytest_importorskip
1017
1118with contextlib .suppress (Exception ):
@@ -141,3 +148,27 @@ def test_qt_api_environ(api):
141148 raise AssertionError('QtPy imported despite bad QT_API')
142149"""
143150 subprocess .check_call ([sys .executable , "-Oc" , cmd ], env = env )
151+
152+
153+ @pytest .mark .parametrize (
154+ "first,second" ,
155+ [
156+ ('1.2.3' , '1.2.3.1' ),
157+ ('1.2.3' , '1.10.0' )
158+ ],
159+ )
160+ def test_parse_version (first , second ):
161+ """Verify the behavior of _parse_version()"""
162+ assert _parse_version (first ) < _parse_version (second )
163+
164+
165+ @pytest .mark .parametrize (
166+ "value,expect" ,
167+ [
168+ ('1.2.3' , (1 , 2 , 3 )),
169+ ('1.x.3' , (1 , 0 , 3 ))
170+ ],
171+ )
172+ def test_parse_version_internal (value , expect ):
173+ """Verify the behavior of _parse_version_internal()"""
174+ assert _parse_version_internal (value ) == expect
You can’t perform that action at this time.
0 commit comments