From 1b19702cd793950b6ee76b80647d18c62a0d37dd Mon Sep 17 00:00:00 2001 From: FredTheNoob Date: Mon, 11 Dec 2023 13:48:16 +0100 Subject: [PATCH] fix tests --- lib/DirectoryWatcher.py | 2 -- main.py | 6 +++++- tests/unit/test_DirectoryWatcher.py | 4 ++-- tests/unit/test_EntityLinker.py | 8 ++++---- tests/unit/test_GetSpacyData.py | 2 +- 5 files changed, 12 insertions(+), 10 deletions(-) diff --git a/lib/DirectoryWatcher.py b/lib/DirectoryWatcher.py index 6a90c40..7125c9a 100644 --- a/lib/DirectoryWatcher.py +++ b/lib/DirectoryWatcher.py @@ -20,8 +20,6 @@ def on_created(self, event): asyncio.run(self.async_callback(event.src_path)) def start_watching(self): - if not os.path.exists(self.directory): - os.mkdir(self.directory) # Define a thread target function def run_observer(): self.observer.schedule( diff --git a/main.py b/main.py index 9f098e3..818688c 100644 --- a/main.py +++ b/main.py @@ -44,7 +44,11 @@ async def newFileCreated(file_path: str): @app.on_event("startup") async def startEvent(): - dirWatcher.start_watching() + if not os.path.exists(DIRECTORY_TO_WATCH): + os.mkdir(DIRECTORY_TO_WATCH) + + if os.path.exists(DIRECTORY_TO_WATCH): + dirWatcher.start_watching() @app.on_event("shutdown") diff --git a/tests/unit/test_DirectoryWatcher.py b/tests/unit/test_DirectoryWatcher.py index ffe7b76..6b6b2b9 100644 --- a/tests/unit/test_DirectoryWatcher.py +++ b/tests/unit/test_DirectoryWatcher.py @@ -12,10 +12,10 @@ async def test_on_created(): # Mock asyncio.run to avoid the RuntimeError with patch('asyncio.run'): # Simulate an on_created event - event_mock = MagicMock(is_directory=False, src_path='/path/to/file.txt') + event_mock = MagicMock(is_directory=False, src_path='/path/to/watch/file.txt') watcher.on_created(event_mock) # Ensure that async_callback is called with the correct parameters - async_callback_mock.assert_called_once_with('/path/to/file.txt') + async_callback_mock.assert_called_once_with('/path/to/watch/file.txt') @pytest.mark.asyncio async def test_start_and_stop_watching(): diff --git a/tests/unit/test_EntityLinker.py b/tests/unit/test_EntityLinker.py index 3fa5772..64cd991 100644 --- a/tests/unit/test_EntityLinker.py +++ b/tests/unit/test_EntityLinker.py @@ -32,7 +32,7 @@ async def mock_insert(db_path, table, entity_name): ] # Call the entitylinkerFunc - entLinks = await entitylinkerFunc(entMentions) + entLinks = await entitylinkerFunc(entMentions, db_path="DB_PATH") # Check the results assert len(entLinks) == 2 @@ -66,7 +66,7 @@ async def mock_insert(db_path, table, entity_name): ] # Call the entitylinkerFunc - entLinks = await entitylinkerFunc(entMentions) + entLinks = await entitylinkerFunc(entMentions, db_path="DB_PATH") # Check the results assert len(entLinks) == 1 @@ -99,7 +99,7 @@ async def mock_insert(db_path, table, entity_name): ] # Call the entitylinkerFunc - entLinks = await entitylinkerFunc(entMentions) + entLinks = await entitylinkerFunc(entMentions, db_path="DB_PATH") # Check the results assert len(entLinks) == 1 @@ -167,7 +167,7 @@ async def mock_insert(db_path, table, queryInformation): } # Call the entitylinkerFunc - entLinks = await entitylinkerFunc(TestingDataset["test"]) + entLinks = await entitylinkerFunc(TestingDataset["test"], db_path="DB_PATH") for index, link in enumerate(entLinks): assert link.name == TestingDataset["GoldStandardNames"][index] assert link.iri == TestingDataset["GoldStandardIRIs"][index] diff --git a/tests/unit/test_GetSpacyData.py b/tests/unit/test_GetSpacyData.py index 452ced3..e7e1e24 100644 --- a/tests/unit/test_GetSpacyData.py +++ b/tests/unit/test_GetSpacyData.py @@ -15,7 +15,7 @@ def test_GetText_fileExists(): testFile.write("This is a testfile") testText = GetSpacyData.GetText("test_article_file.txt") - assert testText == "This is a testfile" + assert testText == "This is a testfile. " # Test that GetText returns an error if the file does not exist