diff --git a/lib/tfw/components/ide_event_handler/test_filemanager.py b/lib/tfw/components/ide_event_handler/test_file_manager.py similarity index 74% rename from lib/tfw/components/ide_event_handler/test_filemanager.py rename to lib/tfw/components/ide_event_handler/test_file_manager.py index c6e0b8b..33c8024 100644 --- a/lib/tfw/components/ide_event_handler/test_filemanager.py +++ b/lib/tfw/components/ide_event_handler/test_file_manager.py @@ -1,5 +1,6 @@ # pylint: disable=redefined-outer-name +from dataclasses import dataclass from secrets import token_urlsafe from os.path import join from os import chdir, mkdir, symlink @@ -10,11 +11,10 @@ import pytest from file_manager import FileManager - +@dataclass class ManagerContext: - def __init__(self, folder, manager): - self.folder = folder - self.manager = manager + folder: str + manager: FileManager def join(self, path): return join(self.folder, path) @@ -22,20 +22,24 @@ class ManagerContext: @pytest.fixture() def context(): - dirs = [] + dirs = {} with TemporaryDirectory() as workdir: chdir(workdir) - for name in ["allowed", "excluded", "invis"]: + for name in ['allowed', 'excluded', 'invis']: node = join(workdir, name) mkdir(node) Path(join(node, 'empty.txt')).touch() Path(join(node, 'empty.bin')).touch() - dirs.append(node) + dirs[name] = node yield ManagerContext( workdir, - FileManager(dirs[0], dirs[:-1], exclude=['*/excluded/*']) + FileManager( + dirs['allowed'], + [dirs['allowed'], dirs['excluded']], + exclude=['*/excluded/*'] + ) ) @pytest.mark.parametrize('subdir', ['allowed/', 'excluded/']) @@ -99,5 +103,22 @@ def test_read_write_file(context): content = token_urlsafe(32) context.manager.file_contents = content assert context.manager.file_contents == content - with open(context.join('allowed/empty.txt'), "r") as ifile: + with open(context.join('allowed/empty.txt'), 'r') as ifile: assert ifile.read() == content + +def test_regular_ide_actions(context): + context.manager.workdir = context.join('allowed') + newfile1, newfile2 = token_urlsafe(16), token_urlsafe(16) + Path(context.join(f'allowed/{newfile1}')).touch() + Path(context.join(f'allowed/{newfile2}')).touch() + for _ in range(8): + context.manager.filename = newfile1 + content1 = token_urlsafe(32) + context.manager.file_contents = content1 + context.manager.filename = newfile2 + content2 = token_urlsafe(32) + context.manager.file_contents = content2 + context.manager.filename = newfile1 + assert context.manager.file_contents == content1 + context.manager.filename = newfile2 + assert context.manager.file_contents == content2