-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_mei.py
26 lines (23 loc) · 948 Bytes
/
test_mei.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import os
import re
import unittest
class TestMEIFiles(unittest.TestCase):
def setUp(self):
self.files = {}
for root, _, filenames in os.walk("."):
for f in sorted(filenames):
if not f.endswith(".mei"):
continue
filepath = os.path.join(root, f)
with open(filepath, "r") as fd:
filedata = fd.read()
self.files[filepath] = filedata
def test_no_unreferenced_zones(self):
zone_id = r"zone.*xml:id=\"([a-z0-9-]*)\""
for filepath, filedata in self.files.items():
zones = re.findall(zone_id, filedata)
body = filedata.split("<body>")[1]
unref = [z for z in zones if z not in body]
with self.subTest(filepath=filepath):
msg = f"{len(unref)} unreferenced zones detected in this file."
self.assertFalse(unref, msg=msg)