QGIS/python/plugins/processing/tests/ParametersTest.py

94 lines
3.2 KiB
Python
Raw Normal View History

2013-04-13 11:04:22 +02:00
# -*- coding: utf-8 -*-
"""
***************************************************************************
ParametersTest.py
---------------------
Date : March 2013
Copyright : (C) 2013 by Victor Olaya
Email : volayaf 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. *
* *
***************************************************************************
"""
__author__ = 'Victor Olaya'
__date__ = 'March 2013'
__copyright__ = '(C) 2013, Victor Olaya'
2013-04-13 11:04:22 +02:00
# This will get replaced with a git SHA1 when you do a git archive
2013-04-13 11:04:22 +02:00
__revision__ = '$Format:%H$'
2013-03-01 15:54:01 +01:00
import unittest
from processing.core.parameters import ParameterNumber
from processing.core.parameters import ParameterCrs
from processing.core.parameters import ParameterExtent
2013-03-01 15:54:01 +01:00
2013-03-01 15:54:01 +01:00
class ParametersTest(unittest.TestCase):
def testParameterNumber(self):
param = ParameterNumber('name', 'desc', 0, 10)
assert not param.setValue('wrongvalue')
2013-03-01 15:54:01 +01:00
assert param.value is None
assert not param.setValue(25)
assert param.value is None
assert param.setValue(5)
assert param.value == 5
2013-03-01 15:54:01 +01:00
assert param.setValue(None)
2013-03-26 14:15:12 +01:00
assert param.value == param.default
2013-03-01 15:54:01 +01:00
s = param.serialize()
param2 = ParameterNumber()
2013-03-26 14:15:12 +01:00
param2.deserialize(s)
2013-03-01 15:54:01 +01:00
assert param.default == param2.default
assert param.max == param2.max
assert param.min == param2.min
assert param.description == param2.description
2013-03-26 14:15:12 +01:00
assert param.name == param2.name
2013-03-01 15:54:01 +01:00
def testParameterCRS(self):
param = ParameterCrs('name', 'desc')
assert param.setValue('EPSG:12003')
assert param.value == 'EPSG:12003'
2013-03-01 15:54:01 +01:00
assert param.setValue(None)
2013-03-26 14:15:12 +01:00
assert param.value == param.default
2013-03-01 15:54:01 +01:00
s = param.serialize()
param2 = ParameterCrs()
2013-03-26 14:15:12 +01:00
param2.deserialize(s)
assert param.default == param2.default
2013-03-01 15:54:01 +01:00
assert param.description == param2.description
2013-03-26 14:15:12 +01:00
assert param.name == param2.name
2013-03-01 15:54:01 +01:00
def testParameterExtent(self):
param = ParameterExtent('name', 'desc')
assert not param.setValue('0,2,0')
assert not param.setValue('0,2,0,a')
assert not param.setValue('0,2,2,4')
assert param.value == '0,2,2,4'
2013-03-01 15:54:01 +01:00
assert param.setValue(None)
2013-03-26 14:15:12 +01:00
assert param.value == param.default
2013-03-01 15:54:01 +01:00
s = param.serialize()
param2 = ParameterExtent()
2013-03-26 14:15:12 +01:00
param2.deserialize(s)
assert param.default == param2.default
2013-03-01 15:54:01 +01:00
assert param.description == param2.description
2013-03-26 14:15:12 +01:00
assert param.name == param2.name
def suite():
2013-03-31 21:18:27 +02:00
suite = unittest.makeSuite(ParametersTest, 'test')
return suite
2013-03-26 14:15:12 +01:00
def runtests():
2013-03-31 21:18:27 +02:00
result = unittest.TestResult()
testsuite = suite()
testsuite.run(result)
return result