Skip to content

Commit

Permalink
Refactor the tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Josef-Friedrich committed Jan 16, 2024
1 parent c6a151b commit 9334602
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 43 deletions.
2 changes: 1 addition & 1 deletion tests/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def __execute(self) -> None:
self.__stderr = stderr.getvalue()
self.__executed = True

def use_score(self, filename: str, version: int = 4) -> Cli:
def append_score(self, filename: str, version: int = 4) -> Cli:
self.__set_score(get_score(filename, version=version), append_to_args=True)
return self

Expand Down
92 changes: 50 additions & 42 deletions tests/test_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,61 +427,69 @@ def test_setter(self, score: Score) -> None:
class TestOptionDistributeField:
@pytest.mark.legacy
def test_distribute_field_legacy(self) -> None:
tmp = helper.get_score("meta-distribute-field.mscx")
Cli(
"meta",
"--distribute-field",
"vbox_title",
"$combined_title - $combined_composer",
tmp,
legacy=True,
).execute()
i = reload(tmp)
c = (
Cli(
"meta",
"--distribute-field",
"vbox_title",
"$combined_title - $combined_composer",
legacy=True,
)
.append_score("meta-distribute-field.mscz")
.execute()
)
i = c.post.meta.interface
assert i.vbox_composer == "Composer"
assert i.metatag_composer == "Composer"
assert i.vbox_title == "Title"
assert i.metatag_work_title == "Title"

def test_distribute_field(self) -> None:
score = helper.get_score("meta-distribute-field.mscz", 4)
Cli(
"--distribute-field",
"vbox_title",
"$combined_title - $combined_composer",
score,
).execute()
i = reload(score)
c = (
Cli(
"--distribute-field",
"vbox_title",
"$combined_title - $combined_composer",
)
.append_score("meta-distribute-field.mscz")
.execute()
)
i = c.post.meta.interface
assert i.vbox_composer == "Composer"
assert i.metatag_composer == "Composer"
assert i.vbox_title == "Title"
assert i.metatag_work_title == "Title"

@pytest.mark.legacy
def test_distribute_field_multple_source_fields_legacy(self) -> None:
tmp = helper.get_score("Title - Composer.mscx")
Cli(
"meta",
"--distribute-field",
"vbox_title,readonly_basename",
"$combined_title - $combined_composer",
tmp,
legacy=True,
).execute()
i = reload(tmp)
c = (
Cli(
"meta",
"--distribute-field",
"vbox_title,readonly_basename",
"$combined_title - $combined_composer",
legacy=True,
)
.append_score("Title - Composer.mscz")
.execute()
)
i = c.post.meta.interface
assert i.vbox_composer == "Composer"
assert i.metatag_composer == "Composer"
assert i.vbox_title == "Title"
assert i.metatag_work_title == "Title"

def test_distribute_field_multple_source_fields(self) -> None:
tmp = helper.get_score("Title - Composer.mscz", 4)
Cli(
"--distribute-field",
"vbox_title,readonly_basename",
"$combined_title - $combined_composer",
tmp,
).execute()
i = reload(tmp)
c = (
Cli(
"--distribute-field",
"vbox_title,readonly_basename",
"$combined_title - $combined_composer",
)
.append_score("Title - Composer.mscz")
.execute()
)
i = c.post.meta.interface
assert i.vbox_composer == "Composer"
assert i.metatag_composer == "Composer"
assert i.vbox_title == "Title"
Expand Down Expand Up @@ -831,7 +839,7 @@ def test_simple_string_legacy(self) -> None:
def test_simple_string(self) -> None:
c = (
Cli("--set-field", "vbox_title", "test")
.use_score("meta-all-values.mscz")
.append_score("meta-all-values.mscz")
.execute()
)
assert c.post.meta.interface.vbox_title == "test"
Expand Down Expand Up @@ -864,7 +872,7 @@ def test_multiple_times(self) -> None:
"vbox_composer",
"vc",
)
.use_score("meta-all-values.mscz")
.append_score("meta-all-values.mscz")
.execute()
)
i = c.post.meta.interface
Expand All @@ -880,7 +888,7 @@ def test_with_templating_legacy(self) -> None:
"$vbox_title ($vbox_composer)",
legacy=True,
)
.use_score("meta-all-values.mscz")
.append_score("meta-all-values.mscz")
.execute()
)
assert c.post.meta.interface.vbox_title == "vbox_title (vbox_composer)"
Expand All @@ -892,7 +900,7 @@ def test_with_templating(self) -> None:
"vbox_title",
"$vbox_title ($vbox_composer)",
)
.use_score("meta-all-values.mscz")
.append_score("meta-all-values.mscz")
.execute()
)
assert c.post.meta.interface.vbox_title == "vbox_title (vbox_composer)"
Expand All @@ -918,7 +926,7 @@ def test_normal_legacy(self) -> None:
assert not i.combined_subtitle

def test_normal(self) -> None:
c = Cli("--delete-duplicates").use_score("meta-duplicates.mscz").execute()
c = Cli("--delete-duplicates").append_score("meta-duplicates.mscz").execute()
i = c.post.meta.interface
assert not i.combined_lyricist
assert not i.combined_subtitle
Expand All @@ -935,7 +943,7 @@ def test_move_subtitle_legacy(self) -> None:
def test_move_subtitle(self) -> None:
c = (
Cli("--delete-duplicates")
.use_score("meta-duplicates-move-subtitle.mscz")
.append_score("meta-duplicates-move-subtitle.mscz")
.execute()
)
i = c.post.meta.interface
Expand Down

0 comments on commit 9334602

Please sign in to comment.