1from pathlib import Path
2import re
3import runpy
4import shutil
5from tempfile import TemporaryDirectory
6import unittest
7
8ROOT = Path(__file__).resolve().parent.parent
9FIXTURE = ROOT / 'corpus/equation-join'
10compare = runpy.run_path(str(ROOT / 'tools/verify-document.py'))['compare']
11
12
13def mathml(xml):
14 """Each equation's MathML in a COM read, trailing spaces dropped."""
15 return [re.sub(r'(<mml:mo>&nbsp;</mml:mo>)+</mml:math>', '</mml:math>', m)
16 for m in re.findall(r'<mml:math[^!]*?</mml:math>', xml)]
17
18
19class EquationJoinTest(unittest.TestCase):
20 def test_joined_equations_reopen_as_onenote_joined_them(self):
21 with TemporaryDirectory() as temporary:
22 read = Path(temporary) / 'read'
23 shutil.copytree(FIXTURE / 'cold/read', read)
24 compare(FIXTURE / 'candidate', read)
25 onenote = mathml((FIXTURE / 'lab/equation-seam.xml').read_text())
26 cold = mathml(''.join(path.read_text(encoding='utf-8-sig') for path in sorted((FIXTURE / 'cold/read').glob('page-*.xml'))))
27 self.assertEqual(len(onenote), 1)
28 self.assertEqual([m.replace(' display="block"', '') for m in cold],
29 [m.replace(' display="block"', '') for m in onenote])
30
31
32if __name__ == '__main__':
33 unittest.main()