| 8 | |
| 9 | |
| 10 | class ReadLocalFileTests(unittest.IsolatedAsyncioTestCase): |
| 11 | async def test_reads_pdf_payload(self): |
| 12 | with tempfile.TemporaryDirectory() as tmp: |
| 13 | path = Path(tmp) / "doc.pdf" |
| 14 | path.write_bytes(b"%PDF-1.4\nfake\n") |
| 15 | result = await read_local_file(path) |
| 16 | self.assertEqual(result.bytes, b"%PDF-1.4\nfake\n") |
| 17 | self.assertEqual(result.content_type, "application/pdf") |
| 18 | self.assertTrue(result.source_url.startswith("file://")) |
| 19 | self.assertEqual(result.headers, {}) |
| 20 | |
| 21 | async def test_html_inferred(self): |
| 22 | with tempfile.TemporaryDirectory() as tmp: |
| 23 | path = Path(tmp) / "page.html" |
| 24 | path.write_bytes(b"<html></html>") |
| 25 | result = await read_local_file(path) |
| 26 | self.assertEqual(result.content_type, "text/html") |
| 27 | |
| 28 | async def test_markdown_inferred(self): |
| 29 | with tempfile.TemporaryDirectory() as tmp: |
| 30 | path = Path(tmp) / "notes.md" |
| 31 | path.write_bytes(b"# title") |
| 32 | result = await read_local_file(path) |
| 33 | self.assertEqual(result.content_type, "text/markdown") |
| 34 | |
| 35 | async def test_unknown_suffix_falls_back_to_octet_stream(self): |
| 36 | with tempfile.TemporaryDirectory() as tmp: |
| 37 | path = Path(tmp) / "blob.bin" |
| 38 | path.write_bytes(b"\x00\x01") |
| 39 | result = await read_local_file(path) |
| 40 | self.assertEqual(result.content_type, "application/octet-stream") |
| 41 | |
| 42 | async def test_accepts_string_path(self): |
| 43 | with tempfile.TemporaryDirectory() as tmp: |
| 44 | path = Path(tmp) / "page.txt" |
| 45 | path.write_bytes(b"hi") |
| 46 | result = await read_local_file(str(path)) |
| 47 | self.assertEqual(result.bytes, b"hi") |
| 48 | |
| 49 | async def test_missing_raises(self): |
| 50 | with self.assertRaises(FileNotFoundError): |
| 51 | await read_local_file("/nonexistent/path/to/nothing.pdf") |
| 52 | |
| 53 | async def test_directory_raises(self): |
| 54 | with tempfile.TemporaryDirectory() as tmp: |
| 55 | with self.assertRaises(IsADirectoryError): |
| 56 | await read_local_file(tmp) |
nothing calls this directly
no outgoing calls
no test coverage detected