Skip to content

Commit b23863b

Browse files
committed
fix model path mocking and assertion for windows
1 parent f640d29 commit b23863b

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

tests/test_jailbreak_model_based.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,12 +235,15 @@ def test_initialize_model_with_valid_path(monkeypatch):
235235
"""
236236
Test initialize_model with a valid classifier path.
237237
"""
238+
from pathlib import Path
239+
238240
import nemoguardrails.library.jailbreak_detection.model_based.checks as checks
239241

240242
checks.initialize_model.cache_clear()
241243

242244
# mock environment variable
243-
monkeypatch.setenv("EMBEDDING_CLASSIFIER_PATH", "/fake/path/to/model")
245+
test_path = "/fake/path/to/model"
246+
monkeypatch.setenv("EMBEDDING_CLASSIFIER_PATH", test_path)
244247

245248
# mock JailbreakClassifier
246249
mock_classifier = mock.MagicMock()
@@ -253,9 +256,9 @@ def test_initialize_model_with_valid_path(monkeypatch):
253256
result = checks.initialize_model()
254257

255258
assert result == mock_classifier
256-
mock_jailbreak_classifier_class.assert_called_once_with(
257-
"/fake/path/to/model/snowflake.pkl"
258-
)
259+
260+
expected_path = str(Path(test_path).joinpath("snowflake.pkl"))
261+
mock_jailbreak_classifier_class.assert_called_once_with(expected_path)
259262

260263

261264
# Test 10: Test that NvEmbedE5 class no longer exists

0 commit comments

Comments
 (0)