1from pathlib import Path
2import runpy
3import shutil
4from tempfile import TemporaryDirectory
5import unittest
6import xml.etree.ElementTree as ET
7
8from native_xml import ns
9
10ROOT = Path(__file__).resolve().parent.parent
11FIXTURE = ROOT / 'corpus/table-widths'
12compare = runpy.run_path(str(ROOT / 'tools/verify-document.py'))['compare']
13
14
15def tables(read):
16 """Each page's tables by title: their first cell text and (width, locked) columns."""
17 result = {}
18 for path in sorted(read.glob('page-*.xml')):
19 page = ET.parse(path).getroot()
20 title = page.find('one:Title/one:OE/one:T', ns).text
21 result[title] = [
22 (table.find('.//one:T', ns).text,
23 [(round(float(column.get('width')), 2), column.get('isLocked') == 'true')
24 for column in table.findall('one:Columns/one:Column', ns)])
25 for table in page.iter('{%s}Table' % ns['one'])]
26 return result
27
28
29class TableWidthsTest(unittest.TestCase):
30 def test_typed_and_dragged_widths_reopen_natively(self):
31 with TemporaryDirectory() as temporary:
32 read = Path(temporary) / 'read'
33 shutil.copytree(FIXTURE / 'cold/read', read)
34 compare(FIXTURE / 'candidate', read)
35 cold = tables(FIXTURE / 'cold/read')
36 # OneNote 2010's own widths for the same table typed in it (lab, 2026-09-30).
37 self.assertEqual(cold['Check a table'][1],
38 ('Fruit', [(60.76, False), (37.11, False), (139.09, False)]))
39 self.assertEqual(cold['Edit a tagged table'][0][1], [(180.25, False), (37.11, False)])
40 dragged = cold['Delete and undo'][-1]
41 self.assertEqual(dragged[0], 'Dragged')
42 self.assertEqual(dragged[1][0], (96.0, True))
43 self.assertFalse(dragged[1][1][1])
44 self.assertGreater(dragged[1][1][0], 300)
45
46
47if __name__ == '__main__':
48 unittest.main()