Skip to content

Commit

Permalink
Move all tests from file text_examples.py into test_host_to.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Josef-Friedrich committed Feb 4, 2024
1 parent 3d0d9ce commit b2f7514
Show file tree
Hide file tree
Showing 2 changed files with 139 additions and 147 deletions.
132 changes: 0 additions & 132 deletions tests/test_examples.py

This file was deleted.

154 changes: 139 additions & 15 deletions tests/test_how_to.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from pathlib import Path

import pytest
from lxml.etree import _Element

from mscxyz import Score, list_path
from tests import helper
Expand Down Expand Up @@ -232,6 +233,96 @@ def test_set_musical_text_font(self) -> None:
assert c.post.style.get("musicalTextFont") == "MScore Text"


@pytest.mark.skip(
"Strange error! Fails in tox make test ... but works in vscode and with pytest -k test_set_meta_tag_title"
)
def test_set_all_font_faces_using_for_loop(score: Score) -> None:
assert score.style.get("defaultFontFace") == "FreeSerif"

for element in score.style.styles:
if "FontFace" in element.tag:
element.text = "Alegreya"
score.save()

new_score: Score = score.reload()
assert new_score.style.get("defaultFontFace") == "Alegreya"


@pytest.mark.skip(
"Strange error! Fails in tox make test ... but works in vscode and with pytest -k test_set_meta_tag_title"
)
def test_set_all_font_faces_using_method(score: Score) -> None:
assert score.style.get("defaultFontFace") == "FreeSerif"

response = score.style.set_text_fonts("Alegreya")

assert response == [
("lyricsOddFontFace", "FreeSerif", "Alegreya"),
("lyricsEvenFontFace", "FreeSerif", "Alegreya"),
("hairpinFontFace", "FreeSerif", "Alegreya"),
("pedalFontFace", "FreeSerif", "Alegreya"),
("chordSymbolAFontFace", "FreeSerif", "Alegreya"),
("chordSymbolBFontFace", "FreeSerif", "Alegreya"),
("nashvilleNumberFontFace", "FreeSerif", "Alegreya"),
("voltaFontFace", "FreeSerif", "Alegreya"),
("ottavaFontFace", "FreeSerif", "Alegreya"),
("tupletFontFace", "FreeSerif", "Alegreya"),
("defaultFontFace", "FreeSerif", "Alegreya"),
("titleFontFace", "FreeSerif", "Alegreya"),
("subTitleFontFace", "FreeSerif", "Alegreya"),
("composerFontFace", "FreeSerif", "Alegreya"),
("lyricistFontFace", "FreeSerif", "Alegreya"),
("fingeringFontFace", "FreeSerif", "Alegreya"),
("lhGuitarFingeringFontFace", "FreeSerif", "Alegreya"),
("rhGuitarFingeringFontFace", "FreeSerif", "Alegreya"),
("stringNumberFontFace", "FreeSerif", "Alegreya"),
("harpPedalDiagramFontFace", "Edwin", "Alegreya"),
("harpPedalTextDiagramFontFace", "Edwin", "Alegreya"),
("longInstrumentFontFace", "FreeSerif", "Alegreya"),
("shortInstrumentFontFace", "FreeSerif", "Alegreya"),
("partInstrumentFontFace", "FreeSerif", "Alegreya"),
("expressionFontFace", "FreeSerif", "Alegreya"),
("tempoFontFace", "FreeSerif", "Alegreya"),
("tempoChangeFontFace", "Edwin", "Alegreya"),
("metronomeFontFace", "FreeSerif", "Alegreya"),
("measureNumberFontFace", "FreeSerif", "Alegreya"),
("mmRestRangeFontFace", "Edwin", "Alegreya"),
("translatorFontFace", "FreeSerif", "Alegreya"),
("systemFontFace", "FreeSerif", "Alegreya"),
("staffFontFace", "FreeSerif", "Alegreya"),
("rehearsalMarkFontFace", "FreeSerif", "Alegreya"),
("repeatLeftFontFace", "FreeSerif", "Alegreya"),
("repeatRightFontFace", "FreeSerif", "Alegreya"),
("frameFontFace", "FreeSerif", "Alegreya"),
("textLineFontFace", "FreeSerif", "Alegreya"),
("systemTextLineFontFace", "Edwin", "Alegreya"),
("glissandoFontFace", "FreeSerif", "Alegreya"),
("bendFontFace", "FreeSerif", "Alegreya"),
("headerFontFace", "FreeSerif", "Alegreya"),
("footerFontFace", "FreeSerif", "Alegreya"),
("instrumentChangeFontFace", "FreeSerif", "Alegreya"),
("stickingFontFace", "FreeSerif", "Alegreya"),
("user1FontFace", "FreeSerif", "Alegreya"),
("user2FontFace", "FreeSerif", "Alegreya"),
("user3FontFace", "FreeSerif", "Alegreya"),
("user4FontFace", "FreeSerif", "Alegreya"),
("user5FontFace", "FreeSerif", "Alegreya"),
("user6FontFace", "FreeSerif", "Alegreya"),
("user7FontFace", "FreeSerif", "Alegreya"),
("user8FontFace", "FreeSerif", "Alegreya"),
("user9FontFace", "FreeSerif", "Alegreya"),
("user10FontFace", "FreeSerif", "Alegreya"),
("user11FontFace", "FreeSerif", "Alegreya"),
("user12FontFace", "FreeSerif", "Alegreya"),
("letRingFontFace", "FreeSerif", "Alegreya"),
("palmMuteFontFace", "FreeSerif", "Alegreya"),
]
score.save()

