Skip to content

Commit d2b611c

Browse files
removed lint and comment issues
1 parent ac61a12 commit d2b611c

File tree

10 files changed

+479
-68
lines changed

10 files changed

+479
-68
lines changed

content-gen/src/tests/agents/test_image_content_agent.py

Lines changed: 24 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,38 +3,42 @@
33

44
import pytest
55

6+
from agents.image_content_agent import (_generate_gpt_image,
7+
_truncate_for_image,
8+
generate_dalle_image, generate_image)
9+
10+
611
def test_truncate_short_description_unchanged():
712
"""Test that short descriptions are returned unchanged."""
8-
from agents.image_content_agent import _truncate_for_image
913

1014
short_desc = "A beautiful blue paint with hex code #0066CC"
1115
result = _truncate_for_image(short_desc, max_chars=1500)
1216

1317
assert result == short_desc
1418

19+
1520
def test_truncate_empty_description():
1621
"""Test handling of empty description."""
17-
from agents.image_content_agent import _truncate_for_image
1822

1923
result = _truncate_for_image("", max_chars=1500)
2024
assert result == ""
2125

2226
result = _truncate_for_image(None, max_chars=1500)
2327
assert result is None
2428

29+
2530
def test_truncate_long_description_truncated():
2631
"""Test that very long descriptions are truncated."""
27-
from agents.image_content_agent import _truncate_for_image
2832

2933
long_desc = "This is a test description. " * 200 # ~5600 chars
3034
result = _truncate_for_image(long_desc, max_chars=1500)
3135

3236
assert len(result) <= 1500
3337
assert "[Additional details truncated for image generation]" in result or len(result) <= 1500
3438

39+
3540
def test_truncate_preserves_hex_codes():
3641
"""Test that hex color codes are preserved in truncation."""
37-
from agents.image_content_agent import _truncate_for_image
3842

