| 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-copy' |
| 12 | compare = runpy.run_path(str(ROOT / 'tools/verify-document.py'))['compare'] |
| 13 | |
| 14 | |
| 15 | class PageCopyTest(unittest.TestCase): |
| 16 | def test_pages_copied_between_sections_read_natively(self): |
| 17 | with TemporaryDirectory() as temporary: |
| 18 | read = Path(temporary) / 'read' |
| 19 | shutil.copytree(FIXTURE / 'cold/read', read) |
| 20 | compare(FIXTURE / 'candidate', read) |
| 21 | pages = [ET.parse(path).getroot() for path in sorted((FIXTURE / 'cold/read').glob('page-*.xml'))] |
| 22 | self.assertEqual(len(pages), int((FIXTURE / 'candidate/expected-count.txt').read_text())) |
| 23 | kinds = {tag for page in pages for tag in {node.tag.rsplit('}', 1)[-1] for node in page.iter()}} |
| 24 | self.assertTrue({'InsertedFile', 'Image', 'Table', 'InkDrawing', 'Tag', 'List', 'Bullet', 'Number'} <= kinds, kinds) |
| 25 | hierarchy = ET.parse(FIXTURE / 'cold/read/hierarchy.xml').getroot() |
| 26 | titles = [page.get('name') for page in hierarchy.iter('{%s}Page' % ns['one'])] |
| 27 | self.assertEqual(titles[0], 'Destination') |
| 28 | self.assertNotIn('Paragraph formatting', titles) |
| 29 | self.assertEqual(len(set(titles)), len(titles)) |
| 30 | self.assertEqual(len(set(titles)), len(titles)) |
| 31 | |
| 32 | |
| 33 | if __name__ == '__main__': |
| 34 | unittest.main() |