From 616c798e83052f160e19f52ec94beb409637c95f Mon Sep 17 00:00:00 2001 From: Leon Derczynski Date: Tue, 23 Jul 2024 08:19:58 +0200 Subject: [PATCH] check hitlog file presence --- tests/test_hitlog.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/tests/test_hitlog.py b/tests/test_hitlog.py index f7b2c73e1..e28d688f4 100644 --- a/tests/test_hitlog.py +++ b/tests/test_hitlog.py @@ -1,11 +1,32 @@ # SPDX-FileCopyrightText: Portions Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved. # SPDX-License-Identifier: Apache-2.0 +import contextlib +import os +import pytest + import garak import garak.cli +CODEPATH_PREFIX = "_garak_test_hitlog_codepath" + + def test_hitlog_codepath(): - args = "-m test.Blank -p test.Test -d always.Fail".split() + args = f"-m test.Blank --report_prefix {CODEPATH_PREFIX} -p test.Test -d always.Fail".split() garak.cli.main(args) + assert os.path.isfile(f"{CODEPATH_PREFIX}.hitlog.jsonl") + + +@pytest.fixture(scope="session", autouse=True) +def cleanup(request): + """Cleanup a testing directory once we are finished.""" + + def remove_codepath_reports(): + with contextlib.suppress(FileNotFoundError): + os.remove(f"{CODEPATH_PREFIX}.report.jsonl") + os.remove(f"{CODEPATH_PREFIX}.report.html") + os.remove(f"{CODEPATH_PREFIX}.hitlog.jsonl") + + request.addfinalizer(remove_codepath_reports)