Skip to content

Commit 47fbdd6

Browse files
tpellissierclaude
andcommitted
Use .txt instead of .pdf for generated test files in upload example
The test file generator no longer produces PDF content, so naming them .txt avoids confusion. Replaces fake PDF structure with plain repeating text lines. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent d3a9b37 commit 47fbdd6

1 file changed

Lines changed: 10 additions & 20 deletions

File tree

examples/advanced/file_upload.py

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -90,32 +90,22 @@ def file_sha256(path: Path): # returns (hex_digest, size_bytes)
9090

9191

9292
def generate_test_file(size_mb: int = 10) -> Path:
93-
"""Generate a dummy file of specified size for testing purposes.
93+
"""Generate a dummy text file of specified size for testing purposes.
9494
95-
Creates a minimal PDF-like file with random padding to reach the target
95+
Creates a plain text file with repeating content to reach the target
9696
size. No external dependencies required.
9797
"""
98-
test_file = Path(__file__).resolve().parent / f"test_dummy_{size_mb}mb.pdf"
98+
test_file = Path(__file__).resolve().parent / f"test_dummy_{size_mb}mb.txt"
9999
target_size = size_mb * 1024 * 1024
100100

101-
# Minimal PDF structure so the file is recognized as PDF
102-
pdf_header = b"%PDF-1.4\n"
103-
pdf_body = b"1 0 obj\n<< /Type /Catalog /Pages 2 0 R >>\nendobj\n"
104-
pdf_body += b"2 0 obj\n<< /Type /Pages /Kids [3 0 R] /Count 1 >>\nendobj\n"
105-
pdf_body += b"3 0 obj\n<< /Type /Page /Parent 2 0 R /MediaBox [0 0 612 792] >>\nendobj\n"
106-
107-
# Fill with dummy data to reach target size
108-
current_size = len(pdf_header) + len(pdf_body)
109-
padding_needed = target_size - current_size - 50 # Reserve space for trailer
110-
padding = b"% " + (b"padding " * (padding_needed // 8))[:padding_needed] + b"\n"
111-
112-
pdf_trailer = b"xref\n0 4\ntrailer\n<< /Size 4 /Root 1 0 R >>\nstartxref\n0\n%%EOF\n"
113-
101+
line = b"The quick brown fox jumps over the lazy dog. " * 2 + b"\n"
114102
with test_file.open("wb") as f:
115-
f.write(pdf_header)
116-
f.write(pdf_body)
117-
f.write(padding)
118-
f.write(pdf_trailer)
103+
written = 0
104+
while written < target_size:
105+
chunk = line * min(1000, (target_size - written) // len(line) + 1)
106+
chunk = chunk[: target_size - written]
107+
f.write(chunk)
108+
written += len(chunk)
119109

120110
print({"test_file_generated": str(test_file), "size_mb": test_file.stat().st_size / (1024 * 1024)})
121111
return test_file

0 commit comments

Comments
 (0)