openwebrx-clone/test/property/validators/test_validator.py

21 lines
675 B
Python
Raw Normal View History

from unittest import TestCase
2021-01-24 20:25:26 +00:00
from owrx.property.validators import Validator, NumberValidator, LambdaValidator, StringValidator
class ValidatorTest(TestCase):
def testReturnsValidator(self):
validator = NumberValidator()
self.assertIs(validator, Validator.of(validator))
def testTransformsLambda(self):
def my_callable(v):
return True
validator = Validator.of(my_callable)
self.assertIsInstance(validator, LambdaValidator)
self.assertTrue(validator.isValid("test"))
2021-01-24 20:25:26 +00:00
def testGetsValidatorByKey(self):
validator = Validator.of("str")
self.assertIsInstance(validator, StringValidator)