示例#1
0
 def test_iter(self):
     # given
     sfs = collections.SnowflakeSet()
     sfs._ids.extend([9, 18, 27, 36, 45, 54, 63])
     # then
     assert list(iter(sfs)) == [9, 18, 27, 36, 45, 54, 63]
     assert list(sfs) == [9, 18, 27, 36, 45, 54, 63]
示例#2
0
 def test_init_creates_array(self):
     # given
     array = collections.SnowflakeSet(9, 8, 7, 8)._ids
     # then
     assert len(array) == 3, "wrong size"
     assert isinstance(array, array_.array)
     assert array.tolist() == [7, 8, 9]
示例#3
0
    def deserialize_message_delete_bulk_event(
            self, shard: gateway_shard.GatewayShard,
            payload: data_binding.JSONObject
    ) -> message_events.MessageDeleteEvent:

        message_ids = collections.SnowflakeSet(
            *(snowflakes.Snowflake(message_id)
              for message_id in payload["ids"]))
        channel_id = snowflakes.Snowflake(payload["channel_id"])

        if "guild_id" in payload:
            return message_events.GuildMessageDeleteEvent(
                app=self._app,
                shard=shard,
                channel_id=channel_id,
                guild_id=snowflakes.Snowflake(payload["guild_id"]),
                message_ids=message_ids,
                is_bulk=True,
            )

        return message_events.DMMessageDeleteEvent(app=self._app,
                                                   shard=shard,
                                                   channel_id=channel_id,
                                                   message_ids=message_ids,
                                                   is_bulk=True)
示例#4
0
 def test_clear_empties_empty_buffer(self):
     # given
     sfs = collections.SnowflakeSet()
     assert len(sfs._ids) == 0
     # when
     sfs.clear()
     # then
     assert len(sfs._ids) == 0
示例#5
0
 def test_clear_empties_buffer(self):
     # given
     sfs = collections.SnowflakeSet(123, 121, 999991, 121, 121, 124, 120)
     assert len(sfs._ids) != 0
     # when
     sfs.clear()
     # then
     assert len(sfs._ids) == 0
示例#6
0
 def test_add_all_inserts_items(self, start_with, add_items, expect):
     # given
     sfs = collections.SnowflakeSet()
     sfs._ids.extend(start_with)
     # when
     sfs.add_all(add_items)
     # then
     assert sfs._ids.tolist() == expect
示例#7
0
 def test_discard(self, start_with, discard, expect):
     # given
     sfs = collections.SnowflakeSet()
     sfs._ids.extend(start_with)
     # when
     for item in discard:
         sfs.discard(item)
     # then
     assert sfs._ids.tolist() == expect
示例#8
0
 def test_add_all_when_empty_collection_passed(self):
     started = [0, 122]
     # given
     sfs = collections.SnowflakeSet()
     sfs._ids.extend(started)
     # when
     sfs.add_all([])
     # then
     assert sfs._ids.tolist() == started
示例#9
0
 def deserialize_guild_message_delete_bulk_event(
     self,
     shard: gateway_shard.GatewayShard,
     payload: data_binding.JSONObject,
     old_messages: typing.Mapping[snowflakes.Snowflake,
                                  messages_models.Message],
 ) -> message_events.GuildBulkMessageDeleteEvent:
     return message_events.GuildBulkMessageDeleteEvent(
         app=self._app,
         shard=shard,
         channel_id=snowflakes.Snowflake(payload["channel_id"]),
         guild_id=snowflakes.Snowflake(payload["guild_id"]),
         message_ids=collections.SnowflakeSet(
             *(snowflakes.Snowflake(message_id)
               for message_id in payload["ids"])),
         old_messages=old_messages,
     )
示例#10
0
 def test_sizeof(self):
     sfs = collections.SnowflakeSet()
     sfs._ids.extend([1, 3, 5, 7, 8])
     assert sfs.__sizeof__() == object.__sizeof__(sfs) + sys.getsizeof(
         sfs._ids)
示例#11
0
 def test_str(self):
     sfs = collections.SnowflakeSet()
     sfs._ids.extend([1, 3, 5, 7, 8])
     assert str(sfs) == "{1, 3, 5, 7, 8}"
示例#12
0
 def test_repr(self):
     sfs = collections.SnowflakeSet()
     sfs._ids.extend([1, 3, 5, 7, 8])
     assert repr(sfs) == "SnowflakeSet(1, 3, 5, 7, 8)"
示例#13
0
 def test_length_hint(self, items):
     # given
     sfs = collections.SnowflakeSet()
     sfs._ids.extend(i for i in range(items))
     # then
     assert operator.length_hint(sfs) == items
示例#14
0
 def test_contains(self, start_with, look_for, expect):
     # given
     sfs = collections.SnowflakeSet()
     sfs._ids.extend(start_with)
     # then
     assert (look_for in sfs) is expect
示例#15
0
 def test_init_creates_empty_array(self):
     # given
     array = collections.SnowflakeSet()._ids
     # then
     assert len(array) == 0, "not empty"
     assert isinstance(array, array_.array)