@@ -335,6 +335,23 @@ def good_pickle_files(user_data, chat_data, bot_data, conversations):
335
335
os .remove (name )
336
336
337
337
338
+ @pytest .fixture (scope = 'function' )
339
+ def pickle_files_wo_bot_data (user_data , chat_data , conversations ):
340
+ all = {'user_data' : user_data , 'chat_data' : chat_data , 'conversations' : conversations }
341
+ with open ('pickletest_user_data' , 'wb' ) as f :
342
+ pickle .dump (user_data , f )
343
+ with open ('pickletest_chat_data' , 'wb' ) as f :
344
+ pickle .dump (chat_data , f )
345
+ with open ('pickletest_conversations' , 'wb' ) as f :
346
+ pickle .dump (conversations , f )
347
+ with open ('pickletest' , 'wb' ) as f :
348
+ pickle .dump (all , f )
349
+ yield True
350
+ for name in ['pickletest_user_data' , 'pickletest_chat_data' ,
351
+ 'pickletest_conversations' , 'pickletest' ]:
352
+ os .remove (name )
353
+
354
+
338
355
@pytest .fixture (scope = 'function' )
339
356
def update (bot ):
340
357
user = User (id = 321 , first_name = 'test_user' , is_bot = False )
@@ -447,6 +464,54 @@ def test_with_good_single_file(self, pickle_persistence, good_pickle_files):
447
464
with pytest .raises (KeyError ):
448
465
conversation2 [(123 , 123 )]
449
466
467
+ def test_with_multi_file_wo_bot_data (self , pickle_persistence , pickle_files_wo_bot_data ):
468
+ user_data = pickle_persistence .get_user_data ()
469
+ assert isinstance (user_data , defaultdict )
470
+ assert user_data [12345 ]['test1' ] == 'test2'
471
+ assert user_data [67890 ][3 ] == 'test4'
472
+ assert user_data [54321 ] == {}
473
+
474
+ chat_data = pickle_persistence .get_chat_data ()
475
+ assert isinstance (chat_data , defaultdict )
476
+ assert chat_data [- 12345 ]['test1' ] == 'test2'
477
+ assert chat_data [- 67890 ][3 ] == 'test4'
478
+ assert chat_data [- 54321 ] == {}
479
+
480
+ bot_data = pickle_persistence .get_bot_data ()
481
+ assert isinstance (bot_data , dict )
482
+ assert not bot_data .keys ()
483
+
484
+ conversation1 = pickle_persistence .get_conversations ('name1' )
485
+ assert isinstance (conversation1 , dict )
486
+ assert conversation1 [(123 , 123 )] == 3
487
+ assert conversation1 [(456 , 654 )] == 4
488
+ with pytest .raises (KeyError ):
489
+ conversation1 [(890 , 890 )]
490
+ conversation2 = pickle_persistence .get_conversations ('name2' )
491
+ assert isinstance (conversation1 , dict )
492
+ assert conversation2 [(123 , 321 )] == 1
493
+ assert conversation2 [(890 , 890 )] == 2
494
+ with pytest .raises (KeyError ):
495
+ conversation2 [(123 , 123 )]
496
+
497
+ def test_with_single_file_wo_bot_data (self , pickle_persistence , pickle_files_wo_bot_data ):
498
+ pickle_persistence .single_file = True
499
+ user_data = pickle_persistence .get_user_data ()
500
+ assert isinstance (user_data , defaultdict )
501
+ assert user_data [12345 ]['test1' ] == 'test2'
502
+ assert user_data [67890 ][3 ] == 'test4'
503
+ assert user_data [54321 ] == {}
504
+
505
+ chat_data = pickle_persistence .get_chat_data ()
506
+ assert isinstance (chat_data , defaultdict )
507
+ assert chat_data [- 12345 ]['test1' ] == 'test2'
508
+ assert chat_data [- 67890 ][3 ] == 'test4'
509
+ assert chat_data [- 54321 ] == {}
510
+
511
+ bot_data = pickle_persistence .get_bot_data ()
512
+ assert isinstance (bot_data , dict )
513
+ assert not bot_data .keys ()
514
+
450
515
def test_updating_multi_file (self , pickle_persistence , good_pickle_files ):
451
516
user_data = pickle_persistence .get_user_data ()
452
517
user_data [54321 ]['test9' ] = 'test 10'
@@ -659,7 +724,7 @@ def first(update, context):
659
724
if not context .chat_data == {}:
660
725
pytest .fail ()
661
726
if not context .bot_data == bot_data :
662
- pytest .failt ()
727
+ pytest .fail ()
663
728
context .user_data ['test1' ] = 'test2'
664
729
context .chat_data ['test3' ] = 'test4'
665
730
context .bot_data ['test1' ] = 'test0'
0 commit comments