From fb76ad50f75adc78dae6998564e1085a985a8567 Mon Sep 17 00:00:00 2001 From: Josef Friedrich Date: Tue, 2 Jan 2024 18:59:05 +0100 Subject: [PATCH] Get rid of score.abspath --- mscxyz/__init__.py | 1 - mscxyz/meta.py | 2 +- mscxyz/score.py | 7 +------ tests/test_score.py | 33 ++++++++++++++------------------- tests/test_style.py | 2 +- 5 files changed, 17 insertions(+), 28 deletions(-) diff --git a/mscxyz/__init__.py b/mscxyz/__init__.py index 5b63893..ff3fcaa 100644 --- a/mscxyz/__init__.py +++ b/mscxyz/__init__.py @@ -57,7 +57,6 @@ MuseScoreFile """see submodule ``score.py``""" - MscoreLyricsInterface """see submodule ``lyrics.py``""" diff --git a/mscxyz/meta.py b/mscxyz/meta.py index 117a8b2..a9b84bb 100644 --- a/mscxyz/meta.py +++ b/mscxyz/meta.py @@ -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: diff --git a/mscxyz/score.py b/mscxyz/score.py index 53c103c..6a3f76a 100644 --- a/mscxyz/score.py +++ b/mscxyz/score.py @@ -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 @@ -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 ) @@ -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) diff --git a/tests/test_score.py b/tests/test_score.py index ab206b0..96e0c96 100644 --- a/tests/test_score.py +++ b/tests/test_score.py @@ -5,7 +5,6 @@ import filecmp import os -import pathlib import shutil import tempfile from typing import Optional @@ -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 @@ -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: diff --git a/tests/test_style.py b/tests/test_style.py index 1ca3f30..e3a74b2 100644 --- a/tests/test_style.py +++ b/tests/test_style.py @@ -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