Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
FredTheNoob committed Dec 11, 2023
1 parent 9ac335e commit 1b19702
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 10 deletions.
2 changes: 0 additions & 2 deletions lib/DirectoryWatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
6 changes: 5 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/test_DirectoryWatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/test_EntityLinker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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]
2 changes: 1 addition & 1 deletion tests/unit/test_GetSpacyData.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1b19702

Please sign in to comment.