diff --git a/telebot/__init__.py b/telebot/__init__.py index d9bee07..33d459d 100644 --- a/telebot/__init__.py +++ b/telebot/__init__.py @@ -205,7 +205,6 @@ class TeleBot: :param filename: Filename of the file where handlers was saved :param del_file_after_loading: Is passed True, after loading save file will be deleted """ - self.next_step_backend: FileHandlerBackend self.next_step_backend.load_handlers(filename, del_file_after_loading) def load_reply_handlers(self, filename="./.handler-saves/reply.save", del_file_after_loading=True): @@ -221,7 +220,6 @@ class TeleBot: :param filename: Filename of the file where handlers was saved :param del_file_after_loading: Is passed True, after loading save file will be deleted """ - self.reply_backend: FileHandlerBackend self.reply_backend.load_handlers(filename, del_file_after_loading) def set_webhook(self, url=None, certificate=None, max_connections=None, allowed_updates=None): diff --git a/telebot/handler_backends.py b/telebot/handler_backends.py index cb6c688..e71fb24 100644 --- a/telebot/handler_backends.py +++ b/telebot/handler_backends.py @@ -5,7 +5,7 @@ import threading from telebot import apihelper -class HandlerBackend: +class HandlerBackend(object): """ Class for saving (next step|reply) handlers """ @@ -40,7 +40,7 @@ class MemoryHandlerBackend(HandlerBackend): class FileHandlerBackend(HandlerBackend): def __init__(self, handlers=None, filename='./.handler-saves/handlers.save', delay=120): - super().__init__(handlers) + super(FileHandlerBackend, self).__init__(handlers) self.filename = filename self.delay = delay self.timer = threading.Timer(delay, self.save_handlers) @@ -116,7 +116,7 @@ class FileHandlerBackend(HandlerBackend): class RedisHandlerBackend(HandlerBackend): def __init__(self, handlers=None, host='localhost', port=6379, db=0, prefix='telebot'): - super().__init__(handlers) + super(RedisHandlerBackend, self).__init__(handlers) from redis import Redis self.prefix = prefix self.redis = Redis(host, port, db) diff --git a/tests/test_handler_backends.py b/tests/test_handler_backends.py index badc634..6ed2c18 100644 --- a/tests/test_handler_backends.py +++ b/tests/test_handler_backends.py @@ -10,7 +10,8 @@ import time import pytest import telebot -from telebot import types, MemoryHandlerBackend, FileHandlerBackend +from telebot import types +from telebot.handler_backends import MemoryHandlerBackend, FileHandlerBackend if REDIS_TESTS: from telebot.handler_backends import RedisHandlerBackend @@ -230,8 +231,8 @@ def test_file_handler_backend_clear_next_step_handler(telegram_bot, private_chat def test_redis_handler_backend_register_next_step_handler(telegram_bot, private_chat, update_type): - if not(REDIS_TESTS): - return + if not REDIS_TESTS: + pytest.skip('please install redis and configure redis server, then enable REDIS_TESTS') telegram_bot.next_step_backend = RedisHandlerBackend(prefix='pyTelegramBotApi:step_backend1') @@ -248,8 +249,8 @@ def test_redis_handler_backend_register_next_step_handler(telegram_bot, private_ def test_redis_handler_backend_clear_next_step_handler(telegram_bot, private_chat, update_type): - if not(REDIS_TESTS): - return + if not REDIS_TESTS: + pytest.skip('please install redis and configure redis server, then enable REDIS_TESTS') telegram_bot.next_step_backend = RedisHandlerBackend(prefix='pyTelegramBotApi:step_backend2')