MCPcopy Create free account
hub / github.com/LLMQuant/quant-mind / ReadLocalFileTests

Class ReadLocalFileTests

tests/preprocess/fetch/test_local.py:10–56  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8
9
10class 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)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected