Skip to content

Commit 65b8d65

Browse files
committed
increasing coverage
1 parent 0fd9a4e commit 65b8d65

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

tests/test_dispatcher.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#
1717
# You should have received a copy of the GNU Lesser Public License
1818
# along with this program. If not, see [http://www.gnu.org/licenses/].
19+
import logging
1920
from queue import Queue
2021
from threading import current_thread
2122
from time import sleep
@@ -82,6 +83,18 @@ def test_error_handler(self, dp):
8283
sleep(.1)
8384
assert self.received is None
8485

86+
def test_construction_with_bad_persistence(self, caplog, bot):
87+
class my_per:
88+
def __init__(self):
89+
self.store_user_data = False
90+
self.store_chat_data = False
91+
92+
with caplog.at_level(logging.WARNING):
93+
Dispatcher(bot, None, persistence=my_per())
94+
rec = caplog.records[-1]
95+
assert rec.msg == 'persistence should be based on Telegram.ext.BasePersistence'
96+
assert rec.levelname == 'WARNING'
97+
8598
def test_error_handler_that_raises_errors(self, dp):
8699
"""
87100
Make sure that errors raised in error handlers don't break the main loop of the dispatcher

tests/test_pickle_persistence.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,11 @@ def update(bot):
8181
class TestPickelPersistence(object):
8282
def test_no_files_present_multi_file(self, pickle_persistence):
8383
assert pickle_persistence.get_user_data() == defaultdict(dict)
84+
assert pickle_persistence.get_user_data() == defaultdict(dict)
85+
assert pickle_persistence.get_chat_data() == defaultdict(dict)
8486
assert pickle_persistence.get_chat_data() == defaultdict(dict)
8587
assert pickle_persistence.get_conversations('noname') == {}
88+
assert pickle_persistence.get_conversations('noname') == {}
8689

8790
def test_no_files_present_single_file(self, pickle_persistence):
8891
pickle_persistence.single_file = True
@@ -219,6 +222,8 @@ def test_updating_single_file(self, pickle_persistence, good_pickle_files):
219222
assert conversations_test['name1'] == conversation1
220223

221224
def test_save_on_flush_multi_files(self, pickle_persistence, good_pickle_files):
225+
# Should run without error
226+
pickle_persistence.flush()
222227
pickle_persistence.on_flush = True
223228

224229
user_data = pickle_persistence.get_user_data()
@@ -268,6 +273,9 @@ def test_save_on_flush_multi_files(self, pickle_persistence, good_pickle_files):
268273
assert conversations_test['name1'] == conversation1
269274

270275
def test_save_on_flush_single_files(self, pickle_persistence, good_pickle_files):
276+
# Should run without error
277+
pickle_persistence.flush()
278+
271279
pickle_persistence.on_flush = True
272280
pickle_persistence.single_file = True
273281

0 commit comments

Comments
 (0)