Beispiel #1
0
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"',
    }
Beispiel #2
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
Beispiel #3
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)
Beispiel #4
0
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"
Beispiel #5
0
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"
Beispiel #6
0
 def test_set_json_decode_error(self):
     self._error(s.set(items=s.str()).json_decode, "not_a_set_either")
Beispiel #7
0
 def test_set_json_decode_success(self):
     self._equal(s.set(items=s.float()).json_decode, {1.2, 3.4, 5.6})
Beispiel #8
0
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"]')
Beispiel #9
0
 def test_set_allow_none(self):
     self.assertEqual(
         s.set(items=s.str(), nullable=True).json_encode(None), None)
Beispiel #10
0
 def test_set_bin_decode_success(self):
     self.assertEqual(
         s.set(items=s.str()).bin_decode(b'["a","b","c"]'), {"a", "b", "c"})
Beispiel #11
0
 def test_set_str_decode_int_error(self):
     self._error(s.set(items=s.int()).str_decode, "12,a,34,56")
Beispiel #12
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})
Beispiel #13
0
 def test_set_validate_type_str_error(self):
     self._error(s.set(items=s.str()).validate, {4, 5, 6})
Beispiel #14
0
 def test_set_validate_type_int_success(self):
     s.set(items=s.int()).validate({1, 2, 3})
Beispiel #15
0
 def test_set_validate_type_str_success(self):
     s.set(items=s.str()).validate({"a", "b", "c"})
Beispiel #16
0
def test_set_str_decode_int_success():
    assert s.set(items=s.int()).str_decode("12,34,56") == {12, 34, 56}
Beispiel #17
0
def test_set_allow_none():
    assert s.set(items=s.str(), nullable=True).json_encode(None) == None
Beispiel #18
0
def test_set_bin_decode_success():
    assert s.set(items=s.str()).bin_decode(b'["a","b","c"]') == {"a", "b", "c"}
Beispiel #19
0
 def test_set_str_decode_str_success(self):
     self.assertEqual(
         s.set(items=s.str()).str_decode("a,b,c"), {"a", "b", "c"})
Beispiel #20
0
 def test_set_validate_type_int_error(self):
     self._error(s.set(items=s.int()).validate, {"d", "e", "f"})
Beispiel #21
0
 def test_set_str_decode_int_success(self):
     self.assertEqual(
         s.set(items=s.int()).str_decode("12,34,56"), {12, 34, 56})
Beispiel #22
0
 def test_set_validate_type_error(self):
     self._error(s.set(items=s.bool()).validate, "this_is_not_a_set")
Beispiel #23
0
 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"'})
Beispiel #24
0
def test_set_str_decode_str_encode():
    assert s.set(items=s.int()).str_encode({2, 3, 1
                                            }) == "1,2,3"  # sorts result
Beispiel #25
0
 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"]'))
Beispiel #26
0
 def test_set_json_encode_type_error(self):
     self._error(s.set(items=s.str()).json_encode, "i_am_not_a_list")
Beispiel #27
0
 def test_set_disallow_none(self):
     self._error(s.set(items=s.str()).json_encode, None)
Beispiel #28
0
 def test_set_json_encode_item_type_error(self):
     self._error(s.set(items=s.str()).json_encode, {1, 2, 3})
Beispiel #29
0
 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)
Beispiel #30
0
def test_set_str_decode_float_success():
    assert s.set(items=s.float()).str_decode("12.34,56.78") == {12.34, 56.78}