File tree Expand file tree Collapse file tree 2 files changed +19
-1
lines changed Expand file tree Collapse file tree 2 files changed +19
-1
lines changed Original file line number Diff line number Diff line change 1
1
2
- from pkg_resources import parse_version
3
2
import sqlalchemy
4
3
5
4
5
+ def parse_version (v ):
6
+ """
7
+ Take a string version and conver it to a tuple (for easier comparison), e.g.:
8
+
9
+ "1.2.3" --> (1, 2, 3)
10
+ "1.2" --> (1, 2, 0)
11
+ "1" --> (1, 0, 0)
12
+ """
13
+ parts = v .split ("." )
14
+ # Pad the list to make sure there is three elements so that we get major, minor, point
15
+ # comparisons that default to "0" if not given. I.e. "1.2" --> (1, 2, 0)
16
+ parts = (parts + 3 * ['0' ])[:3 ]
17
+ return tuple (int (x ) for x in parts )
18
+
19
+
6
20
def sqlalchemy_version (op , val ):
7
21
sa_ver = parse_version (sqlalchemy .__version__ )
8
22
target_ver = parse_version (val )
Original file line number Diff line number Diff line change 4
4
5
5
6
6
class TestSQLAlchemyVersion :
7
+ def test_parse_version (self ):
8
+ assert utils .parse_version ('1.2.3' ) == (1 , 2 , 3 )
9
+ assert utils .parse_version ('1.2' ) == (1 , 2 , 0 )
10
+ assert utils .parse_version ('1' ) == (1 , 0 , 0 )
7
11
8
12
@mock .patch .object (utils , 'sqlalchemy' )
9
13
def test_sqlalchemy_version (self , m_sqlalchemy ):
You can’t perform that action at this time.
0 commit comments