mirror of https://github.com/kivy/kivy.git
add tests for errorvalue/errorhandler of Properties and update versionchanged
This commit is contained in:
parent
92d76ddfaf
commit
ed75b67abb
|
@ -213,8 +213,8 @@ cdef class Property:
|
|||
`errorvalue`: object
|
||||
If set, will replace an invalid property value (overrides errorhandler)
|
||||
|
||||
.. versionchanged:: 1.4.0
|
||||
Parameters errorhandler and errorvalue added
|
||||
.. versionchanged:: 1.4.2
|
||||
Parameters errorhandler and errorvalue added
|
||||
'''
|
||||
|
||||
def __cinit__(self):
|
||||
|
|
|
@ -311,3 +311,48 @@ class PropertiesTestCase(unittest.TestCase):
|
|||
self.assertEqual(wid.basevalue, 2)
|
||||
self.assertEqual(wid.prop, 4)
|
||||
self.assertEqual(observe_called, 3)
|
||||
|
||||
def test_bounded_numeric_property_error_value(self):
|
||||
from kivy.properties import BoundedNumericProperty
|
||||
|
||||
bnp = BoundedNumericProperty(0, min=-5, max=5, errorvalue=1)
|
||||
bnp.link(wid, 'bnp')
|
||||
|
||||
bnp.set(wid, 1)
|
||||
self.assertEqual(bnp.get(wid), 1)
|
||||
|
||||
bnp.set(wid, 5)
|
||||
self.assertEqual(bnp.get(wid), 5)
|
||||
|
||||
bnp.set(wid, 6)
|
||||
self.assertEqual(bnp.get(wid), 1)
|
||||
|
||||
bnp.set(wid, -5)
|
||||
self.assertEqual(bnp.get(wid), -5)
|
||||
|
||||
bnp.set(wid, -6)
|
||||
self.assertEqual(bnp.get(wid), 1)
|
||||
|
||||
def test_bounded_numeric_property_error_handler(self):
|
||||
from kivy.properties import BoundedNumericProperty
|
||||
|
||||
bnp = BoundedNumericProperty(
|
||||
0, min=-5, max=5,
|
||||
errorhandler=lambda x: 5 if x > 5 else -5)
|
||||
|
||||
bnp.link(wid, 'bnp')
|
||||
|
||||
bnp.set(wid, 1)
|
||||
self.assertEqual(bnp.get(wid), 1)
|
||||
|
||||
bnp.set(wid, 5)
|
||||
self.assertEqual(bnp.get(wid), 5)
|
||||
|
||||
bnp.set(wid, 10)
|
||||
self.assertEqual(bnp.get(wid), 5)
|
||||
|
||||
bnp.set(wid, -5)
|
||||
self.assertEqual(bnp.get(wid), -5)
|
||||
|
||||
bnp.set(wid, -10)
|
||||
self.assertEqual(bnp.get(wid), -5)
|
||||
|
|
Loading…
Reference in New Issue