async def test_with_context_types(self, ud, cd, bd, singlefile):
        cc = ContextTypes(user_data=ud, chat_data=cd, bot_data=bd)
        persistence = PicklePersistence("pickletest",
                                        single_file=singlefile,
                                        context_types=cc)

        assert isinstance(await persistence.get_bot_data(), bd)
        assert await persistence.get_bot_data() == 0

        persistence.user_data = None
        persistence.chat_data = None
        await persistence.drop_user_data(123)
        await persistence.drop_chat_data(123)
        assert isinstance(await persistence.get_user_data(), dict)
        assert isinstance(await persistence.get_chat_data(), dict)
        persistence.user_data = None
        persistence.chat_data = None
        await persistence.update_user_data(1, ud(1))
        await persistence.update_chat_data(1, cd(1))
        await persistence.update_bot_data(bd(1))
        assert (await persistence.get_user_data())[1] == 1
        assert (await persistence.get_chat_data())[1] == 1
        assert await persistence.get_bot_data() == 1

        await persistence.flush()
        persistence = PicklePersistence("pickletest",
                                        single_file=singlefile,
                                        context_types=cc)
        assert isinstance((await persistence.get_user_data())[1], ud)
        assert (await persistence.get_user_data())[1] == 1
        assert isinstance((await persistence.get_chat_data())[1], cd)
        assert (await persistence.get_chat_data())[1] == 1
        assert isinstance(await persistence.get_bot_data(), bd)
        assert await persistence.get_bot_data() == 1
コード例 #2
0
ファイル: convert_pp.py プロジェクト: Yossi/cwtgbot
        for attr_name, attr in new_obj.__dict__.items():
            setattr(new_obj, attr_name, replace_bot(attr))
        return new_obj
    if hasattr(obj, '__slots__'):
        for attr_name in new_obj.__slots__:
            setattr(new_obj, attr_name,
                    replace_bot(replace_bot(getattr(new_obj, attr_name))))
        return new_obj

    return obj


print('Loading data.')
if persistence.single_file:
    persistence.load_singlefile()
else:
    for data in ['bot', 'chat', 'user']:
        persistence.load_file('{}_{}_data'.format(persistence.filename, data))
print('Done.')

print('Converting data.')
persistence.bot_data = replace_bot(persistence.bot_data)
persistence.chat_data = replace_bot(persistence.chat_data)
persistence.user_data = replace_bot(persistence.user_data)
print('Done.')

print('Writing to file.')
persistence.flush()
print(
    'Done. Upgrade to v13 now and run your bot to make sure everything works.')