|
| 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