def test_intersection_of_type_restrictions(): schema = Integer(multiple_of=3) & Integer(multiple_of=5) assert schema.validate(2) == [('Must be a multiple of 3.', []), ('Must be a multiple of 5.', [])] assert schema.validate(3) == [('Must be a multiple of 5.', [])] assert schema.validate(5) == [('Must be a multiple of 3.', [])] assert schema.validate(15) == []
def test_union_of_unions(): schema = (Integer() | String()) | Boolean() assert schema.validate('abc') == [] assert schema.validate(123) == [] assert schema.validate(True) == [] assert schema.validate({}) == [('Must match one of the options.', [])] schema = Integer() | (String() | Boolean()) assert schema.validate('abc') == [] assert schema.validate(123) == [] assert schema.validate(True) == [] assert schema.validate({}) == [('Must match one of the options.', [])]
def test_xor_of_types(): schema = Integer() ^ String() assert schema.validate('abc') == [] assert schema.validate(123) == [] assert schema.validate(True) == [('Must match one of the options.', [])]
def test_xor_of_type_restrictions(): schema = Integer(multiple_of=3) ^ Integer(multiple_of=5) assert schema.validate(2) == [('Must match one of the options.', [])] assert schema.validate(3) == [] assert schema.validate(5) == [] assert schema.validate(15) == [('Must match only one of the options.', [])]
def test_complex_not(): schema = Integer() & (~Integer(multiple_of=3) & ~Integer(multiple_of=5)) assert schema.validate('') == [('Must be an integer.', [])] assert schema.validate(2) == [] assert schema.validate(3) == [('Must not match the option.', [])] assert schema.validate(5) == [('Must not match the option.', [])]
def test_integer_type(): schema = Integer() assert schema.validate(1) == [] assert schema.validate(1.0) == [] assert schema.validate(1.5) == [('Must be an integer.', [])] assert schema.validate(True) == [('Must be an integer.', [])]
def test_intersection_of_types(): # validate will never succeed in this case. schema = Integer() & String() assert schema.validate('abc') == [('Must be an integer.', [])] assert schema.validate(123) == [('Must be a string.', [])]