예제 #1
0
def test_dict_json_encode_optional_success():
    _equal(
        s.dict({
            "ejc": s.float(),
            "ejd": s.bool()
        }, {"ejc"}).json_encode,
        {"ejc": 123.45},
    )
예제 #2
0
 def test_dict_json_decode_success(self):
     self._equal(
         s.dict({
             "dja": s.float(),
             "djb": s.bool()
         }, {"dja", "djb"}).json_decode, {
             "dja": 802.11,
             "djb": True
         })
예제 #3
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,
     )
예제 #4
0
 def test(
         self,
         a: s.list(s.str()),
         b: s.set(s.str()),
         c: s.int(),
         d: s.float(),
         e: s.bool(),
         f: s.bytes(),
         g: s.datetime(),
         h: s.uuid(),
 ):
     pass
예제 #5
0
class DC:
    id: s.uuid()
    str: s.str(nullable=True)
    dict: s.dict({"a": s.int()}, nullable=True)
    list: s.list(s.int(), nullable=True)
    _set: s.set(s.str(), nullable=True)
    int: s.int(nullable=True)
    float: s.float(nullable=True)
    bool: s.bool(nullable=True)
    bytes: s.bytes(format="byte", nullable=True)
    date: s.date(nullable=True)
    datetime: s.datetime(nullable=True)
예제 #6
0
 def __init__(
         self,
         *,
         python_type,
         content_type="application/json",
         props={},
         required=set(),
         additional=False,
         **kwargs,
 ):
     super().__init__(python_type=python_type,
                      content_type=content_type,
                      **kwargs)
     self.schema = s.dict(
         {
             "type": s.str(enum={self.__class__.__name__}),
             "bbox": s.list(items=s.float(), min_items=4),
             **props,
         },
         required={"type"}.union(required),
         additional=additional,
     )
예제 #7
0
 def test_float_json_decode_error(self):
     self._error(s.float().json_decode, "10.2")
예제 #8
0
 def test_float_json_decode_float(self):
     self._equal(s.float().json_decode, 9.1)
예제 #9
0
 def test_set_json_decode_success(self):
     self._equal(s.set(items=s.float()).json_decode, {1.2, 3.4, 5.6})
예제 #10
0
 def test_list_json_decode_success(self):
     self._equal(s.list(items=s.float()).json_decode, [1.2, 3.4, 5.6])
예제 #11
0
 def test_float_allow_none(self):
     self.assertEqual(s.float(nullable=True).json_encode(None), None)
예제 #12
0
 def test_float_validate_enum_error(self):
     self._error(s.float(enum=[6.7, 8.9, 10.11]).validate, 12.13)
예제 #13
0
 def test_float_str_decode_error(self):
     self._error(s.float().str_decode, "1,2")
예제 #14
0
 def test_float_validate_minimum_error(self):
     self._error(s.float(minimum=2.0).validate, 1.9)
예제 #15
0
 def test_float_validate_minimum_success(self):
     s.float(minimum=1.0).validate(1.1)
예제 #16
0
 def test_float_validate_type_error(self):
     self._error(s.float().validate, "123.45")
예제 #17
0
 def test_float_validate_type_success(self):
     s.float().validate(123.45)
예제 #18
0
 def test_dict_validate_required_success(self):
     s.dict({"e": s.float()}, {"e"}).validate({"e": 1.2})
예제 #19
0
 def test_set_str_decode_float_success(self):
     self.assertEqual(
         s.set(items=s.float()).str_decode("12.34,56.78"), {12.34, 56.78})
예제 #20
0
 def test_float_str_decode_float(self):
     self.assertEqual(s.float().str_decode("11.3"), 11.3)
예제 #21
0
 def test_float_str_decode_int(self):
     self.assertEqual(s.float().str_decode("12"), 12.0)
예제 #22
0
 def test_float_validate_maximum_success(self):
     s.float(maximum=3.0).validate(2.9)
예제 #23
0
 def test_float_validate_enum_success(self):
     s.float(enum=[1.2, 3.4, 5.6]).validate(3.4)
예제 #24
0
 def test_float_validate_maximum_error(self):
     self._error(s.float(maximum=4.0).validate, 4.1)
예제 #25
0
 def test_float_disallow_none(self):
     self._error(s.float().json_encode, None)
예제 #26
0
 def test_float_json_encode_error(self):
     self._error(s.float().json_encode, 7)
예제 #27
0
 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)
예제 #28
0
 def test_float_json_decode_int(self):
     self.assertEqual(s.float().json_decode(8), 8.0)
예제 #29
0
 def test_float_json_encode_success(self):
     self._equal(s.float().json_encode, 6.1)
예제 #30
0
 def test_list_str_decode_float_success(self):
     self.assertEqual(
         s.list(items=s.float()).str_decode("12.34,56.78"), [12.34, 56.78])