Skip to content

Commit b8e8335

Browse files
Address review on missing-lexicon test
- Group the new imports into a single sorted block and keep wn separate - Use generic exception messages since the recovery path matches on the exception type, not the message text, so an unpinned wn version will not break the test - Load the probe through garak._plugins.load_plugin like the other tests instead of instantiating the class directly Signed-off-by: Aditya Singh <adisin650@gmail.com>
1 parent b1601a8 commit b8e8335

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

tests/probes/test_probes_topic.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
# SPDX-License-Identifier: Apache-2.0
33

44
import pathlib
5+
import pytest
56
import sqlite3
67
from unittest.mock import MagicMock, patch
78

8-
import pytest
99
import wn
1010

1111
import garak._plugins
@@ -80,16 +80,18 @@ def test_topic_wordnet_blocklist_get_initial_nodes(sysnet):
8080
@pytest.mark.parametrize(
8181
"first_call_error",
8282
[
83-
sqlite3.OperationalError("no such table: lexicons"),
84-
wn.Error("no lexicon found with lang=None and lexicon='oewn:2023'"),
83+
sqlite3.OperationalError("database not initialised"),
84+
wn.Error("requested lexicon is not installed"),
8585
],
8686
ids=["sqlite_missing_database", "wn_missing_lexicon"],
8787
)
8888
def test_topic_wordnet_downloads_missing_lexicon(first_call_error):
8989
# when the lexicon cannot be opened the probe should download it and retry,
9090
# rather than letting the underlying error propagate and fail to load.
91-
# wn.Error covers the case where the database exists but the requested
92-
# lexicon is not installed, see https://github.com/NVIDIA/garak/issues/1230
91+
# The recovery path keys off the exception type (sqlite3.OperationalError for
92+
# a missing database, wn.Error for a missing lexicon, see
93+
# https://github.com/NVIDIA/garak/issues/1230), so the message text here is
94+
# only illustrative and does not need to track wn's exact wording.
9395
loaded_wordnet = MagicMock(name="wn.Wordnet")
9496
download_path = MagicMock(name="download_tempfile_path")
9597

@@ -100,7 +102,7 @@ def test_topic_wordnet_downloads_missing_lexicon(first_call_error):
100102
patch.object(wn, "download", return_value=download_path) as mock_download,
101103
patch.object(pathlib.Path, "rmdir"),
102104
):
103-
probe = garak.probes.topic.WordnetBlockedWords()
105+
probe = garak._plugins.load_plugin("probes.topic.WordnetBlockedWords")
104106

105107
assert (
106108
mock_download.call_count == 1

0 commit comments

Comments
 (0)