Skip to content

Commit

Permalink
Improve gui testing
Browse files Browse the repository at this point in the history
  • Loading branch information
Josef-Friedrich committed Feb 3, 2024
1 parent 8d2c3e7 commit efdae6a
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 11 deletions.
28 changes: 23 additions & 5 deletions mscxyz/score.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,14 @@ def is_uncompressed(self) -> bool:
return self.extension != "mscz"

def change_path(
self, suffix: Optional[Any] = None, extension: Optional[str] = None
self,
suffix: Optional[Any] = None,
extension: Optional[str] = None,
filename: Optional[str] = None,
) -> Path:
return utils.PathChanger(self.path).change(suffix=suffix, extension=extension)
return utils.PathChanger(self.path).change(
suffix=suffix, extension=extension, filename=filename
)

@property
def export(self) -> Export:
Expand Down Expand Up @@ -163,8 +168,21 @@ def style(self) -> Style:
def make_snapshot(self) -> None:
self.__xml_string_initial = self.xml_string

def new(self) -> Score:
return Score(self.path)
def new(
self,
suffix: Optional[Any] = None,
extension: Optional[str] = None,
filename: Optional[str] = None,
) -> Score:
return Score(
self.change_path(suffix=suffix, extension=extension, filename=filename)
)

def __str__(self) -> str:
return str(self.path)

def exists(self) -> bool:
return self.path.exists()

def backup(self) -> None:
"""Make a copy of the MuseScore file."""
Expand Down Expand Up @@ -279,4 +297,4 @@ def reload(self, save: bool = False) -> Score:
"""
if save:
self.save()
return Score(self.path)
return self.new()
7 changes: 6 additions & 1 deletion mscxyz/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,13 @@ def add_suffix(self, suffix: Any) -> Path:
)

def change(
self, suffix: Optional[Any] = None, extension: Optional[str] = None
self,
suffix: Optional[Any] = None,
extension: Optional[str] = None,
filename: Optional[str] = None,
) -> Path:
if filename is not None:
return self.path.parent / filename
path_changer: PathChanger = self.new()
if suffix:
path_changer = PathChanger(path_changer.add_suffix(suffix))
Expand Down
2 changes: 1 addition & 1 deletion tests/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ def open_in_mscore(self) -> None:
open_in_gui(self.score().path)


def open_in_gui(file: str | Path) -> None:
def open_in_gui(file: str | Path | Score) -> None:
"""Open a file wiht xdg-open in the background"""
subprocess.Popen(("/usr/local/bin/mscore", str(file)), close_fds=True)

Expand Down
5 changes: 1 addition & 4 deletions tests/test_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,8 @@ def test_din_a4_compress_rename() -> None:
.append_score("Im-Fruehtau-zu-Berge.mscz")
.score()
)

dest = score.path.parent / "_Piano_A4.mscz"

dest = score.new(filename="_Piano_A4.mscz")
assert dest.exists()

open_in_gui(dest)


Expand Down

0 comments on commit efdae6a

Please sign in to comment.