Skip to content

Commit

Permalink
Merge pull request #3 from DDMAL/gh-actions
Browse files Browse the repository at this point in the history
Adding a basic gh-actions workflow to test the production MEI files
  • Loading branch information
dchiller authored Jun 15, 2022
2 parents 5c06b0b + 8029e6d commit 990508b
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/test.yml
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__pycache__/
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,8 @@ Each folder in the root of this repository represents a manuscript, denoted by i

Inside the folders, the naming convention for [MEI](https://music-encoding.org/) files is: ```<siglum>_<folio number>.mei```.
For example, for the folio `001r` in the `cdn-hsmu-m2149l4` ([Salzinnes Antiphonal](https://cantus.uwaterloo.ca/source/123723)) manuscript, the [MEI](https://music-encoding.org/) filename is `cdn-hsmu-m2149l4_001r.mei`.

## Validation of the [MEI](https://music-encoding.org/) files

In addition to the files, this repository is configured to run some basic sanity checks on the MEI files. Currently, the implemented checks will:
- Verify that the files do not have any declared but unreferenced `<zone>` elements.
26 changes: 26 additions & 0 deletions test_mei.py
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)

0 comments on commit 990508b

Please sign in to comment.