chat: ChatDB now correctly ignores files that contain no valid messages
This commit is contained in:
+13
-1
@@ -2,6 +2,7 @@ import unittest
|
||||
import pathlib
|
||||
import tempfile
|
||||
import time
|
||||
import yaml
|
||||
from io import StringIO
|
||||
from unittest.mock import patch
|
||||
from chatmastermind.tags import TagLine
|
||||
@@ -156,13 +157,24 @@ class TestChatDB(unittest.TestCase):
|
||||
next_fname = pathlib.Path(self.db_path.name) / '.next'
|
||||
with open(next_fname, 'w') as f:
|
||||
f.write('4')
|
||||
# add some "trash" in order to test if it's correctly handled / ignored
|
||||
self.trash_files = ['.config.yaml', 'foo.yaml', 'bla.txt']
|
||||
for file in self.trash_files:
|
||||
with open(pathlib.Path(self.db_path.name) / file, 'w') as f:
|
||||
f.write('test trash')
|
||||
# also create a file with actual yaml content
|
||||
with open(pathlib.Path(self.db_path.name) / 'content.yaml', 'w') as f:
|
||||
yaml.dump({'key': 'value'}, f)
|
||||
self.trash_files.append('content.yaml')
|
||||
|
||||
self.maxDiff = None
|
||||
|
||||
def message_list(self, tmp_dir: tempfile.TemporaryDirectory) -> list[pathlib.Path]:
|
||||
"""
|
||||
List all Message files in the given TemporaryDirectory.
|
||||
"""
|
||||
# exclude '.next'
|
||||
return list(pathlib.Path(tmp_dir.name).glob('*.[ty]*'))
|
||||
return [f for f in pathlib.Path(tmp_dir.name).glob('*.[ty]*') if f.name not in self.trash_files]
|
||||
|
||||
def tearDown(self) -> None:
|
||||
self.db_path.cleanup()
|
||||
|
||||
Reference in New Issue
Block a user