def test_dict_json_encode_optional_success(): _equal( s.dict({ "ejc": s.float(), "ejd": s.bool() }, {"ejc"}).json_encode, {"ejc": 123.45}, )
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 })
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 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
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)
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, )
def test_float_json_decode_error(self): self._error(s.float().json_decode, "10.2")
def test_float_json_decode_float(self): self._equal(s.float().json_decode, 9.1)
def test_set_json_decode_success(self): self._equal(s.set(items=s.float()).json_decode, {1.2, 3.4, 5.6})
def test_list_json_decode_success(self): self._equal(s.list(items=s.float()).json_decode, [1.2, 3.4, 5.6])
def test_float_allow_none(self): self.assertEqual(s.float(nullable=True).json_encode(None), None)
def test_float_validate_enum_error(self): self._error(s.float(enum=[6.7, 8.9, 10.11]).validate, 12.13)
def test_float_str_decode_error(self): self._error(s.float().str_decode, "1,2")
def test_float_validate_minimum_error(self): self._error(s.float(minimum=2.0).validate, 1.9)
def test_float_validate_minimum_success(self): s.float(minimum=1.0).validate(1.1)
def test_float_validate_type_error(self): self._error(s.float().validate, "123.45")
def test_float_validate_type_success(self): s.float().validate(123.45)
def test_dict_validate_required_success(self): s.dict({"e": s.float()}, {"e"}).validate({"e": 1.2})
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})
def test_float_str_decode_float(self): self.assertEqual(s.float().str_decode("11.3"), 11.3)
def test_float_str_decode_int(self): self.assertEqual(s.float().str_decode("12"), 12.0)
def test_float_validate_maximum_success(self): s.float(maximum=3.0).validate(2.9)
def test_float_validate_enum_success(self): s.float(enum=[1.2, 3.4, 5.6]).validate(3.4)
def test_float_validate_maximum_error(self): self._error(s.float(maximum=4.0).validate, 4.1)
def test_float_disallow_none(self): self._error(s.float().json_encode, None)
def test_float_json_encode_error(self): self._error(s.float().json_encode, 7)
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_float_json_decode_int(self): self.assertEqual(s.float().json_decode(8), 8.0)
def test_float_json_encode_success(self): self._equal(s.float().json_encode, 6.1)
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])