@@ -144,20 +144,26 @@ def require_liteparse_binary() -> str:
144144 return binary_path
145145
146146
147- def _download_test_pdf () -> bytes :
148- """Download a small public PDF for testing. Tries multiple sources."""
149- pdf_urls = [
150- "https://unec.edu.az/application/uploads/2014/12/pdf-sample.pdf" ,
151- "https://www.orimi.com/pdf-test.pdf" ,
152- ]
153- for url in pdf_urls :
154- try :
155- resp = requests .get (url , timeout = 30 )
156- if resp .status_code == 200 and resp .content [:5 ] == b"%PDF-" :
157- return resp .content
158- except Exception :
159- continue
160- pytest .fail ("Could not download any test PDF from the web" )
147+ # Two public PDFs with known, distinct text content:
148+ #
149+ # PDF_URL_A (unec.edu.az/pdf-sample.pdf):
150+ # Contains "Adobe® Portable Document Format (PDF) is a universal file format
151+ # that preserves all of the fonts, formatting, colours and graphics"
152+ #
153+ # PDF_URL_B (pdfobject.com/pdf/sample.pdf):
154+ # Contains "This is a simple PDF file. Fun fun fun."
155+ # and "Lorem ipsum dolor sit amet, consectetuer adipiscing elit."
156+ #
157+ PDF_URL_A = "https://unec.edu.az/application/uploads/2014/12/pdf-sample.pdf"
158+ PDF_URL_B = "https://pdfobject.com/pdf/sample.pdf"
159+
160+
161+ def _download_pdf (url : str ) -> bytes :
162+ """Download a single PDF by URL, fail if unavailable."""
163+ resp = requests .get (url , timeout = 30 )
164+ assert resp .status_code == 200 , f"Failed to download { url } : HTTP { resp .status_code } "
165+ assert resp .content [:5 ] == b"%PDF-" , f"Not a PDF: { url } "
166+ return resp .content
161167
162168
163169def test_hook_scripts_exist ():
@@ -245,12 +251,13 @@ def test_noresults_without_sources():
245251def test_extract_single_pdf ():
246252 """Test extraction on a single real PDF downloaded from the web.
247253
248- Downloads a real PDF, places it as pdf plugin output, runs the
249- liteparse snapshot hook, and asserts the output contains expected
250- text content from the actual PDF document.
254+ Uses PDF_URL_B (pdfobject.com sample) which contains the exact text:
255+ "This is a simple PDF file. Fun fun fun."
256+ "Lorem ipsum dolor sit amet, consectetuer adipiscing elit."
257+ Asserts these specific sentences appear in the extracted output.
251258 """
252259 binary_path = require_liteparse_binary ()
253- pdf_content = _download_test_pdf ( )
260+ pdf_content = _download_pdf ( PDF_URL_B )
254261
255262 with tempfile .TemporaryDirectory () as tmpdir :
256263 tmpdir = Path (tmpdir )
@@ -267,7 +274,7 @@ def test_extract_single_pdf():
267274
268275 result = subprocess .run (
269276 [str (LITEPARSE_HOOK ),
270- "--url" , "https://example.com/test.pdf" ,
277+ "--url" , PDF_URL_B ,
271278 "--snapshot-id" , "test-single-pdf" ,
272279 ],
273280 cwd = tmpdir ,
@@ -288,13 +295,16 @@ def test_extract_single_pdf():
288295 assert (output_dir / "metadata.json" ).exists (), "metadata.json not created"
289296
290297 text_content = (output_dir / "content.txt" ).read_text (errors = "ignore" )
291- assert len (text_content ) > 10 , f"content.txt too short: { text_content !r} "
292-
293- # The test PDFs contain known text - verify real content was extracted
294- # pdf-sample.pdf contains "Adobe Acrobat" or similar known strings
295298 text_lower = text_content .lower ()
296- assert any (word in text_lower for word in ["pdf" , "sample" , "adobe" , "acrobat" , "document" , "page" , "file" , "test" ]), (
297- f"Extracted text does not contain expected PDF content keywords. Got: { text_content [:500 ]!r} "
299+
300+ # Assert specific sentences from the actual PDF page content
301+ assert "this is a simple pdf file" in text_lower , (
302+ f"Expected exact text 'This is a simple PDF file' from { PDF_URL_B } . "
303+ f"Got: { text_content [:500 ]!r} "
304+ )
305+ assert "consectetuer adipiscing elit" in text_lower , (
306+ f"Expected exact text 'consectetuer adipiscing elit' from { PDF_URL_B } . "
307+ f"Got: { text_content [:500 ]!r} "
298308 )
299309
300310 metadata = json .loads ((output_dir / "metadata.json" ).read_text ())
@@ -303,23 +313,32 @@ def test_extract_single_pdf():
303313
304314
305315def test_extract_multiple_pdfs ():
306- """Test that ALL PDFs are processed when multiple exist across plugins."""
316+ """Test that ALL PDFs are processed when multiple exist across plugins.
317+
318+ Uses two different PDFs with distinct content:
319+ PDF_URL_A (unec.edu.az): contains "preserves all of the fonts, formatting, colours and graphics"
320+ PDF_URL_B (pdfobject.com): contains "This is a simple PDF file. Fun fun fun."
321+
322+ Places them in pdf/ and responses/ directories and verifies the combined
323+ output contains unique text from BOTH documents.
324+ """
307325 binary_path = require_liteparse_binary ()
308- pdf_content = _download_test_pdf ()
326+ pdf_a = _download_pdf (PDF_URL_A )
327+ pdf_b = _download_pdf (PDF_URL_B )
309328
310329 with tempfile .TemporaryDirectory () as tmpdir :
311330 tmpdir = Path (tmpdir )
312331 snap_dir = tmpdir / "snap"
313332
314- # Place PDF in pdf/ plugin output
333+ # Place PDF A in pdf/ plugin output
315334 pdf_dir = snap_dir / "pdf"
316335 pdf_dir .mkdir (parents = True , exist_ok = True )
317- (pdf_dir / "output.pdf" ).write_bytes (pdf_content )
336+ (pdf_dir / "output.pdf" ).write_bytes (pdf_a )
318337
319- # Place another PDF in responses/
338+ # Place PDF B in responses/ as if the server served a PDF
320339 responses_dir = snap_dir / "responses" / "application" / "example.com"
321340 responses_dir .mkdir (parents = True , exist_ok = True )
322- (responses_dir / "document.pdf" ).write_bytes (pdf_content )
341+ (responses_dir / "document.pdf" ).write_bytes (pdf_b )
323342
324343 env = os .environ .copy ()
325344 env ["SNAP_DIR" ] = str (snap_dir )
@@ -351,10 +370,25 @@ def test_extract_multiple_pdfs():
351370 )
352371 assert metadata ["total_sources_found" ] == 2
353372
354- # Verify combined output contains content from both files
355373 text_content = (output_dir / "content.txt" ).read_text (errors = "ignore" )
356- assert "---" in text_content or text_content .count ("<!-- source:" ) >= 2 , (
357- "Combined text should contain content from both PDFs"
374+ text_lower = text_content .lower ()
375+
376+ # Assert unique content from PDF A (unec.edu.az pdf-sample.pdf)
377+ # This PDF is about Adobe Acrobat and contains this exact phrase:
378+ assert "preserves all" in text_lower and "colours and graphics" in text_lower , (
379+ f"Expected text from PDF_URL_A about 'preserves all of the fonts, formatting, "
380+ f"colours and graphics'. Got: { text_content [:500 ]!r} "
381+ )
382+
383+ # Assert unique content from PDF B (pdfobject.com sample.pdf)
384+ # This PDF contains a simple greeting and Lorem ipsum:
385+ assert "this is a simple pdf file" in text_lower , (
386+ f"Expected text from PDF_URL_B: 'This is a simple PDF file'. "
387+ f"Got: { text_content [:500 ]!r} "
388+ )
389+ assert "consectetuer adipiscing elit" in text_lower , (
390+ f"Expected text from PDF_URL_B: 'consectetuer adipiscing elit'. "
391+ f"Got: { text_content [:500 ]!r} "
358392 )
359393
360394
0 commit comments