Skip to content

Commit

Permalink
Implement --fix-lyrics in cli NG
Browse files Browse the repository at this point in the history
  • Loading branch information
Josef-Friedrich committed Jan 19, 2024
1 parent fe0db5d commit e203a14
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 14 deletions.
9 changes: 4 additions & 5 deletions mscxyz/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down
4 changes: 2 additions & 2 deletions mscxyz/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
74 changes: 67 additions & 7 deletions tests/test_lyrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import pytest

import mscxyz
from mscxyz import Score, utils
from tests import helper
from tests.helper import Cli
Expand Down Expand Up @@ -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] = []
Expand Down Expand Up @@ -105,6 +113,7 @@ def _test_fix(self, version: int = 2) -> None:
"lein.",
"lein.",
]

assert syllabic == [
"begin",
"begin",
Expand All @@ -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:
Expand Down

0 comments on commit e203a14

Please sign in to comment.