pickle -> sqlite store: D6 async writes, D9 reload race, one-shot pickle migration
This commit is contained in:
+1
-13
@@ -1,6 +1,3 @@
|
||||
import os
|
||||
import pickle
|
||||
import tempfile
|
||||
import unittest
|
||||
from unittest.mock import Mock, patch
|
||||
|
||||
@@ -147,7 +144,6 @@ You always try to say something positive about the current day and the Fjærkroa
|
||||
def test_update_history(self) -> None:
|
||||
updater = self.bot.airesponder
|
||||
updater.history = []
|
||||
updater.history_file = None
|
||||
|
||||
question = {"content": '{"channel": "test_channel", "message": "What is the meaning of life?"}'}
|
||||
answer = {"content": '{"channel": "test_channel", "message": "42"}'}
|
||||
@@ -179,15 +175,7 @@ You always try to say something positive about the current day and the Fjærkroa
|
||||
next_answer2 = {"content": '{"channel": "other_channel", "message": "Tripple Z"}'}
|
||||
updater.update_history(next_question2, next_answer2, 4)
|
||||
self.assertEqual(updater.history, [new_answer, next_answer, next_question2, next_answer2])
|
||||
|
||||
# Test case 5: Check history file save using mock
|
||||
with unittest.mock.patch("builtins.open", unittest.mock.mock_open()) as mock_file:
|
||||
_, temp_path = tempfile.mkstemp()
|
||||
os.remove(temp_path)
|
||||
self.bot.airesponder.history_file = temp_path
|
||||
updater.update_history(question, answer, 2)
|
||||
mock_file.assert_called_with(temp_path, "wb")
|
||||
mock_file().write.assert_called_with(pickle.dumps([question, answer]))
|
||||
# File persistence moved to the SQLite store — covered by PER-01 (SPEC-009)
|
||||
|
||||
|
||||
if __name__ == "__mait__":
|
||||
|
||||
Reference in New Issue
Block a user