def test_set_str_decode_crazy_csv_scenario(): assert s.set(items=s.str()).str_decode('a,"b,c",d,"""e"""') == { "a", "b,c", "d", '"e"', }
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)
class Signal: """Detected signal, computed from station reception reports.""" id: s.uuid(description="Identifies signal.") task_id: s.uuid(description="Identifies task that signal is for.") report_ids: s.set(description="Station receiption reports of signal.", items=s.uuid()) time: s.datetime(description="Date and time of signal.") duration: s.int(description="Duration of signal, in seconds.", min=1) location: roax.geo.Point( description="Computed location of transmitting station.") cep: s.int(description="Circle error probable of location, in metres.") _required = "task_id report_ids time duration location cep"
class Member: """User membership in team.""" id: s.uuid(description="Identifies the membership.") team_id: s.uuid(description="Identifies the team.") user_id: s.uuid(description="Identifies the user.") status: s.str( description="Status of user's group membership.", enum={"active", "suspended", "requested", "denied"}, ) roles: s.set( description="User role(s) in team.", items=s.str(enum={"read", "submit", "admin", "owner"}), ) _required = "team_id user_id status roles"
def test_set_json_decode_error(self): self._error(s.set(items=s.str()).json_decode, "not_a_set_either")
def test_set_json_decode_success(self): self._equal(s.set(items=s.float()).json_decode, {1.2, 3.4, 5.6})
def test_set_bin_encode_success(): assert json.loads( s.set(items=s.str()).bin_encode( {"a", "b", "c"}).decode()) == json.loads('["a","b","c"]')
def test_set_allow_none(self): self.assertEqual( s.set(items=s.str(), nullable=True).json_encode(None), None)
def test_set_bin_decode_success(self): self.assertEqual( s.set(items=s.str()).bin_decode(b'["a","b","c"]'), {"a", "b", "c"})
def test_set_str_decode_int_error(self): self._error(s.set(items=s.int()).str_decode, "12,a,34,56")
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_set_validate_type_str_error(self): self._error(s.set(items=s.str()).validate, {4, 5, 6})
def test_set_validate_type_int_success(self): s.set(items=s.int()).validate({1, 2, 3})
def test_set_validate_type_str_success(self): s.set(items=s.str()).validate({"a", "b", "c"})
def test_set_str_decode_int_success(): assert s.set(items=s.int()).str_decode("12,34,56") == {12, 34, 56}
def test_set_allow_none(): assert s.set(items=s.str(), nullable=True).json_encode(None) == None
def test_set_bin_decode_success(): assert s.set(items=s.str()).bin_decode(b'["a","b","c"]') == {"a", "b", "c"}
def test_set_str_decode_str_success(self): self.assertEqual( s.set(items=s.str()).str_decode("a,b,c"), {"a", "b", "c"})
def test_set_validate_type_int_error(self): self._error(s.set(items=s.int()).validate, {"d", "e", "f"})
def test_set_str_decode_int_success(self): self.assertEqual( s.set(items=s.int()).str_decode("12,34,56"), {12, 34, 56})
def test_set_validate_type_error(self): self._error(s.set(items=s.bool()).validate, "this_is_not_a_set")
def test_set_str_decode_crazy_csv_scenario(self): self.assertEqual( s.set(items=s.str()).str_decode('a,"b,c",d,"""e"""'), {"a", "b,c", "d", '"e"'})
def test_set_str_decode_str_encode(): assert s.set(items=s.int()).str_encode({2, 3, 1 }) == "1,2,3" # sorts result
def test_set_bin_encode_success(self): self.assertEqual( json.loads( s.set(items=s.str()).bin_encode({"a", "b", "c"}).decode()), json.loads('["a","b","c"]'))
def test_set_json_encode_type_error(self): self._error(s.set(items=s.str()).json_encode, "i_am_not_a_list")
def test_set_disallow_none(self): self._error(s.set(items=s.str()).json_encode, None)
def test_set_json_encode_item_type_error(self): self._error(s.set(items=s.str()).json_encode, {1, 2, 3})
def test_set_json_encode_success(self): schema = s.set(s.str()) value = {"a", "b", "c"} encdec = schema.json_decode(schema.json_encode(value)) self.assertEqual(encdec, value)
def test_set_str_decode_float_success(): assert s.set(items=s.float()).str_decode("12.34,56.78") == {12.34, 56.78}