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]
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]
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)
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
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
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
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
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
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, )
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)
def test_str(self): sfs = collections.SnowflakeSet() sfs._ids.extend([1, 3, 5, 7, 8]) assert str(sfs) == "{1, 3, 5, 7, 8}"
def test_repr(self): sfs = collections.SnowflakeSet() sfs._ids.extend([1, 3, 5, 7, 8]) assert repr(sfs) == "SnowflakeSet(1, 3, 5, 7, 8)"
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
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
def test_init_creates_empty_array(self): # given array = collections.SnowflakeSet()._ids # then assert len(array) == 0, "not empty" assert isinstance(array, array_.array)