3943
desc_with_hex = """### Product A
4044
This is a nice paint color.
@@ -49,9 +53,9 @@ def test_truncate_preserves_hex_codes():
4953

5054
assert "### Product A" in result or "#FF5733" in result or len(result) <= 500
5155

56+
5257
def test_truncate_preserves_product_headers():
5358
"""Test that product headers (### ...) are preserved."""
54-
from agents.image_content_agent import _truncate_for_image
5559

5660
desc = """### Snow Veil White
5761
A pure white paint for interiors.
@@ -66,9 +70,9 @@ def test_truncate_preserves_product_headers():
6670

6771
assert len(result) <= 300
6872

73+
6974
def test_truncate_preserves_finish_descriptions():
7075
"""Test that finish descriptions (matte, eggshell) are considered."""
71-
from agents.image_content_agent import _truncate_for_image
7276

7377
desc = """### Product
7478
Color description here.
@@ -80,6 +84,7 @@ def test_truncate_preserves_finish_descriptions():
8084

8185
assert len(result) <= 400
8286

87+
8388
@pytest.mark.asyncio
8489
async def test_generate_dalle_image_success():
8590
"""Test successful DALL-E image generation."""
@@ -115,8 +120,6 @@ async def test_generate_dalle_image_success():
115120
mock_openai.close = AsyncMock()
116121
mock_client.return_value = mock_openai
117122

118-
from agents.image_content_agent import generate_dalle_image
119-
120123
result = await generate_dalle_image(
121124
prompt="Create a marketing image for paint",
122125
product_description="Blue paint with hex #0066CC",
@@ -127,6 +130,7 @@ async def test_generate_dalle_image_success():
127130
assert "image_base64" in result
128131
assert result["model"] == "dall-e-3"
129132

133+
130134
@pytest.mark.asyncio
131135
async def test_generate_dalle_image_with_managed_identity():
132136
"""Test DALL-E generation with managed identity credential."""
@@ -161,13 +165,12 @@ async def test_generate_dalle_image_with_managed_identity():
161165
mock_openai.close = AsyncMock()
162166
mock_client.return_value = mock_openai
163167

164-
from agents.image_content_agent import generate_dalle_image
165-
166168
result = await generate_dalle_image(prompt="Test prompt")
167169

168170
assert result["success"] is True
169171
mock_cred.assert_called_once_with(client_id="test-client-id")
170172

173+
171174
@pytest.mark.asyncio
172175
async def test_generate_dalle_image_error_handling():
173176
"""Test DALL-E generation error handling."""
@@ -188,14 +191,13 @@ async def test_generate_dalle_image_error_handling():
188191

189192
mock_cred.side_effect = Exception("Authentication failed")
190193

191-
from agents.image_content_agent import generate_dalle_image
192-
193194
result = await generate_dalle_image(prompt="Test prompt")
194195

195196
assert result["success"] is False
196197
assert "error" in result
197198
assert "Authentication failed" in result["error"]
198199

200+
199201
@pytest.mark.asyncio
200202
async def test_generate_gpt_image_success():
201203
"""Test successful gpt-image-1 generation."""
@@ -230,8 +232,6 @@ async def test_generate_gpt_image_success():
230232
mock_openai.close = AsyncMock()
231233
mock_client.return_value = mock_openai
232234

233-
from agents.image_content_agent import _generate_gpt_image
234-
235235
result = await _generate_gpt_image(
236236
prompt="Create a marketing image",
237237
product_description="Paint product",
@@ -242,6 +242,7 @@ async def test_generate_gpt_image_success():
242242
assert "image_base64" in result
243243
assert result["model"] == "gpt-image-1"
244244

245+
245246
@pytest.mark.asyncio
246247
async def test_generate_gpt_image_quality_passthrough():
247248
"""Test that gpt-image passes quality setting through unchanged."""
@@ -276,13 +277,12 @@ async def test_generate_gpt_image_quality_passthrough():
276277
mock_openai.close = AsyncMock()
277278
mock_client.return_value = mock_openai
278279

279-
from agents.image_content_agent import _generate_gpt_image
280-
281280
_ = await _generate_gpt_image(prompt="Test")
282281

283282
call_kwargs = mock_openai.images.generate.call_args.kwargs
284283
assert call_kwargs["quality"] == "medium"
285284

285+
286286
@pytest.mark.asyncio
287287
async def test_generate_gpt_image_no_b64_falls_back_to_url():
288288
"""Test fallback to URL fetch when b64_json is not available."""
@@ -330,12 +330,11 @@ async def test_generate_gpt_image_no_b64_falls_back_to_url():
330330
mock_resp.__aexit__ = AsyncMock()
331331
mock_session.return_value = mock_session_instance
332332

333-
from agents.image_content_agent import _generate_gpt_image
334-
335333
result = await _generate_gpt_image(prompt="Test")
336334

337335
assert result["success"] is True
338336

337+
339338
@pytest.mark.asyncio
340339
async def test_generate_gpt_image_error_handling():
341340
"""Test gpt-image error handling."""
@@ -356,13 +355,12 @@ async def test_generate_gpt_image_error_handling():
356355

357356
mock_cred.side_effect = Exception("Auth error")
358357

359-
from agents.image_content_agent import _generate_gpt_image
360-
361358
result = await _generate_gpt_image(prompt="Test")
362359

363360
assert result["success"] is False
364361
assert "error" in result
365362

363+
366364
@pytest.mark.asyncio
367365
async def test_routes_to_dalle_for_dalle_model():
368366
"""Test that dall-e-3 model routes to DALL-E generator."""
@@ -374,14 +372,13 @@ async def test_routes_to_dalle_for_dalle_model():
374372
mock_dalle.return_value = {"success": True, "model": "dall-e-3"}
375373
mock_gpt.return_value = {"success": True, "model": "gpt-image-1"}
376374

377-
from agents.image_content_agent import generate_dalle_image
378-
379375
result = await generate_dalle_image(prompt="Test")
380376

381377
mock_dalle.assert_called_once()
382378
mock_gpt.assert_not_called()
383379
assert result["model"] == "dall-e-3"
384380

381+
385382
@pytest.mark.asyncio
386383
async def test_routes_to_gpt_image_for_gpt_model():
387384
"""Test that gpt-image-1 model routes to gpt-image generator."""
@@ -393,14 +390,13 @@ async def test_routes_to_gpt_image_for_gpt_model():
393390
mock_dalle.return_value = {"success": True, "model": "dall-e-3"}
394391
mock_gpt.return_value = {"success": True, "model": "gpt-image-1"}
395392

396-
from agents.image_content_agent import generate_dalle_image
397-
398393
result = await generate_dalle_image(prompt="Test")
399394

400395
mock_gpt.assert_called_once()
401396
mock_dalle.assert_not_called()
402397
assert result["model"] == "gpt-image-1"
403398

399+
404400
@pytest.mark.asyncio
405401
async def test_routes_to_gpt_image_for_gpt_image_1_5():
406402
"""Test that gpt-image-1.5 model routes to gpt-image generator."""
@@ -412,16 +408,14 @@ async def test_routes_to_gpt_image_for_gpt_image_1_5():
412408
mock_dalle.return_value = {"success": True, "model": "dall-e-3"}
413409
mock_gpt.return_value = {"success": True, "model": "gpt-image-1.5"}
414410

415-
from agents.image_content_agent import generate_dalle_image
416-
417411
_ = await generate_dalle_image(prompt="Test")
418412

419413
mock_gpt.assert_called_once()
420414
mock_dalle.assert_not_called()
421415

416+
422417
def test_truncate_preserves_hex_in_middle_of_line():
423418
"""Test hex code in middle of line is preserved."""
424-
from agents.image_content_agent import _truncate_for_image
425419

426420
# Text with #hex in the middle of lines
427421
desc = """### Product Name
@@ -433,9 +427,9 @@ def test_truncate_preserves_hex_in_middle_of_line():
433427
# Should contain some hex reference
434428
assert len(result) <= 400
435429

430+
436431
def test_truncate_preserves_description_quotes():
437432
"""Test quoted descriptions with 'appears as' are preserved."""
438-
from agents.image_content_agent import _truncate_for_image
439433

440434
desc = '''### Product
441435
"This color appears as a soft blue tone. It has variations in the light."
@@ -445,9 +439,9 @@ def test_truncate_preserves_description_quotes():
445439
result = _truncate_for_image(desc, max_chars=500)
446440
assert len(result) <= 500
447441

442+
448443
def test_truncate_with_eggshell_finish():
449444
"""Test that eggshell finish descriptions are considered."""
450-
from agents.image_content_agent import _truncate_for_image
451445

452446
desc = """### Product
453447
Basic description.
@@ -458,6 +452,7 @@ def test_truncate_with_eggshell_finish():
458452
result = _truncate_for_image(desc, max_chars=400)
459453
assert len(result) <= 400
460454

455+
461456
@pytest.mark.asyncio
462457
async def test_generate_image_truncates_very_long_prompt():
463458
"""Test that _generate_dalle_image truncates very long product descriptions.
@@ -500,8 +495,6 @@ async def test_generate_image_truncates_very_long_prompt():
500495
mock_openai.close = AsyncMock()
501496
mock_client.return_value = mock_openai
502497

503-
from agents.image_content_agent import generate_image
504-
505498
# Create very long product description (~10000 chars)
506499
very_long_product_desc = "Product description with details. " * 300
507500

0 commit comments

Comments
 (0)