-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from DDMAL/gh-actions
Adding a basic gh-actions workflow to test the production MEI files
- Loading branch information
Showing
4 changed files
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
name: unit-tests | ||
on: | ||
pull_request: | ||
types: [opened, synchronize] | ||
jobs: | ||
run-tests: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Run basic tests on all MEI files | ||
- run: python -m unittest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
__pycache__/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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) |