forked from p15670423/monkey
UT: Update tests as per changes to file repositories
This commit is contained in:
parent
7823759cf8
commit
64990eea0e
|
@ -24,7 +24,7 @@ class MockFileRepository(IFileRepository):
|
|||
def delete_file(self, unsafe_file_name: str):
|
||||
pass
|
||||
|
||||
def delete_files_by_pattern(self, file_name_pattern: str):
|
||||
def delete_files_by_regex(self, file_name_regex: str):
|
||||
pass
|
||||
|
||||
def delete_all_files(self):
|
||||
|
|
|
@ -24,8 +24,8 @@ class SingleFileRepository(IFileRepository):
|
|||
self._file = None
|
||||
self._file_name = ""
|
||||
|
||||
def delete_files_by_pattern(self, file_name_pattern: str):
|
||||
if re.match(file_name_pattern, self._file_name):
|
||||
def delete_files_by_regex(self, file_name_regex: re.Pattern):
|
||||
if re.match(file_name_regex, self._file_name):
|
||||
self.delete_file("")
|
||||
|
||||
def delete_all_files(self):
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import io
|
||||
import re
|
||||
from pathlib import Path
|
||||
from unittest.mock import Mock, patch
|
||||
|
||||
|
@ -145,12 +146,12 @@ def test_open_locked_file(tmp_path, monkeypatch):
|
|||
fss.open_file("locked_file.txt")
|
||||
|
||||
|
||||
def test_delete_files_by_pattern(tmp_path):
|
||||
def test_delete_files_by_regex(tmp_path):
|
||||
for filename in {"xyz-1.txt", "abc-2.txt", "pqr-3.txt", "abc-4.txt", "abc-5.pdf"}:
|
||||
(tmp_path / filename).touch()
|
||||
|
||||
fss = LocalStorageFileRepository(tmp_path)
|
||||
fss.delete_files_by_pattern("abc-*.txt")
|
||||
fss.delete_files_by_regex(re.compile(r"^abc-[\w-]+.txt$"))
|
||||
|
||||
files = {f.name for f in tmp_path.iterdir()}
|
||||
assert files == {"xyz-1.txt", "pqr-3.txt", "abc-5.pdf"}
|
||||
|
|
Loading…
Reference in New Issue