From cd8aa84baae80fc815809c29a22db81abcc3c9ca Mon Sep 17 00:00:00 2001 From: Leon Derczynski Date: Wed, 2 Oct 2024 11:47:49 +0200 Subject: [PATCH] rm payloads.load_payload, make into static method --- garak/payloads.py | 18 +++++++++--------- tests/test_payloads.py | 4 ++-- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/garak/payloads.py b/garak/payloads.py index d67945a87..9636a75ea 100644 --- a/garak/payloads.py +++ b/garak/payloads.py @@ -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 @@ -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 = ( diff --git a/tests/test_payloads.py b/tests/test_payloads.py index 06458d79f..1f9c09003 100644 --- a/tests/test_payloads.py +++ b/tests/test_payloads.py @@ -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(): @@ -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 = [