mirror of
https://github.com/ha7ilm/openwebrx.git
synced 2026-04-21 06:13:45 +00:00
introduce PropertyValidator (wrapper)
This commit is contained in:
parent
40e531c0da
commit
ad0a5c27db
2 changed files with 80 additions and 4 deletions
37
test/property/test_property_validator.py
Normal file
37
test/property/test_property_validator.py
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
from unittest import TestCase
|
||||
from owrx.property import PropertyLayer, PropertyValidator, PropertyValidationError
|
||||
from owrx.property.validators import NumberValidator, StringValidator
|
||||
|
||||
|
||||
class PropertyValidatorTest(TestCase):
|
||||
def testPassesUnvalidated(self):
|
||||
pm = PropertyLayer()
|
||||
pv = PropertyValidator(pm)
|
||||
pv["testkey"] = "testvalue"
|
||||
self.assertEqual(pv["testkey"], "testvalue")
|
||||
self.assertEqual(pm["testkey"], "testvalue")
|
||||
|
||||
def testPassesValidValue(self):
|
||||
pv = PropertyValidator(PropertyLayer(), {"testkey": NumberValidator()})
|
||||
pv["testkey"] = 42
|
||||
self.assertEqual(pv["testkey"], 42)
|
||||
|
||||
def testThrowsErrorOnInvalidValue(self):
|
||||
pv = PropertyValidator(PropertyLayer(), {"testkey": NumberValidator()})
|
||||
with self.assertRaises(PropertyValidationError):
|
||||
pv["testkey"] = "text"
|
||||
|
||||
def testSetValidator(self):
|
||||
pv = PropertyValidator(PropertyLayer())
|
||||
pv.setValidator("testkey", NumberValidator())
|
||||
with self.assertRaises(PropertyValidationError):
|
||||
pv["testkey"] = "text"
|
||||
|
||||
def testUpdateValidator(self):
|
||||
pv = PropertyValidator(PropertyLayer(), {"testkey": StringValidator()})
|
||||
# this should pass
|
||||
pv["testkey"] = "text"
|
||||
pv.setValidator("testkey", NumberValidator())
|
||||
# this should raise
|
||||
with self.assertRaises(PropertyValidationError):
|
||||
pv["testkey"] = "text"
|
||||
Loading…
Add table
Add a link
Reference in a new issue