| 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/media-edit' |
| 12 | compare = runpy.run_path(str(ROOT / 'tools/verify-document.py'))['compare'] |
| 13 | |
| 14 | |
| 15 | class MediaEditTest(unittest.TestCase): |
| 16 | def test_an_edit_next_to_a_recording_keeps_the_recording_and_its_annotation(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 | page = next(page for page in pages if page.get('name') == 'Files and recording') |
| 23 | media = page.find('.//one:MediaFile', ns) |
| 24 | self.assertEqual(media.get('preferredName'), 'silence.wav') |
| 25 | recording = media.find('one:MediaReference', ns).get('mediaID') |
| 26 | index = page.find('.//one:MediaIndex', ns) |
| 27 | self.assertEqual(index.get('timeIndex'), '500') |
| 28 | self.assertEqual(index.find('one:MediaReference', ns).get('mediaID'), recording) |
| 29 | texts = [t.text for t in page.findall('.//one:T', ns) if t.text] |
| 30 | self.assertIn('Added after recording', texts) |
| 31 | |
| 32 | |
| 33 | if __name__ == '__main__': |
| 34 | unittest.main() |