Skip to content

Commit

Permalink
Move --set-field to cli-ng
Browse files Browse the repository at this point in the history
  • Loading branch information
Josef-Friedrich committed Jan 16, 2024
1 parent ca0f407 commit 4ea8904
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 23 deletions.
6 changes: 6 additions & 0 deletions mscxyz/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,8 @@ def list_styles(version: int) -> None:
no = int(args.lyrics_extract)
score.lyrics.extract_lyrics(no)

# meta

if args.meta_metatag:
for a in args.meta_metatag:
field = a[0]
Expand Down Expand Up @@ -800,6 +802,10 @@ def list_styles(version: int) -> None:
)
setattr(score.meta.combined, field, value)

if args.meta_set:
for a in args.meta_set:
score.meta.set_field(destination_field=a[0], format_string=a[1])

# elif args.subcommand == "meta":
# score = Score(file)
# if __no_error(lxml.etree.XMLSyntaxError, score.errors):
Expand Down
90 changes: 67 additions & 23 deletions tests/test_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -819,30 +819,59 @@ def test_option_combined(self) -> None:
assert v.subtitle == "s"
assert v.title == "t"

def test_set_field_simple_string(self) -> None:

class TestOptionSetField:
@pytest.mark.legacy
def test_simple_string_legacy(self) -> None:
tmp = helper.get_score("meta-all-values.mscx")
Cli("meta", "--set-field", "vbox_title", "lol", tmp, legacy=True).execute()
Cli("meta", "--set-field", "vbox_title", "test", tmp, legacy=True).execute()
i = reload(tmp)
assert i.vbox_title == "lol"
assert i.vbox_title == "test"

def test_set_field_multiple_times(self) -> None:
def test_simple_string(self) -> None:
c = (
Cli("--set-field", "vbox_title", "test")
.use_score("meta-all-values.mscz")
.execute()
)
assert c.post.meta.interface.vbox_title == "test"

@pytest.mark.legacy
def test_multiple_times_legacy(self) -> None:
tmp = helper.get_score("meta-all-values.mscx")
Cli(
"meta",
"--set-field",
"vbox_title",
"lol",
"vt",
"--set-field",
"vbox_composer",
"troll",
"vc",
tmp,
legacy=True,
).execute()
i = reload(tmp)
assert i.vbox_title == "lol"
assert i.vbox_composer == "troll"
assert i.vbox_title == "vt"
assert i.vbox_composer == "vc"

def test_set_field_with_templating(self) -> None:
def test_multiple_times(self) -> None:
c = (
Cli(
"--set-field",
"vbox_title",
"vt",
"--set-field",
"vbox_composer",
"vc",
)
.use_score("meta-all-values.mscz")
.execute()
)
i = c.post.meta.interface
assert i.vbox_title == "vt"
assert i.vbox_composer == "vc"

def test_with_templating_legacy(self) -> None:
tmp = helper.get_score("meta-all-values.mscx")
Cli(
"meta",
Expand All @@ -855,14 +884,27 @@ def test_set_field_with_templating(self) -> None:
i = reload(tmp)
assert i.vbox_title == "vbox_title (vbox_composer)"

def test_log(self) -> None:
tmp = helper.get_score("simple.mscx")
log = tempfile.mktemp()
Cli(
"meta", "--log", log, "$combined_title-$combined_composer", tmp, legacy=True
).execute()
log_file = open(log, "r")
assert log_file.readline() == "Title-Composer\n"
def test_with_templating(self) -> None:
c = (
Cli(
"--set-field",
"vbox_title",
"$vbox_title ($vbox_composer)",
)
.use_score("meta-all-values.mscz")
.execute()
)
assert c.post.meta.interface.vbox_title == "vbox_title (vbox_composer)"


def test_log() -> None:
tmp = helper.get_score("simple.mscx")
log = tempfile.mktemp()
Cli(
"meta", "--log", log, "$combined_title-$combined_composer", tmp, legacy=True
).execute()
log_file = open(log, "r")
assert log_file.readline() == "Title-Composer\n"


class TestOptionDeleteDuplicates:
Expand All @@ -875,9 +917,8 @@ def test_normal_legacy(self) -> None:
assert not i.combined_subtitle

def test_normal(self) -> None:
tmp = helper.get_score("meta-duplicates.mscz", 4)
Cli("--delete-duplicates", tmp).execute()
i = reload(tmp)
c = Cli("--delete-duplicates").use_score("meta-duplicates.mscz").execute()
i = c.post.meta.interface
assert not i.combined_lyricist
assert not i.combined_subtitle

Expand All @@ -891,9 +932,12 @@ def test_move_subtitle_legacy(self) -> None:
assert i.combined_title == "Title"

def test_move_subtitle(self) -> None:
tmp = helper.get_score("meta-duplicates-move-subtitle.mscz", 4)
Cli("--delete-duplicates", tmp).execute()
i = reload(tmp)
c = (
Cli("--delete-duplicates")
.use_score("meta-duplicates-move-subtitle.mscz")
.execute()
)
i = c.post.meta.interface
assert not i.combined_lyricist
assert not i.combined_subtitle
assert i.combined_title == "Title"
Expand Down

0 comments on commit 4ea8904

Please sign in to comment.