Skip to content

Commit

Permalink
Get rid of score.abspath
Browse files Browse the repository at this point in the history
  • Loading branch information
Josef-Friedrich committed Jan 2, 2024
1 parent b7447b1 commit fb76ad5
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 28 deletions.
1 change: 0 additions & 1 deletion mscxyz/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
MuseScoreFile
"""see submodule ``score.py``"""


MscoreLyricsInterface
"""see submodule ``lyrics.py``"""

Expand Down
2 changes: 1 addition & 1 deletion mscxyz/meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ def __init__(self, tree: MuseScoreFile):

@property
def readonly_abspath(self) -> str:
return self.xml_tree.abspath
return str(self.xml_tree.path)

@property
def readonly_basename(self) -> str:
Expand Down
7 changes: 1 addition & 6 deletions mscxyz/score.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,6 @@ class MuseScoreFile:
``files/by_version/2/simple.mscx``.
"""

abspath: str
"""The absolute path of the score file, for example:
``/home/jf/test/files/by_version/2/simple.mscx``."""

relpath_backup: str

dirname: str
Expand Down Expand Up @@ -196,7 +192,6 @@ def __init__(self, relpath: str) -> None:
self.errors = []
self.relpath = relpath
self.path = Path(relpath).resolve()
self.abspath = os.path.abspath(relpath)
self.relpath_backup = relpath.replace(
"." + self.extension, "_bak." + self.extension
)
Expand All @@ -207,7 +202,7 @@ def __init__(self, relpath: str) -> None:
self.zip_container = ZipContainer(self.path)
self.loadpath = str(self.zip_container.mscx_file)
else:
self.loadpath = self.abspath
self.loadpath = str(self.path)

try:
self.xml_tree = lxml.etree.parse(self.loadpath)
Expand Down
33 changes: 14 additions & 19 deletions tests/test_score.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import filecmp
import os
import pathlib
import shutil
import tempfile
from typing import Optional
Expand Down Expand Up @@ -91,14 +90,10 @@ def setup_method(self) -> None:
self.file = MuseScoreFile(helper.get_file("simple.mscx"))

def test_attribute_path(self) -> None:
assert self.file.relpath

def test_attribute_relpath(self) -> None:
assert self.file.path.exists()

def test_attribute_abspath(self) -> None:
assert self.file.abspath == self.file.loadpath
pathlib.Path(self.file.abspath).exists()
def test_attribute_relpath(self) -> None:
assert self.file.relpath

def test_attribute_dirname(self) -> None:
assert self.file.dirname
Expand Down Expand Up @@ -211,42 +206,42 @@ def test_method_save(self) -> None:


class TestMuseScoreFileVersion2:
tree = MuseScoreFile(helper.get_file("simple.mscz", 2))
score = helper.get_score("simple.mscz", 2)

def test_property_version(self) -> None:
assert self.tree.version == 2.06
assert self.score.version == 2.06

def test_property_version_major(self) -> None:
assert self.tree.version_major == 2
assert self.score.version_major == 2

def test_method_get_version(self) -> None:
assert self.tree.get_version() == 2.06
assert self.score.get_version() == 2.06


class TestMuseScoreFileVersion3:
tree = MuseScoreFile(helper.get_file("simple.mscz", 3))
score = helper.get_score("simple.mscz", 3)

def test_property_version(self) -> None:
assert self.tree.version == 3.01
assert self.score.version == 3.01

def test_property_version_major(self) -> None:
assert self.tree.version_major == 3
assert self.score.version_major == 3

def test_method_get_version(self) -> None:
assert self.tree.get_version() == 3.01
assert self.score.get_version() == 3.01


class TestMuseScoreFileVersion4:
tree = MuseScoreFile(helper.get_file("simple.mscz", 4))
score = helper.get_score("simple.mscz", 4)

def test_property_version(self) -> None:
assert self.tree.version == 4.2
assert self.score.version == 4.2

def test_property_version_major(self) -> None:
assert self.tree.version_major == 4
assert self.score.version_major == 4

def test_method_get_version(self) -> None:
assert self.tree.get_version() == 4.2
assert self.score.get_version() == 4.2


class TestClean:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_style.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def reload(score: MuseScoreFile) -> MscoreStyleInterface:
:param score: The MuseScore file to reload the style from.
:return: The reloaded style.
"""
score = MuseScoreFile(score.abspath)
score = MuseScoreFile(str(score.path))
return score.style


Expand Down

0 comments on commit fb76ad5

Please sign in to comment.