| 1 | from pathlib import Path |
| 2 | import runpy |
| 3 | import shutil |
| 4 | from tempfile import TemporaryDirectory |
| 5 | import unittest |
| 6 | import xml.etree.ElementTree as ET |
| 7 | |
| 8 | from native_xml import ns |
| 9 | |
| 10 | ROOT = Path(__file__).resolve().parent.parent |
| 11 | FIXTURE = ROOT / 'corpus/page-date' |
| 12 | compare = runpy.run_path(str(ROOT / 'tools/verify-document.py'))['compare'] |
| 13 | |
| 14 | |
| 15 | def native_pages(notebook, capture): |
| 16 | with TemporaryDirectory() as temporary: |
| 17 | read = Path(temporary) / 'read' |
| 18 | shutil.copytree(capture / 'read', read) |
| 19 | compare(notebook, read) |
| 20 | pages = (ET.parse(path).getroot() for path in sorted((capture / 'read').glob('page-*.xml'))) |
| 21 | return {page.get('name'): page for page in pages} |
| 22 | |
| 23 | |
| 24 | class PageDateTest(unittest.TestCase): |
| 25 | def test_onenote_dates_a_page_through_its_creation_time(self): |
| 26 | pages = native_pages(FIXTURE / 'native/notebook', FIXTURE / 'native') |
| 27 | self.assertEqual(pages['Changed date'].get('dateTime'), '2024-03-05T14:30:00.000Z') |
| 28 | self.assertNotEqual(pages['Kept date'].get('dateTime'), '2024-03-05T14:30:00.000Z') |
| 29 | |
| 30 | def test_a_rust_dated_page_reads_back_with_its_new_date(self): |
| 31 | pages = native_pages(FIXTURE / 'candidate', FIXTURE / 'cold') |
| 32 | self.assertEqual(pages['Kept date'].get('dateTime'), '2025-07-04T16:45:00.000Z') |
| 33 | self.assertEqual(pages['Changed date'].get('dateTime'), '2024-03-05T14:30:00.000Z') |
| 34 | title = pages['Kept date'].find('one:Title/one:OE/one:T', ns) |
| 35 | self.assertEqual(title.text, 'Kept date') |
| 36 | |
| 37 | |
| 38 | if __name__ == '__main__': |
| 39 | unittest.main() |