コード例 #1
0
ファイル: test_schema.py プロジェクト: lliu8080/roax
 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)
コード例 #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,
     )
コード例 #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)
コード例 #4
0
ファイル: test_schema.py プロジェクト: lliu8080/roax
 def test_one_of_validation_all_match(self):
     self._error(s.one_of([s.str(), s.str()]).validate, "string")
コード例 #5
0
ファイル: test_schema.py プロジェクト: lliu8080/roax
 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)
コード例 #6
0
ファイル: test_schema.py プロジェクト: lliu8080/roax
 def test_one_of_none_match(self):
     self._error(s.one_of([s.str(), s.int()]).validate, 123.45)
コード例 #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)
コード例 #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
コード例 #9
0
def test_one_of_match_none():
    assert s.one_of((s.int(), s.str())).match(False) == None
コード例 #10
0
def test_one_of_match_all():
    assert s.one_of([s.str(), s.str()]).match("string") == None
コード例 #11
0
def test_one_of_match_str():
    assert isinstance(s.one_of((s.int(), s.str())).match("one"), s.str)
コード例 #12
0
def test_one_of_nullable_inner():
    s.one_of((s.int(nullable=True), s.str())).validate(None)
コード例 #13
0
def test_one_of_nullable_outer():
    s.one_of((s.int(), s.str()), nullable=True).validate(None)
コード例 #14
0
def test_one_of_validation_all_match_nullable():
    _error(
        s.one_of([s.str(nullable=True),
                  s.int(nullable=True)]).validate, None)
コード例 #15
0
def test_one_of_validation_all_match_str():
    _error(s.one_of([s.str(), s.str()]).validate, "string")