| 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/rtl-page' |
| 12 | compare = runpy.run_path(str(ROOT / 'tools/verify-document.py'))['compare'] |
| 13 | |
| 14 | |
| 15 | class RtlPageTest(unittest.TestCase): |
| 16 | def test_a_right_to_left_page_edited_in_snowbound_reopens_where_it_was_put(self): |
| 17 | with TemporaryDirectory() as temporary: |
| 18 | read = Path(temporary) / 'read' |
| 19 | shutil.copytree(FIXTURE / 'cold/read', read) |
| 20 | compare(FIXTURE / 'candidate', read) |
| 21 | page = ET.parse(FIXTURE / 'cold/read/page-000.xml').getroot() |
| 22 | self.assertEqual(page.find('one:PageSettings', ns).get('RTL'), 'true') |
| 23 | positions = {''.join(outline.find('.//one:T', ns).itertext()): outline.find('one:Position', ns).attrib |
| 24 | for outline in page.findall('one:Outline', ns) if outline.find('.//one:T', ns) is not None} |
| 25 | self.assertEqual((positions['Typed on a right-to-left page']['x'], positions['Fictitious positioned outline.']['x']), |
| 26 | ('126.0', '180.0')) |
| 27 | self.assertEqual(len(page.findall('one:InkDrawing', ns)), 3) |
| 28 | |
| 29 | |
| 30 | if __name__ == '__main__': |
| 31 | unittest.main() |