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/printout'
12compare = runpy.run_path(str(ROOT / 'tools/verify-document.py'))['compare']
13
14
15def pictures(read):
16 """The printout page's pictures in order: printout state, printout page and position."""
17 for path in sorted(read.glob('page-*.xml')):
18 page = ET.parse(path).getroot()
19 if page.get('name') == 'Printout':
20 return [(image.get('isPrintOut'), image.get('originalPageNumber'),
21 image.find('one:Position', ns).get('y'))
22 for image in page.findall('one:Image', ns)]
23
24
25class PrintoutTest(unittest.TestCase):
26 def test_edited_printout_reopens_natively(self):
27 for notebook, read in (('native/notebook', 'native/read'), ('candidate', 'cold/read')):
28 with TemporaryDirectory() as temporary:
29 copy = Path(temporary) / 'read'
30 shutil.copytree(FIXTURE / read, copy)
31 compare(FIXTURE / notebook, copy)
32 native = pictures(FIXTURE / 'native/read')
33 self.assertEqual([(p, n) for p, n, _ in native], [('true', '0'), ('true', '1')])
34 # The first page moved half an inch down stays a printout; the second, deleted and
35 # restored, is the printout page it was.
36 cold = pictures(FIXTURE / 'cold/read')
37 self.assertEqual(cold, [('true', '0', str(float(native[0][2]) + 36)), ('true', '1', native[1][2])])
38
39
40if __name__ == '__main__':
41 unittest.main()