Skip to content
Open
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ docs-build:
jb build -W -v ./doc

unit-test:
$(CMD) pytest --cov=$(PYMODULE) $(UNIT_TESTS)
$(CMD) pytest -n auto --cov=$(PYMODULE) $(UNIT_TESTS)

unit-test-cov-html:
$(CMD) pytest --cov=$(PYMODULE) $(UNIT_TESTS) --cov-report html
$(CMD) pytest -n auto --cov=$(PYMODULE) $(UNIT_TESTS) --cov-report html

unit-test-cov-xml:
$(CMD) pytest --cov=$(PYMODULE) $(UNIT_TESTS) --cov-report xml --junitxml=junit/test-results.xml --doctest-modules
$(CMD) pytest -n auto --cov=$(PYMODULE) $(UNIT_TESTS) --cov-report xml --junitxml=junit/test-results.xml --doctest-modules

integration-test:
$(CMD) pytest $(INTEGRATION_TESTS) --cov=$(PYMODULE) $(INTEGRATION_TESTS) --cov-report xml --junitxml=junit/test-results.xml --doctest-modules
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ dev = [
"pytest-asyncio>=0.23.5",
"pytest-cov>=4.0.0",
"pytest-timeout>=2.3.1",
"pytest-xdist>=3.6.1",
"respx>=0.22.0",
"semantic-kernel>=1.20.0",
"sphinxcontrib-mermaid>=1.0.0",
Expand Down
13 changes: 9 additions & 4 deletions tests/unit/converter/test_azure_speech_text_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,15 @@ def is_speechsdk_installed():
@pytest.mark.skipif(not is_speechsdk_installed(), reason="Azure Speech SDK is not installed.")
class TestAzureSpeechAudioToTextConverter:

@patch(
"pyrit.common.default_values.get_required_value", side_effect=lambda env_var_name, passed_value: passed_value
)
def test_azure_speech_audio_text_converter_initialization(self, mock_get_required_value):
@pytest.fixture(autouse=True)
def setup_environment(self):
with patch(
"pyrit.common.default_values.get_required_value",
side_effect=lambda env_var_name, passed_value: passed_value or "dummy_value",
):
yield

def test_azure_speech_audio_text_converter_initialization(self):
converter = AzureSpeechAudioToTextConverter(
azure_speech_region="dummy_region", azure_speech_key="dummy_key", recognition_language="es-ES"
)
Expand Down
20 changes: 15 additions & 5 deletions tests/unit/converter/test_pdf_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,23 @@
from fpdf import FPDF
from fpdf.enums import XPos, YPos
from pypdf import PageObject, PdfReader
from unit.mocks import MockPromptTarget

from pyrit.memory.central_memory import CentralMemory
from pyrit.memory.duckdb_memory import DuckDBMemory
from pyrit.models import DataTypeSerializer, SeedPrompt
from pyrit.prompt_converter import ConverterResult, PDFConverter


@pytest.fixture
def setup_memory():
memory = DuckDBMemory(db_path=":memory:")
CentralMemory.set_memory_instance(memory)
mock_target = MockPromptTarget()
yield mock_target
CentralMemory.set_memory_instance(None)


@pytest.fixture
def pdf_converter_no_template():
"""A PDFConverter with no template path provided."""
Expand Down Expand Up @@ -60,7 +72,6 @@ async def test_convert_async_no_template(pdf_converter_no_template):
patch.object(pdf_converter_no_template, "_generate_pdf", return_value=mock_pdf_bytes) as mock_generate,
patch.object(pdf_converter_no_template, "_serialize_pdf") as mock_serialize,
):

serializer_mock = MagicMock()
serializer_mock.value = "mock_url"
mock_serialize.return_value = serializer_mock
Expand Down Expand Up @@ -92,7 +103,6 @@ async def test_convert_async_with_template(pdf_converter_with_template):
patch.object(pdf_converter_with_template, "_generate_pdf", return_value=mock_pdf_bytes) as mock_generate,
patch.object(pdf_converter_with_template, "_serialize_pdf") as mock_serialize,
):

serializer_mock = MagicMock()
serializer_mock.value = "mock_url"
mock_serialize.return_value = serializer_mock
Expand Down Expand Up @@ -370,7 +380,7 @@ async def test_empty_injection_items(mock_pdf_path):


@pytest.mark.asyncio
async def test_injection_items_non_existent_page_number(mock_pdf_path):
async def test_injection_items_non_existent_page_number(mock_pdf_path, setup_memory):
"""
Test the PDFConverter's handling of injection items with a non-existent page number.
"""
Expand Down Expand Up @@ -405,7 +415,7 @@ async def test_injection_items_non_existent_page_number(mock_pdf_path):


@pytest.mark.asyncio
async def test_non_standard_font_usage():
async def test_non_standard_font_usage(setup_memory):
"""
Test the ability to use a non-standard font (Times) in PDF generation.
"""
Expand Down Expand Up @@ -434,7 +444,7 @@ async def test_non_standard_font_usage():


@pytest.mark.asyncio
async def test_injection_on_last_page(mock_pdf_path):
async def test_injection_on_last_page(mock_pdf_path, setup_memory):
"""
Test injecting text on the last page of a multi-page PDF
"""
Expand Down
Loading