Skip to content
Merged
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
2 changes: 1 addition & 1 deletion pyrit/prompt_converter/translation_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def __init__(
prompt_template: Optional[SeedPrompt] = None,
max_retries: int = 3,
max_wait_time_in_seconds: int = 60,
):
) -> None:
"""
Initialize the converter with the target chat support, language, and optional prompt template.

Expand Down
4 changes: 2 additions & 2 deletions pyrit/prompt_target/azure_blob_storage_target.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ def __init__(
env_var_name=self.AZURE_STORAGE_CONTAINER_ENVIRONMENT_VARIABLE, passed_value=container_url
)

self._sas_token = sas_token
self._client_async: AsyncContainerClient = None
self._sas_token: Optional[str] = sas_token
self._client_async: Optional[AsyncContainerClient] = None

super().__init__(endpoint=self._container_url, max_requests_per_minute=max_requests_per_minute)

Expand Down
10 changes: 5 additions & 5 deletions tests/unit/scenarios/test_leakage_scenario.py
Original file line number Diff line number Diff line change
Expand Up @@ -536,9 +536,9 @@ def test_ensure_blank_image_exists_creates_image(self, mock_objective_scorer, sa
# Verify it's a valid image with correct dimensions
from PIL import Image

img = Image.open(test_image_path)
assert img.size == (800, 600)
assert img.mode == "RGB"
with Image.open(test_image_path) as img:
assert img.size == (800, 600)
assert img.mode == "RGB"

def test_ensure_blank_image_exists_does_not_overwrite(self, mock_objective_scorer, sample_objectives, tmp_path):
"""Test that _ensure_blank_image_exists doesn't overwrite existing image."""
Expand All @@ -564,8 +564,8 @@ def test_ensure_blank_image_exists_does_not_overwrite(self, mock_objective_score
assert Path(test_image_path).stat().st_mtime == original_mtime

# Verify it's still the original image
img = Image.open(test_image_path)
assert img.size == (100, 100) # Original size, not 800x600
with Image.open(test_image_path) as img:
assert img.size == (100, 100) # Original size, not 800x600

def test_ensure_blank_image_exists_creates_parent_directories(
self, mock_objective_scorer, sample_objectives, tmp_path
Expand Down
3 changes: 2 additions & 1 deletion tests/unit/target/test_tts_target.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import os
import uuid
from collections.abc import MutableSequence
from pathlib import Path
from unittest.mock import AsyncMock, MagicMock, patch

import pytest
Expand Down Expand Up @@ -121,7 +122,7 @@ async def test_tts_send_prompt_file_save_async(
assert file_path
assert file_path.endswith(f".{response_format}")
assert os.path.exists(file_path)
data = open(file_path, "rb").read() # noqa: SIM115
data = Path(file_path).read_bytes()
assert data == b"audio data"
os.remove(file_path)

Expand Down
8 changes: 4 additions & 4 deletions tests/unit/target/test_websocket_copilot_target.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
@pytest.fixture
def mock_authenticator():
token_payload = {"tid": "test_tenant_id", "oid": "test_object_id", "exp": 9999999999}
mock_token = jwt.encode(token_payload, "secret", algorithm="HS256")
mock_token = jwt.encode(token_payload, "a]T3!s$ecReT#kEy_4_tEst!ng@2024+", algorithm="HS256")
if isinstance(mock_token, bytes):
mock_token = mock_token.decode("utf-8")
authenticator = MagicMock(spec=CopilotAuthenticator)
Expand Down Expand Up @@ -267,7 +267,7 @@ async def test_build_websocket_url_with_missing_ids(self, mock_authenticator, mo
token_payload = {"tid": "test_tenant_id", "oid": "test_object_id", "exp": 9999999999}
del token_payload[missing_id]

mock_token = jwt.encode(token_payload, "secret", algorithm="HS256")
mock_token = jwt.encode(token_payload, "a]T3!s$ecReT#kEy_4_tEst!ng@2024+", algorithm="HS256")
if isinstance(mock_token, bytes):
mock_token = mock_token.decode("utf-8")
mock_authenticator.get_token = AsyncMock(return_value=mock_token)
Expand Down Expand Up @@ -848,7 +848,7 @@ async def test_send_prompt_async_successful(self, mock_authenticator, make_messa

assert len(responses) == 1
assert responses[0].message_pieces[0].converted_value == "Response from Copilot"
assert responses[0].message_pieces[0].role == "assistant"
assert responses[0].message_pieces[0].api_role == "assistant"

@pytest.mark.asyncio
async def test_send_prompt_async_with_exceptions(self, mock_authenticator, make_message_piece, mock_memory):
Expand Down Expand Up @@ -884,7 +884,7 @@ async def test_send_prompt_async_with_image(self, mock_authenticator, make_messa

assert len(responses) == 1
assert responses[0].message_pieces[0].converted_value == "Image description response"
assert responses[0].message_pieces[0].role == "assistant"
assert responses[0].message_pieces[0].api_role == "assistant"

@pytest.mark.asyncio
async def test_send_prompt_async_with_mixed_content(self, mock_authenticator, make_message_piece, mock_memory):
Expand Down
Loading