forked from NVIDIA/garak
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Jeffrey Martin <[email protected]>
- Loading branch information
1 parent
4e5cec4
commit f5fd86c
Showing
5 changed files
with
97 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import os | ||
import pytest | ||
import tempfile | ||
import garak.generators.ggml | ||
|
||
DEFAULT_GENERATIONS_QTY = 10 | ||
|
||
stored_env = os.getenv(garak.generators.ggml.ENV_VAR) | ||
model_name = None | ||
|
||
|
||
@pytest.fixture(autouse=True) | ||
def reset_env(request) -> None: | ||
if stored_env is not None: | ||
os.environ[garak.generators.ggml.ENV_VAR] = stored_env | ||
model_name = tempfile.NamedTemporaryFile(suffix="_test_model.gguf") | ||
|
||
|
||
@pytest.fixture(autouse=True) | ||
def set_fake_env() -> None: | ||
os.environ[garak.generators.ggml.ENV_VAR] = os.path.abspath(__file__) | ||
|
||
|
||
def test_init_bad_app(): | ||
with pytest.raises(RuntimeError) as exc_info: | ||
if os.getenv(garak.generators.ggml.ENV_VAR) is not None: | ||
del os.environ[garak.generators.ggml.ENV_VAR] | ||
garak.generators.ggml.GgmlGenerator(model_name) | ||
assert "not provided by environment" in str(exc_info.value) | ||
|
||
|
||
def test_init_missing_model(): | ||
model_name = tempfile.TemporaryFile().name | ||
with pytest.raises(FileNotFoundError) as exc_info: | ||
garak.generators.ggml.GgmlGenerator(model_name) | ||
assert "File not found" in str(exc_info.value) | ||
|
||
|
||
def test_init_bad_model(): | ||
with tempfile.NamedTemporaryFile(mode="w", suffix="_test_model.gguf") as file: | ||
file.write(file.name) | ||
file.seek(0) | ||
with pytest.raises(RuntimeError) as exc_info: | ||
garak.generators.ggml.GgmlGenerator(file.name) | ||
assert "not in GGUF" in str(exc_info.value) | ||
|
||
|
||
def test_init_good_model(): | ||
with tempfile.NamedTemporaryFile(suffix="_test_model.gguf") as file: | ||
file.write(garak.generators.ggml.GGUF_MAGIC) | ||
file.seek(0) | ||
g = garak.generators.ggml.GgmlGenerator(file.name) | ||
assert g is not None | ||
|
||
|
||
# def test_subprocess_first_err(): | ||
# with open(model_name, "wb") as file: | ||
# file.write(garak.generators.ggml.GGUF_MAGIC) | ||
# g = garak.generators.ggml.GgmlGenerator(model_name) | ||
# with pytest.raises(subprocess.CalledProcessError) as exc_info: | ||
# result = g.generate("mock prompt") | ||
# assert exc_info is not None | ||
|
||
|
||
# def test_subprocess_continue_err(): | ||
# with open(model_name, "wb") as file: | ||
# file.write(garak.generators.ggml.GGUF_MAGIC) | ||
# g = garak.generators.ggml.GgmlGenerator(model_name) | ||
# g.generate("mock prompt") | ||
# with pytest.raises(subprocess.CalledProcessError) as exc_info: | ||
# result = g.generate("mock prompt") | ||
# assert exc_info is not None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters