def test_any_of_json_codec(self): for value in [123.45, False]: schema = s.any_of([s.float(), s.bool()]) self.assertEqual(schema.json_decode(schema.json_encode(value)), value)
def test_any_of_none_match(self): self._error(s.any_of([s.str(), s.int()]).validate, 123.45)
def test_any_of_either_match(self): s.any_of([s.str(), s.int()]).validate("one") s.any_of([s.str(), s.int()]).validate(1)
def test_any_of_json_codec(): for value in [123.45, False]: schema = s.any_of([s.float(), s.bool()]) assert schema.json_decode(schema.json_encode(value)) == value
def test_any_of_match_str(): assert isinstance(s.any_of((s.int(), s.str())).match("one"), s.str)
def test_any_of_match_int(): assert isinstance(s.any_of((s.int(), s.str())).match(1), s.int)
def test_any_of_nullable_inner(): s.any_of((s.int(nullable=True), s.str())).validate(None)
def test_any_of_nullable_outer(): s.any_of((s.int(), s.str()), nullable=True).validate(None)