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):
193
193
194
194
195
195
def _parse_version (version ):
196
- """Parse a version string into a tuple of ints """
196
+ """Parse a version into a comparable object """
197
197
try :
198
198
from packaging .version import parse as _packaging_version_parse
199
199
except ImportError :
200
- return tuple ( _parse_int ( x ) for x in version . split ( "." ) )
200
+ return _parse_version_internal ( version )
201
201
else :
202
202
return _packaging_version_parse (version )
203
203
204
204
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
+
205
210
# Unless `FORCE_QT_API` is set, use previously imported Qt Python bindings
206
211
if not os .environ .get ("FORCE_QT_API" ):
207
212
if "PyQt5" in sys .modules :
Original file line number Diff line number Diff line change 5
5
6
6
import pytest
7
7
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
+ )
9
16
from qtpy .tests .utils import pytest_importorskip
10
17
11
18
with contextlib .suppress (Exception ):
@@ -141,3 +148,27 @@ def test_qt_api_environ(api):
141
148
raise AssertionError('QtPy imported despite bad QT_API')
142
149
"""
143
150
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