Skip to content

Commit 1f715c1

Browse files
committed
add tests for Plugin Manager version compare function
1 parent d265f33 commit 1f715c1

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed

tests/src/python/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ ADD_PYTHON_TEST(PyQgsWFSProvider test_provider_wfs.py)
112112
ADD_PYTHON_TEST(PyQgsWFSProviderGUI test_provider_wfs_gui.py)
113113
ADD_PYTHON_TEST(PyQgsConsole test_console.py)
114114
ADD_PYTHON_TEST(PyQgsLayerDependencies test_layer_dependencies.py)
115+
ADD_PYTHON_TEST(PyQgsVersionCompare test_versioncompare.py)
115116

116117
IF (NOT WIN32)
117118
ADD_PYTHON_TEST(PyQgsLogger test_qgslogger.py)
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# -*- coding: utf-8 -*-
2+
'''
3+
test_versioncompare.py
4+
--------------------------------------
5+
Date : September 2016
6+
Copyright : (C) 2016 Alexander Bruy
7+
email : alexander dot bruy at gmail dot com
8+
***************************************************************************
9+
* *
10+
* This program is free software; you can redistribute it and/or modify *
11+
* it under the terms of the GNU General Public License as published by *
12+
* the Free Software Foundation; either version 2 of the License, or *
13+
* (at your option) any later version. *
14+
* *
15+
***************************************************************************/
16+
'''
17+
18+
import qgis # NOQA
19+
20+
from qgis.testing import unittest, start_app
21+
from pyplugin_installer.version_compare import compareVersions
22+
23+
start_app()
24+
25+
26+
class TestVersionCompare(unittest.TestCase):
27+
28+
def setUp(self):
29+
"""Run before each test."""
30+
pass
31+
32+
def tearDown(self):
33+
"""Run after each test."""
34+
pass
35+
36+
def testCompareVersions(self):
37+
a = '1.0.0'
38+
# a == b
39+
b = '1.0.0'
40+
self.assertEquals(compareVersions(a, b), 0)
41+
# a > b
42+
b = '0.1.0'
43+
self.assertEquals(compareVersions(a, b), 1)
44+
# b > a
45+
b = '1.1.0'
46+
self.assertEquals(compareVersions(a, b), 2)
47+
48+
# test that prefix stripped correctly
49+
a = 'ver. 1.0.0'
50+
b = 'ver. 0.1.0'
51+
self.assertEquals(compareVersions(a, b), 1)
52+
53+
# test versions with build numbers
54+
a = '1.0.0-1'
55+
b = '1.0.0-2'
56+
self.assertEquals(compareVersions(a, b), 2)
57+
58+
# test versions with suffixes
59+
a = '1.0.0a'
60+
b = '1.0.0b'
61+
self.assertEquals(compareVersions(a, b), 2)
62+
63+
# test versions with suffixes in different cases
64+
a = '1.0.0-201609011405-2690BD9'
65+
b = '1.0.0-201609011405-2690bd9'
66+
self.assertEquals(compareVersions(a, b), 0)
67+
68+
69+
if __name__ == '__main__':
70+
unittest.main()

0 commit comments

Comments
 (0)