doocus update and meeting list export
This commit is contained in:
@@ -13,6 +13,7 @@ from pathlib import Path
|
||||
from tests import REPO_ROOT # noqa: F401 (puts repo root on sys.path)
|
||||
from doocus import registry
|
||||
from doocus.workflow import DocConfig, DocWorkflow
|
||||
from doocus.tree import build_index, classify
|
||||
|
||||
|
||||
def has(mod: str) -> bool:
|
||||
@@ -136,5 +137,59 @@ class TestExtractors(unittest.TestCase):
|
||||
self.assertEqual(meta["title"], "PDF Doc")
|
||||
|
||||
|
||||
class TestTreeIndex(unittest.TestCase):
|
||||
def test_classify(self):
|
||||
self.assertEqual(classify("docx"), "extracted")
|
||||
self.assertEqual(classify("pdf"), "extracted")
|
||||
self.assertEqual(classify("mp4"), "meeting")
|
||||
self.assertEqual(classify("mkv"), "meeting")
|
||||
self.assertEqual(classify("md"), "link")
|
||||
self.assertEqual(classify("csv"), "link")
|
||||
self.assertEqual(classify("bin"), "link")
|
||||
|
||||
def test_build_index_replicates_tree(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
src = Path(tmp) / "drive"
|
||||
(src / "team a" / "sub").mkdir(parents=True)
|
||||
(src / "team a" / "notes.md").write_text("# Hi\n\nbody\n")
|
||||
(src / "team a" / "sub" / "t.csv").write_text("a,b\n1,2\n")
|
||||
(src / "team a" / "clip.mp4").write_bytes(b"\x00\x00") # video → meeting
|
||||
(src / "misc.bin").write_bytes(b"\x00") # unknown → link
|
||||
out = Path(tmp) / "out"
|
||||
|
||||
index = build_index(src, out)
|
||||
|
||||
# Whole tree replicated (no flattening), paths preserved.
|
||||
paths = {f["path"] for f in index["files"]}
|
||||
self.assertEqual(paths, {
|
||||
"team a/notes.md", "team a/sub/t.csv", "team a/clip.mp4", "misc.bin"})
|
||||
modes = {f["path"]: f["mode"] for f in index["files"]}
|
||||
self.assertEqual(modes["team a/clip.mp4"], "meeting")
|
||||
self.assertEqual(modes["team a/notes.md"], "link")
|
||||
self.assertEqual(modes["misc.bin"], "link")
|
||||
# Every node carries the Drive-url slot.
|
||||
self.assertTrue(all("url" in f for f in index["files"]))
|
||||
self.assertTrue((out / "index.json").exists())
|
||||
|
||||
@unittest.skipUnless(has("docx"), "python-docx not installed")
|
||||
def test_build_index_extracts_sidecar(self):
|
||||
import docx
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
src = Path(tmp) / "drive"
|
||||
src.mkdir()
|
||||
doc = docx.Document()
|
||||
doc.add_paragraph("hello world")
|
||||
doc.save(src / "report.docx")
|
||||
out = Path(tmp) / "out"
|
||||
|
||||
index = build_index(src, out)
|
||||
node = next(f for f in index["files"] if f["path"] == "report.docx")
|
||||
self.assertEqual(node["mode"], "extracted")
|
||||
sidecar = out / node["out"]
|
||||
self.assertTrue((sidecar / "content.md").exists())
|
||||
self.assertTrue((sidecar / "meta.json").exists())
|
||||
self.assertIn("hello", (sidecar / "content.md").read_text())
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user