Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Sweep Rules] Add Unit Tests for pulling_ace/utils/subprocessor.py #43

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions test/test_subprocessor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import unittest
from unittest.mock import patch, call
from pulling_ace.utils import subprocessor

class SubprocessorTest(unittest.TestCase):
@patch('subprocessor.subprocess.run')
def test_toxicity(self, mock_run):
subprocessor.toxicity('huggingface', 'gpt2', 'RTPBlank')
mock_run.assert_called_once_with(
['python3', '-m', 'garak', '--model_type', 'huggingface', '--model_name', 'gpt2', '--probes', 'realtoxicityprompts.RTPBlank'],
check=True, capture_output=True, text=True
)

@patch('subprocessor.subprocess.run')
def test_promptinjection(self, mock_run):
subprocessor.promptinjection('huggingface', 'gpt2', 'HijackHateHumans')
mock_run.assert_called_once_with(
['python3', '-m', 'garak', '--model_type', 'huggingface', '--model_name', 'gpt2', '--probes', 'promptinject.HijackHateHumans'],
check=True, capture_output=True, text=True
)

@patch('subprocessor.subprocess.run')
def test_riskcards(self, mock_run):
subprocessor.riskcards('huggingface', 'gpt2', 'Bullying')
mock_run.assert_called_once_with(
['python3', '-m', 'garak', '--model_type', 'huggingface', '--model_name', 'gpt2', '--probes', 'lmrc.Bullying'],
check=True, capture_output=True, text=True
)

@patch('subprocessor.riskcards')
def test_riskcard_wrapper(self, mock_riskcards):
subprocessor.riskcard_wrapper({'model_type': 'huggingface', 'model_name': 'gpt2', 'probe': 'Bullying'})
mock_riskcards.assert_called_once_with('huggingface', 'gpt2', 'Bullying')

@patch('subprocessor.promptinjection')
def test_promptinjection_wrapper(self, mock_promptinjection):
subprocessor.promptinjection_wrapper({'model_type': 'huggingface', 'model_name': 'gpt2', 'probe': 'HijackHateHumans'})
mock_promptinjection.assert_called_once_with('huggingface', 'gpt2', 'HijackHateHumans')

@patch('subprocessor.toxicity')
def test_toxicity_wrapper(self, mock_toxicity):
subprocessor.toxicity_wrapper({'model_type': 'huggingface', 'model_name': 'gpt2', 'probe': 'RTPBlank'})
mock_toxicity.assert_called_once_with('huggingface', 'gpt2', 'RTPBlank')

@patch('subprocessor.multiprocessing.Pool')
def test_run_injections(self, mock_pool):
subprocessor.run_injections('huggingface', 'gpt2', 'promptinject')
mock_pool.return_value.map.assert_called_once()

if __name__ == '__main__':
unittest.main()
Loading