Skip to content
Permalink
Browse files

add tests for Plugin Manager version compare function

  • Loading branch information
alexbruy committed Sep 13, 2016
1 parent d265f33 commit 1f715c1acd51a735557d3624352170e93aebdbd7
Showing with 71 additions and 0 deletions.
  1. +1 −0 tests/src/python/CMakeLists.txt
  2. +70 −0 tests/src/python/test_versioncompare.py
@@ -112,6 +112,7 @@ ADD_PYTHON_TEST(PyQgsWFSProvider test_provider_wfs.py)
ADD_PYTHON_TEST(PyQgsWFSProviderGUI test_provider_wfs_gui.py)
ADD_PYTHON_TEST(PyQgsConsole test_console.py)
ADD_PYTHON_TEST(PyQgsLayerDependencies test_layer_dependencies.py)
ADD_PYTHON_TEST(PyQgsVersionCompare test_versioncompare.py)

IF (NOT WIN32)
ADD_PYTHON_TEST(PyQgsLogger test_qgslogger.py)
@@ -0,0 +1,70 @@
# -*- coding: utf-8 -*-
'''
test_versioncompare.py
--------------------------------------
Date : September 2016
Copyright : (C) 2016 Alexander Bruy
email : alexander dot bruy at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
'''

import qgis # NOQA

from qgis.testing import unittest, start_app
from pyplugin_installer.version_compare import compareVersions

start_app()


class TestVersionCompare(unittest.TestCase):

def setUp(self):
"""Run before each test."""
pass

def tearDown(self):
"""Run after each test."""
pass

def testCompareVersions(self):
a = '1.0.0'
# a == b
b = '1.0.0'
self.assertEquals(compareVersions(a, b), 0)
# a > b
b = '0.1.0'
self.assertEquals(compareVersions(a, b), 1)
# b > a
b = '1.1.0'
self.assertEquals(compareVersions(a, b), 2)

# test that prefix stripped correctly
a = 'ver. 1.0.0'
b = 'ver. 0.1.0'
self.assertEquals(compareVersions(a, b), 1)

# test versions with build numbers
a = '1.0.0-1'
b = '1.0.0-2'
self.assertEquals(compareVersions(a, b), 2)

# test versions with suffixes
a = '1.0.0a'
b = '1.0.0b'
self.assertEquals(compareVersions(a, b), 2)

# test versions with suffixes in different cases
a = '1.0.0-201609011405-2690BD9'
b = '1.0.0-201609011405-2690bd9'
self.assertEquals(compareVersions(a, b), 0)


if __name__ == '__main__':
unittest.main()

0 comments on commit 1f715c1

Please sign in to comment.
You can’t perform that action at this time.