Skip to content

Commit 57868d2

Browse files
Add additional assertions to live tests for new tools
- Now evaluates: - File names - MIME types - File sizes - Warnings in response - Input ID Assisted-by: Codex
1 parent d875637 commit 57868d2

13 files changed

Lines changed: 85 additions & 7 deletions

tests/live/test_live_convert_to_excel.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ def test_live_convert_to_excel_success(
5050
output_file.type
5151
== "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
5252
)
53+
assert output_file.size > 0
54+
assert response.warning is None
5355
assert str(response.input_id) == str(uploaded_pdf_for_excel.id)
5456
if output_name is not None:
5557
assert output_file.name.startswith(output_name)
@@ -76,6 +78,8 @@ async def test_live_async_convert_to_excel_success(
7678
output_file.type
7779
== "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
7880
)
81+
assert output_file.size > 0
82+
assert response.warning is None
7983
assert str(response.input_id) == str(uploaded_pdf_for_excel.id)
8084

8185

tests/live/test_live_convert_to_markdown.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ def test_live_convert_to_markdown_success(
2222

2323
assert isinstance(response, PdfRestFileBasedResponse)
2424
assert response.output_files
25+
output_file = response.output_file
26+
assert output_file.name.endswith(".md")
27+
assert output_file.type == "text/markdown"
28+
assert output_file.size > 0
29+
assert response.warning is None
2530
assert response.input_id == uploaded.id
2631

2732

@@ -40,7 +45,11 @@ async def test_live_async_convert_to_markdown_success(
4045

4146
assert isinstance(response, PdfRestFileBasedResponse)
4247
assert response.output_files
43-
assert response.output_file.name.startswith("async-md")
48+
output_file = response.output_file
49+
assert output_file.name.startswith("async-md")
50+
assert output_file.type == "text/markdown"
51+
assert output_file.size > 0
52+
assert response.warning is None
4453
assert response.input_id == uploaded.id
4554

4655

tests/live/test_live_convert_to_powerpoint.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ def test_live_convert_to_powerpoint_success(
5050
output_file.type
5151
== "application/vnd.openxmlformats-officedocument.presentationml.presentation"
5252
)
53+
assert output_file.size > 0
54+
assert response.warning is None
5355
assert str(response.input_id) == str(uploaded_pdf_for_powerpoint.id)
5456
if output_name is not None:
5557
assert output_file.name.startswith(output_name)
@@ -78,6 +80,8 @@ async def test_live_async_convert_to_powerpoint_success(
7880
output_file.type
7981
== "application/vnd.openxmlformats-officedocument.presentationml.presentation"
8082
)
83+
assert output_file.size > 0
84+
assert response.warning is None
8185
assert str(response.input_id) == str(uploaded_pdf_for_powerpoint.id)
8286

8387

tests/live/test_live_convert_xfa_to_acroforms.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ def test_live_convert_xfa_to_acroforms_success(
4747
assert response.output_files
4848
output_file = response.output_file
4949
assert output_file.type == "application/pdf"
50+
assert output_file.size > 0
51+
assert response.warning is None
5052
assert str(response.input_id) == str(uploaded_pdf_for_acroforms.id)
5153
if output_name is not None:
5254
assert output_file.name.startswith(output_name)
@@ -90,6 +92,8 @@ async def test_live_async_convert_xfa_to_acroforms_success(
9092
output_file = response.output_file
9193
assert output_file.name.startswith("async")
9294
assert output_file.type == "application/pdf"
95+
assert output_file.size > 0
96+
assert response.warning is None
9397
assert str(response.input_id) == str(uploaded_pdf_for_acroforms.id)
9498

9599

tests/live/test_live_extract_images.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,15 @@ def test_live_extract_images_success(
2121
response = client.extract_images(uploaded)
2222

2323
assert isinstance(response, PdfRestFileBasedResponse)
24-
assert response.output_files
24+
output_files = response.output_files
25+
assert output_files
26+
assert all(file.name for file in output_files)
27+
assert all(
28+
file.type and (file.type.startswith("image/") or file.type == "application/zip")
29+
for file in output_files
30+
)
31+
assert all(file.size > 0 for file in output_files)
32+
assert response.warning is None
2533
assert response.input_id == uploaded.id
2634

2735

@@ -39,8 +47,16 @@ async def test_live_async_extract_images_success(
3947
response = await client.extract_images(uploaded, output="async-images")
4048

4149
assert isinstance(response, PdfRestFileBasedResponse)
42-
assert response.output_files
43-
assert response.output_file.name.startswith("async-images")
50+
output_files = response.output_files
51+
assert output_files
52+
assert output_files[0].name.startswith("async-images")
53+
assert all(file.name for file in output_files)
54+
assert all(
55+
file.type and (file.type.startswith("image/") or file.type == "application/zip")
56+
for file in output_files
57+
)
58+
assert all(file.size > 0 for file in output_files)
59+
assert response.warning is None
4460
assert response.input_id == uploaded.id
4561

4662

tests/live/test_live_extract_pdf_text_to_file.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ def test_live_extract_pdf_text_to_file_success(
2828

2929
assert isinstance(response, PdfRestFileBasedResponse)
3030
assert response.output_files
31+
output_file = response.output_file
32+
assert output_file.name.endswith(".txt")
33+
assert output_file.type == "text/plain"
34+
assert output_file.size > 0
35+
assert response.warning is None
3136
assert response.input_id == uploaded.id
3237

3338

@@ -53,7 +58,11 @@ async def test_live_async_extract_pdf_text_to_file_success(
5358

5459
assert isinstance(response, PdfRestFileBasedResponse)
5560
assert response.output_files
56-
assert response.output_file.name.startswith("async-text")
61+
output_file = response.output_file
62+
assert output_file.name.startswith("async-text")
63+
assert output_file.type == "text/plain"
64+
assert output_file.size > 0
65+
assert response.warning is None
5766
assert response.input_id == uploaded.id
5867

5968

tests/live/test_live_flatten_annotations.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ def test_live_flatten_annotations_success(
4747
assert response.output_files
4848
output_file = response.output_file
4949
assert output_file.type == "application/pdf"
50+
assert output_file.size > 0
51+
assert response.warning is None
5052
assert str(response.input_id) == str(uploaded_pdf_for_annotations.id)
5153
if output_name is not None:
5254
assert output_file.name.startswith(output_name)
@@ -72,6 +74,8 @@ async def test_live_async_flatten_annotations_success(
7274
output_file = response.output_file
7375
assert output_file.name.startswith("async")
7476
assert output_file.type == "application/pdf"
77+
assert output_file.size > 0
78+
assert response.warning is None
7579
assert str(response.input_id) == str(uploaded_pdf_for_annotations.id)
7680

7781

tests/live/test_live_flatten_transparencies.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ def test_live_flatten_transparencies_success(
5050
assert response.output_files
5151
output_file = response.output_file
5252
assert output_file.type == "application/pdf"
53+
assert output_file.size > 0
54+
assert response.warning is None
5355
assert str(response.input_id) == str(uploaded_pdf_for_transparencies.id)
5456
if output_name is not None:
5557
assert output_file.name.startswith(output_name)
@@ -75,6 +77,8 @@ async def test_live_async_flatten_transparencies_success(
7577
output_file = response.output_file
7678
assert output_file.name.startswith("async")
7779
assert output_file.type == "application/pdf"
80+
assert output_file.size > 0
81+
assert response.warning is None
7882
assert str(response.input_id) == str(uploaded_pdf_for_transparencies.id)
7983

8084

tests/live/test_live_linearize_pdf.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ def test_live_linearize_pdf(
4747
assert response.output_files
4848
output_file = response.output_file
4949
assert output_file.type == "application/pdf"
50+
assert output_file.size > 0
51+
assert response.warning is None
5052
assert str(response.input_id) == str(uploaded_pdf_for_linearize.id)
5153
if output_name is not None:
5254
assert output_file.name.startswith(output_name)
@@ -73,6 +75,8 @@ async def test_live_async_linearize_pdf(
7375
output_file = response.output_file
7476
assert output_file.name.startswith("async-linearized")
7577
assert output_file.type == "application/pdf"
78+
assert output_file.size > 0
79+
assert response.warning is None
7680
assert str(response.input_id) == str(uploaded_pdf_for_linearize.id)
7781

7882

tests/live/test_live_ocr_pdf.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@ def test_live_ocr_pdf_success(
2222

2323
assert isinstance(response, PdfRestFileBasedResponse)
2424
assert response.output_files
25-
assert response.output_file.id
25+
output_file = response.output_file
26+
assert output_file.name.endswith(".pdf")
27+
assert output_file.type == "application/pdf"
28+
assert output_file.size > 0
29+
assert response.warning is None
2630
assert response.input_id == uploaded.id
2731

2832

@@ -42,6 +46,9 @@ async def test_live_async_ocr_pdf_success(
4246
assert isinstance(response, PdfRestFileBasedResponse)
4347
assert response.output_files
4448
assert response.output_file.name.startswith("async-ocr")
49+
assert response.output_file.type == "application/pdf"
50+
assert response.output_file.size > 0
51+
assert response.warning is None
4552
assert response.input_id == uploaded.id
4653

4754

0 commit comments

Comments
 (0)