Skip to content

Commit b77b367

Browse files
biefanromanlutz
authored andcommitted
FIX Reject empty WMDP category values (microsoft#1497)
Co-authored-by: Roman Lutz <romanlutz13@gmail.com>
1 parent df1ad7a commit b77b367

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

pyrit/datasets/executors/question_answer/wmdp_dataset.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def fetch_wmdp_dataset(category: Optional[str] = None) -> QuestionAnsweringDatas
3131
"""
3232
# Determine which subset of data to load
3333
data_categories = None
34-
if not category: # if category is not specified, read in all 3 subsets of data
34+
if category is None: # if category is not specified, read in all 3 subsets of data
3535
data_categories = ["wmdp-cyber", "wmdp-bio", "wmdp-chem"]
3636
elif category not in ["cyber", "bio", "chem"]:
3737
raise ValueError(f"Invalid Parameter: {category}. Expected 'cyber', 'bio', or 'chem'")
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Copyright (c) Microsoft Corporation.
2+
# Licensed under the MIT license.
3+
4+
from unittest.mock import patch
5+
6+
import pytest
7+
8+
from pyrit.datasets.executors.question_answer.wmdp_dataset import fetch_wmdp_dataset
9+
10+
11+
class _EmptySplit:
12+
def __len__(self) -> int:
13+
return 0
14+
15+
16+
def test_fetch_wmdp_dataset_rejects_empty_category():
17+
with patch(
18+
"pyrit.datasets.executors.question_answer.wmdp_dataset.load_dataset",
19+
return_value={"test": _EmptySplit()},
20+
) as mock_load_dataset:
21+
with pytest.raises(ValueError, match="Invalid Parameter"):
22+
fetch_wmdp_dataset(category="")
23+
24+
mock_load_dataset.assert_not_called()

0 commit comments

Comments
 (0)