diff --git a/mscxyz/cli.py b/mscxyz/cli.py index 0659f97..df88a87 100644 --- a/mscxyz/cli.py +++ b/mscxyz/cli.py @@ -752,13 +752,12 @@ def list_styles(version: int) -> None: score.style.show_footer = args.style_show_footer # print("\n" + utils.color(file, "red")) - - # elif args.subcommand == "lyrics": - # score = Score(file) if args.lyrics_remap: score.lyrics.remap(args.lyrics_remap) - # elif args.lyrics_fix: - # score.lyrics.fix_lyrics(mscore=args.general_mscore) + + if args.lyrics_fix: + score.lyrics.fix_lyrics(mscore=args.general_mscore) + if args.lyrics_extract: no = 0 if args.lyrics_extract != "all": diff --git a/mscxyz/utils.py b/mscxyz/utils.py index 4a0f2a3..2677b82 100644 --- a/mscxyz/utils.py +++ b/mscxyz/utils.py @@ -594,9 +594,9 @@ def save(self, dest: str | Path) -> None: def read_file(filename: str | Path) -> str: - """Read the MuseScore XML file as text. + """Read the file as text. - :return: The content of the MuseScore XML file as text. + :return: The content of file as text. """ with open(filename, "r") as f: return f.read() diff --git a/tests/test_lyrics.py b/tests/test_lyrics.py index 80ab46b..1169d23 100644 --- a/tests/test_lyrics.py +++ b/tests/test_lyrics.py @@ -6,6 +6,7 @@ import pytest +import mscxyz from mscxyz import Score, utils from tests import helper from tests.helper import Cli @@ -70,10 +71,17 @@ def test_extract_by_number(self, lyrics: Score) -> None: class TestLyricsFix: - def _test_fix(self, version: int = 2) -> None: - score_path = helper.get_file("lyrics-fix.mscx", version) - Cli("lyrics", "--fix", score_path, legacy=True).execute() - score = helper.reload(score_path) + @pytest.mark.legacy + @pytest.mark.parametrize( + "version", + mscxyz.supported_versions, + ) + def test_fix_legacy(self, version: int) -> None: + score = ( + Cli("lyrics", "--fix", legacy=True) + .append_score("lyrics-fix.mscx", version) + .score() + ) self.lyrics = score.lyrics.elements text: list[str] = [] @@ -105,6 +113,7 @@ def _test_fix(self, version: int = 2) -> None: "lein.", "lein.", ] + assert syllabic == [ "begin", "begin", @@ -122,9 +131,60 @@ def _test_fix(self, version: int = 2) -> None: "end", ] - def test_fix(self) -> None: - self._test_fix(version=2) - self._test_fix(version=3) + @pytest.mark.parametrize( + "version", + mscxyz.supported_versions, + ) + def test_fix(self, version: int) -> None: + score = Cli("--fix-lyrics").append_score("lyrics-fix.mscx", version).score() + self.lyrics = score.lyrics.elements + + text: list[str] = [] + syllabic: list[str] = [] + for element in self.lyrics: + tag = element.element + tag_text = tag.find("text") + + text.append(utils.xml.get_text_safe(tag_text)) + tag_syllabic = tag.find("syllabic") + + syllabic_text = utils.xml.get_text(tag_syllabic) + if syllabic_text: + syllabic.append(syllabic_text) + + assert text == [ + "Al", + "K\xf6pf", + "le", + "chen", + "mei", + "un", + "ne", + "ters", + "En", + "Was", + "te", + "si", + "lein.", + "lein.", + ] + + assert syllabic == [ + "begin", + "begin", + "end", + "end", + "begin", + "begin", + "end", + "end", + "begin", + "begin", + "middle", + "middle", + "end", + "end", + ] class TestLyricsRemap: