Skip to content

Commit

Permalink
rm payloads.load_payload, make into static method
Browse files Browse the repository at this point in the history
  • Loading branch information
leondz committed Oct 2, 2024
1 parent 66ca95f commit cd8aa84
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
18 changes: 9 additions & 9 deletions garak/payloads.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,6 @@ def _validate_payload(payload_json):
return True


def load_payload(
name: str, path: Union[str, pathlib.Path, None] = None
) -> PayloadGroup:
if path is None:
path = PAYLOAD_DIR / f"{name}.json"
return PayloadGroup(name, path)


class PayloadGroup:
"""Represents a configured group of payloads for use with garak
probes. Each group should have a name, one or more payload types, and
Expand Down Expand Up @@ -206,11 +198,19 @@ def search(
if any(matches):
yield payload

@staticmethod
def _load_payload(
name: str, path: Union[str, pathlib.Path, None] = None
) -> PayloadGroup:
if path is None:
path = PAYLOAD_DIR / f"{name}.json"
return PayloadGroup(name, path)

def load(self, name) -> PayloadGroup:
"""Return a PayloadGroup"""
try:
path = self.__class__.payload_list[name]["path"]
p = load_payload(name, path) # or raise KeyError
p = self._load_payload(name, path) # or raise KeyError

except KeyError as ke:
msg = (
Expand Down
4 changes: 2 additions & 2 deletions tests/test_payloads.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def test_payloads_have_valid_tags(payload_name, payload_typology):

def test_nonexistent_payload_direct_load():
with pytest.raises(garak.exception.GarakException):
garak.payloads.load_payload("jkasfohgi")
garak.payloads.Director._load_payload("jkasfohgi")


def test_nonexistent_payload_manager_load():
Expand All @@ -78,7 +78,7 @@ def test_non_json_direct_load():
with pytest.raises(
garak.exception.PayloadFailure
): # blank file aint valid json
garak.payloads.load_payload("jkasfohgi", t.name)
garak.payloads.Director._load_payload("jkasfohgi", t.name)


OK_PAYLOADS = [
Expand Down

0 comments on commit cd8aa84

Please sign in to comment.