1"""VM-free gate for corpus/recycle-bin-view: OneNote 2010 reads a recycle bin Snowbound wrote, and
2the notebook after pages and a section left it and the rest was emptied, without repairing
3either."""
4
5import pathlib
6import unittest
7import xml.etree.ElementTree as ElementTree
8
9ROOT = pathlib.Path(__file__).resolve().parents[1] / "corpus" / "recycle-bin-view"
10ONE = "{http://schemas.microsoft.com/office/onenote/2010/onenote}"
11
12
13def tree(state):
14 notebook = ElementTree.parse(ROOT / "cold" / state / "read" / "hierarchy.xml").getroot()
15
16 def walk(node):
17 return [
18 (child.get("name"), [page.get("name") for page in child.findall(ONE + "Page")])
19 if child.tag == ONE + "Section"
20 else (child.get("name"), walk(child))
21 for child in node
22 if child.tag in (ONE + "Section", ONE + "SectionGroup")
23 ]
24
25 return walk(next(notebook.iter(ONE + "Notebook")) if notebook.tag != ONE + "Notebook" else notebook)
26
27
28class RecycleBinView(unittest.TestCase):
29 def test_onenote_reads_the_bin_snowbound_wrote(self):
30 self.assertEqual(
31 tree("before"),
32 [
33 ("New Section 1", ["Kept"]),
34 (
35 "OneNote_RecycleBin",
36 [
37 ("Deleted Pages", ["Restored page", "Copied page", "Purged page"]),
38 ("Back", ["Restored page"]),
39 ("Copied", ["Copied page"]),
40 ("Purged", ["Purged page"]),
41 ("Restored", ["In a restored section"]),
42 ("Emptied", ["In an emptied section"]),
43 ],
44 ),
45 ],
46 )
47
48 def test_restored_copied_and_emptied_read_as_meant(self):
49 self.assertEqual(
50 tree("after"),
51 [
52 ("New Section 1", ["Kept", "Restored page", "Copied page"]),
53 ("Restored", ["In a restored section"]),
54 ("OneNote_RecycleBin", [("Deleted Pages", [])]),
55 ],
56 )
57
58 def test_onenote_repaired_nothing(self):
59 for state in ("before", "after"):
60 candidate = ROOT / "candidate" / state
61 for written in candidate.rglob("*.one*"):
62 relative = written.relative_to(candidate)
63 cold = ROOT / "cold" / state / "notebook" / relative
64 self.assertEqual(written.read_bytes(), cold.read_bytes(), relative)
65
66
67if __name__ == "__main__":
68 unittest.main()