Ejemplo n.º 1
0
 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)
Ejemplo n.º 2
0
 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,
     )
Ejemplo n.º 3
0
 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)
Ejemplo n.º 4
0
 def test_one_of_validation_all_match(self):
     self._error(s.one_of([s.str(), s.str()]).validate, "string")
Ejemplo n.º 5
0
 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)
Ejemplo n.º 6
0
 def test_one_of_none_match(self):
     self._error(s.one_of([s.str(), s.int()]).validate, 123.45)
Ejemplo n.º 7
0
def test_one_of_match_inner_none_single():
    assert isinstance(
        s.one_of((s.str(nullable=True), s.int())).match(None), s.str)
Ejemplo n.º 8
0
def test_one_of_match_inner_none_ambiguous():
    assert s.one_of(
        (s.str(nullable=True), s.int(nullable=True))).match(None) == None
Ejemplo n.º 9
0
def test_one_of_match_none():
    assert s.one_of((s.int(), s.str())).match(False) == None
Ejemplo n.º 10
0
def test_one_of_match_all():
    assert s.one_of([s.str(), s.str()]).match("string") == None
Ejemplo n.º 11
0
def test_one_of_match_str():
    assert isinstance(s.one_of((s.int(), s.str())).match("one"), s.str)
Ejemplo n.º 12
0
def test_one_of_nullable_inner():
    s.one_of((s.int(nullable=True), s.str())).validate(None)
Ejemplo n.º 13
0
def test_one_of_nullable_outer():
    s.one_of((s.int(), s.str()), nullable=True).validate(None)
Ejemplo n.º 14
0
def test_one_of_validation_all_match_nullable():
    _error(
        s.one_of([s.str(nullable=True),
                  s.int(nullable=True)]).validate, None)
Ejemplo n.º 15
0
def test_one_of_validation_all_match_str():
    _error(s.one_of([s.str(), s.str()]).validate, "string")