Esempio n. 1
0
    def test_data_type_schema(self) -> None:
        """
        We really only test this to get test coverage.  The
        code covered here is really only used in testing tools.
        """
        test_schema = DictType([
            ("type", Equals("realm")),
            ("maybe_n", OptionalType(int)),
            ("s", str),
            ("timestamp", NumberType()),
            ("flag", bool),
            ("tup", TupleType([int, str])),
            ("level", EnumType([1, 2, 3])),
            ("lst", ListType(int)),
            ("config", StringDictType(str)),
            ("value", UnionType([int, str])),
            ("url", UrlType()),
        ])
        expected = """
test (dict):
    config (string_dict):
        value: str
    flag: bool
    level in [1, 2, 3]
    lst (list):
        type: int
    maybe_n: int
    s: str
    timestamp: number
    tup (tuple):
        0: int
        1: str
    type in ['realm']
    url: str
    value (union):
        type: int
        type: str
"""
        self.assertEqual(schema("test", test_schema).strip(), expected.strip())
Esempio n. 2
0
    ),
])
check_hotspots = make_checker(hotspots_event)

invites_changed_event = event_dict_type(required_keys=[
    # the most boring event...no metadata
    ("type", Equals("invites_changed")),
])
check_invites_changed = make_checker(invites_changed_event)

# This type, like other instances of TupleType, is a legacy feature of
# a very old Zulip API; we plan to replace it with an object as those
# are more extensible.
muted_topic_type = TupleType([
    str,  # stream name
    str,  # topic name
    int,  # timestamp
])

muted_topics_event = event_dict_type(required_keys=[
    ("type", Equals("muted_topics")),
    ("muted_topics", ListType(muted_topic_type)),
])
check_muted_topics = make_checker(muted_topics_event)

muted_user_type = DictType(required_keys=[
    ("id", int),
    ("timestamp", int),
])

muted_users_event = event_dict_type(required_keys=[