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/extended-ascii'
12compare = runpy.run_path(str(ROOT / 'tools/verify-document.py'))['compare']
13
14
15class ExtendedAsciiTest(unittest.TestCase):
16 def test_onenote_reads_extended_ascii_as_latin_1_whatever_the_language(self):
17 expected = 'Extended bytes: ' + ' '.join(chr(byte) for byte in range(128, 256))
18 for language in ('en', 'ru', 'ja'):
19 with self.subTest(language=language):
20 capture = FIXTURE / language / 'cold'
21 with TemporaryDirectory() as temporary:
22 read = Path(temporary) / 'read'
23 shutil.copytree(capture / 'read', read)
24 compare(FIXTURE / language / 'candidate', read)
25 page = ET.parse(capture / 'read/page-000.xml').getroot()
26 texts = [t.text for t in page.iterfind('.//one:Outline//one:T', ns)]
27 self.assertEqual(texts, [expected.replace('\xa0', ' ')])
28
29
30if __name__ == '__main__':
31 unittest.main()