Skip to content

Add semantic tests for the MusicXML export - #199

Open
wang1zhen wants to merge 1 commit into
frescobaldi:masterfrom
wang1zhen:musicxml-tests
Open

wang1zhen wants to merge 1 commit into
frescobaldi:masterfrom
wang1zhen:musicxml-tests

Conversation

@wang1zhen

@wang1zhen wang1zhen commented Oct 2, 2026 •

Copy link
Copy Markdown

Add semantic tests for the MusicXML export

This is the first of four PRs that improve the LilyPond to MusicXML export (ly.musicxml). It only adds tests; the following PRs build on it:

  1. this PR: tests
  2. MusicXML export: don't hide errors, write valid MusicXML 4.0 #202: errors are no longer hidden, the output is valid MusicXML 4.0
  3. MusicXML export: measures, divisions and grace notes #200: measures, durations and grace notes
  4. MusicXML export: transpose, repeats, chord mode, lyrics and partCombine #201: \transpose, repeats, chord mode, lyrics and \partCombine

What it adds

The existing tests compare whole files, so a change anywhere in the output makes them fail, and they cover few features. The new tests look only at the part of the output they are about: pitches, voices, measure lengths, divisions, barlines and so on. Helpers for this are in tests/musicxml_helpers.py.

  • One test module per area of the export: dispatch of ly.music nodes, \transpose, repeats, chord mode, \afterGrace, \partCombine, lyrics, measures, divisions, and the MusicXML version.
  • A corpus of realistic snippets (tests/musicxml_corpus.py): every snippet must convert without warnings to MusicXML that is valid against the schema.
  • The MusicXML 4.0 schema, localized like the existing 3.0 schema (tests/musicxml-4.0/).

Tests for behaviour that does not work yet are marked as strict xfail. Each of the following PRs removes the markers of the tests it makes pass, so its effect is visible in the test results.

Writing these tests found several bugs in the current export, among them:

  • a measure ends in the middle of a triplet
  • the overflow of a note that crosses a barline is dropped
  • \transpose is ignored
  • the forward repeat is put on the right barline
  • the stanzas of the lyrics are all numbered 1
  • \scaleDurations crashes
  • the DOCTYPE says MusicXML 2.0

All of these are fixed in the following PRs.

🤖 Generated with Claude Code

Instead of comparing whole files, the new tests look at the parts of the
output they are about (pitches, voices, measure lengths, divisions,
barlines, ...), with helpers in tests/musicxml_helpers.py:

- one test module per area of the export: dispatch of ly.music nodes,
  \transpose, repeats, chord mode, \afterGrace, \partCombine, lyrics,
  measures, divisions and the MusicXML version
- a corpus of realistic snippets that must convert, without warnings, to
  MusicXML that is valid against the schema
- the localized MusicXML 4.0 schema (tests/musicxml-4.0/)

Tests for behaviour that is not implemented yet are marked as strict
xfail; the changes implementing it remove the markers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CMyxTwm2w6VtbxBdt5dL1T

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants