| 1 | from pathlib import Path |
| 2 | import re |
| 3 | import runpy |
| 4 | import shutil |
| 5 | from tempfile import TemporaryDirectory |
| 6 | import unittest |
| 7 | |
| 8 | ROOT = Path(__file__).resolve().parent.parent |
| 9 | FIXTURE = ROOT / 'corpus/picture-link' |
| 10 | compare = runpy.run_path(str(ROOT / 'tools/verify-document.py'))['compare'] |
| 11 | |
| 12 | |
| 13 | class PictureLinkTest(unittest.TestCase): |
| 14 | def test_restored_picture_reopens_with_its_link(self): |
| 15 | with TemporaryDirectory() as temporary: |
| 16 | read = Path(temporary) / 'read' |
| 17 | shutil.copytree(FIXTURE / 'cold/read', read) |
| 18 | compare(FIXTURE / 'candidate', read) |
| 19 | links = sorted(m for path in (FIXTURE / 'cold/read').glob('page-*.xml') |
| 20 | for m in re.findall(r'<one:Image [^>]*hyperlink="([^"]*)"', |
| 21 | path.read_text(encoding='utf-8-sig'))) |
| 22 | self.assertIn('https://example.invalid/image/png', links) |
| 23 | self.assertEqual(len(links), 5) |
| 24 | |
| 25 | |
| 26 | if __name__ == '__main__': |
| 27 | unittest.main() |