new_score: Score = score.reload()
assert new_score.style.get("defaultFontFace") == "Alegreya"


class TestAutocomplete:
def test_bash(self) -> None:
assert (
Expand All @@ -252,19 +343,52 @@ def test_tcsh(self) -> None:
)


class TestRename:
def test_rename(self, tmp_path: Path) -> None:
src = helper.get_dir("leadsheets", 4)
dest = tmp_path
Cli(
"--rename",
"%lower{%shorten{$title,1}}/$title",
"--target",
dest,
"--no-whitespace",
src,
).execute()
def test_rename(tmp_path: Path) -> None:
src = helper.get_dir("leadsheets", 4)
dest = tmp_path
Cli(
"--rename",
"%lower{%shorten{$title,1}}/$title",
"--target",
dest,
"--no-whitespace",
src,
).execute()

assert (dest / "i" / "I-Walk-the-Line.mscz").exists()
assert (dest / "j" / "Jackson.mscz").exists()
assert (dest / "f" / "Folsom-Prison-Blues.mscz").exists()


def test_instantiate_a_score_object(score_file: str) -> None:
score = Score(score_file)
assert score.path.exists()
assert score.filename == "score.mscz"
assert score.basename == "score"
assert score.extension == "mscz"
assert score.version == 4.20
assert score.version_major == 4


def test_investigate_xml_root(score_file: str) -> None:
score = Score(score_file)

def print_elements(element: _Element, level: int) -> None:
for sub_element in element:
print(f"{' ' * level}<{sub_element.tag}>")
print_elements(sub_element, level + 1)

print_elements(score.xml_root, 0)


@pytest.mark.skip(
"Strange error! Fails in tox make test ... but works in vscode and with pytest -k test_set_meta_tag_title"
)
def test_set_meta_tag_composer(score: Score) -> None:
assert score.meta.metatag.composer == "Composer"

score.meta.metatag.composer = "Mozart"
score.save()

assert (dest / "i" / "I-Walk-the-Line.mscz").exists()
assert (dest / "j" / "Jackson.mscz").exists()
assert (dest / "f" / "Folsom-Prison-Blues.mscz").exists()
new_score: Score = score.reload()
assert new_score.meta.metatag.composer == "Mozart"

0 comments on commit b2f7514

Please sign in to comment.