def test_one_of_json_codec(self): for value in [ 123, UUID("06b959d0-65e0-11e7-866d-6be08781d5cb"), False ]: schema = s.one_of([s.int(), s.uuid(), s.bool()]) self.assertEqual(schema.json_decode(schema.json_encode(value)), value)
def __init__(self, **kwargs): super().__init__( python_type=geojson.Feature, props={ "geometry": Geometry(nullable=True).schema, "properties": s.dict(props={}, additional=True, nullable=True), "id": s.one_of({s.str(), s.int(), s.float()}), }, required={"geometry", "properties"}, **kwargs, )
def __init__(self, **kwargs): super().__init__( { Point(), MultiPoint(), LineString(), MultiLineString(), Polygon(), MultiPolygon(), }, **kwargs, ) self.schema = s.one_of([sch.schema for sch in self.schemas], **kwargs)
def test_one_of_validation_all_match(self): self._error(s.one_of([s.str(), s.str()]).validate, "string")
def test_one_of_either_match(self): s.one_of([s.str(), s.int()]).validate("one") s.one_of([s.str(), s.int()]).validate(1)
def test_one_of_none_match(self): self._error(s.one_of([s.str(), s.int()]).validate, 123.45)
def test_one_of_match_inner_none_single(): assert isinstance( s.one_of((s.str(nullable=True), s.int())).match(None), s.str)
def test_one_of_match_inner_none_ambiguous(): assert s.one_of( (s.str(nullable=True), s.int(nullable=True))).match(None) == None
def test_one_of_match_none(): assert s.one_of((s.int(), s.str())).match(False) == None
def test_one_of_match_all(): assert s.one_of([s.str(), s.str()]).match("string") == None
def test_one_of_match_str(): assert isinstance(s.one_of((s.int(), s.str())).match("one"), s.str)
def test_one_of_nullable_inner(): s.one_of((s.int(nullable=True), s.str())).validate(None)
def test_one_of_nullable_outer(): s.one_of((s.int(), s.str()), nullable=True).validate(None)
def test_one_of_validation_all_match_nullable(): _error( s.one_of([s.str(nullable=True), s.int(nullable=True)]).validate, None)
def test_one_of_validation_all_match_str(): _error(s.one_of([s.str(), s.str()]).validate, "string")