Skip to content

Commit 0dd6cb3

Browse files
committed
Replace assert_equal_path
1 parent ca3adfe commit 0dd6cb3

File tree

4 files changed

+35
-85
lines changed

4 files changed

+35
-85
lines changed

beets/test/_common.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -111,16 +111,6 @@ def import_session(lib=None, loghandler=None, paths=[], query=[], cli=False):
111111
return cls(lib, loghandler, paths, query)
112112

113113

114-
class Assertions:
115-
"""A mixin with additional unit test assertions."""
116-
117-
def assert_equal_path(self, a, b):
118-
"""Check that two paths are equal."""
119-
a_bytes, b_bytes = util.normpath(a), util.normpath(b)
120-
121-
assert a_bytes == b_bytes, f"{a_bytes=} != {b_bytes=}"
122-
123-
124114
# Mock I/O.
125115

126116

beets/test/helper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ def tearDown(self):
177177
self.io.restore()
178178

179179

180-
class TestHelper(_common.Assertions, ConfigMixin):
180+
class TestHelper(ConfigMixin):
181181
"""Helper mixin for high-level cli and plugin tests.
182182
183183
This mixin provides methods to isolate beets' global state provide

test/test_importer.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,7 @@ def test_import_link_arrives(self):
131131

132132
assert self.track_lib_path.exists()
133133
assert self.track_lib_path.is_symlink()
134-
self.assert_equal_path(
135-
self.track_lib_path.resolve(), self.track_import_path
136-
)
134+
assert self.track_lib_path.resolve() == self.track_import_path
137135

138136
@unittest.skipUnless(_common.HAVE_HARDLINK, "need hardlinks")
139137
def test_import_hardlink_arrives(self):
@@ -711,9 +709,7 @@ def test_asis_updated_without_copy_does_not_move_file(self):
711709
def test_outside_file_is_copied(self):
712710
config["import"]["copy"] = False
713711
self.importer.run()
714-
self.assert_equal_path(
715-
self.lib.items().get().path, self.import_media[0].path
716-
)
712+
assert self.lib.items().get().filepath == self.track_import_path
717713

718714
self.reimporter = self.setup_importer()
719715
self.reimporter.add_choice(importer.Action.APPLY)

test/test_ui.py

Lines changed: 32 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import subprocess
2222
import sys
2323
import unittest
24+
from pathlib import Path
2425
from unittest.mock import Mock, patch
2526

2627
import pytest
@@ -828,37 +829,29 @@ def setUp(self):
828829
del os.environ["BEETSDIR"]
829830

830831
# Also set APPDATA, the Windows equivalent of setting $HOME.
831-
appdata_dir = os.fsdecode(
832-
os.path.join(self.temp_dir, b"AppData", b"Roaming")
833-
)
832+
appdata_dir = self.temp_dir_path / "AppData" / "Roaming"
834833

835834
self._orig_cwd = os.getcwd()
836835
self.test_cmd = self._make_test_cmd()
837836
commands.default_commands.append(self.test_cmd)
838837

839838
# Default user configuration
840839
if platform.system() == "Windows":
841-
self.user_config_dir = os.fsencode(
842-
os.path.join(appdata_dir, "beets")
843-
)
840+
self.user_config_dir = appdata_dir / "beets"
844841
else:
845-
self.user_config_dir = os.path.join(
846-
self.temp_dir, b".config", b"beets"
847-
)
848-
os.makedirs(syspath(self.user_config_dir))
849-
self.user_config_path = os.path.join(
850-
self.user_config_dir, b"config.yaml"
851-
)
842+
self.user_config_dir = self.temp_dir_path / ".config" / "beets"
843+
self.user_config_dir.mkdir(parents=True, exist_ok=True)
844+
self.user_config_path = self.user_config_dir / "config.yaml"
852845

853846
# Custom BEETSDIR
854-
self.beetsdir = os.path.join(self.temp_dir, b"beetsdir")
855-
self.cli_config_path = os.path.join(
856-
os.fsdecode(self.temp_dir), "config.yaml"
857-
)
858-
os.makedirs(syspath(self.beetsdir))
847+
self.beetsdir = self.temp_dir_path / "beetsdir"
848+
self.beetsdir.mkdir(parents=True, exist_ok=True)
849+
850+
self.env_config_path = str(self.beetsdir / "config.yaml")
851+
self.cli_config_path = str(self.temp_dir_path / "config.yaml")
859852
self.env_patcher = patch(
860853
"os.environ",
861-
{"HOME": os.fsdecode(self.temp_dir), "APPDATA": appdata_dir},
854+
{"HOME": str(self.temp_dir_path), "APPDATA": str(appdata_dir)},
862855
)
863856
self.env_patcher.start()
864857

@@ -957,9 +950,8 @@ def test_cli_config_file_overwrites_user_defaults(self):
957950
assert config["anoption"].get() == "cli overwrite"
958951

959952
def test_cli_config_file_overwrites_beetsdir_defaults(self):
960-
os.environ["BEETSDIR"] = os.fsdecode(self.beetsdir)
961-
env_config_path = os.path.join(self.beetsdir, b"config.yaml")
962-
with open(env_config_path, "w") as file:
953+
os.environ["BEETSDIR"] = str(self.beetsdir)
954+
with open(self.env_config_path, "w") as file:
963955
file.write("anoption: value")
964956

965957
with open(self.cli_config_path, "w") as file:
@@ -1006,39 +998,25 @@ def test_cli_config_paths_resolve_relative_to_user_dir(self):
1006998
file.write("statefile: state")
1007999

10081000
self.run_command("--config", self.cli_config_path, "test", lib=None)
1009-
self.assert_equal_path(
1010-
util.bytestring_path(config["library"].as_filename()),
1011-
os.path.join(self.user_config_dir, b"beets.db"),
1012-
)
1013-
self.assert_equal_path(
1014-
util.bytestring_path(config["statefile"].as_filename()),
1015-
os.path.join(self.user_config_dir, b"state"),
1016-
)
1001+
assert config["library"].as_path() == self.user_config_dir / "beets.db"
1002+
assert config["statefile"].as_path() == self.user_config_dir / "state"
10171003

10181004
def test_cli_config_paths_resolve_relative_to_beetsdir(self):
1019-
os.environ["BEETSDIR"] = os.fsdecode(self.beetsdir)
1005+
os.environ["BEETSDIR"] = str(self.beetsdir)
10201006

10211007
with open(self.cli_config_path, "w") as file:
10221008
file.write("library: beets.db\n")
10231009
file.write("statefile: state")
10241010

10251011
self.run_command("--config", self.cli_config_path, "test", lib=None)
1026-
self.assert_equal_path(
1027-
util.bytestring_path(config["library"].as_filename()),
1028-
os.path.join(self.beetsdir, b"beets.db"),
1029-
)
1030-
self.assert_equal_path(
1031-
util.bytestring_path(config["statefile"].as_filename()),
1032-
os.path.join(self.beetsdir, b"state"),
1033-
)
1012+
assert config["library"].as_path() == self.beetsdir / "beets.db"
1013+
assert config["statefile"].as_path() == self.beetsdir / "state"
10341014

10351015
def test_command_line_option_relative_to_working_dir(self):
10361016
config.read()
10371017
os.chdir(syspath(self.temp_dir))
10381018
self.run_command("--library", "foo.db", "test", lib=None)
1039-
self.assert_equal_path(
1040-
config["library"].as_filename(), os.path.join(os.getcwd(), "foo.db")
1041-
)
1019+
assert config["library"].as_path() == Path.cwd() / "foo.db"
10421020

10431021
def test_cli_config_file_loads_plugin_commands(self):
10441022
with open(self.cli_config_path, "w") as file:
@@ -1050,24 +1028,23 @@ def test_cli_config_file_loads_plugin_commands(self):
10501028
self.unload_plugins()
10511029

10521030
def test_beetsdir_config(self):
1053-
os.environ["BEETSDIR"] = os.fsdecode(self.beetsdir)
1031+
os.environ["BEETSDIR"] = str(self.beetsdir)
10541032

1055-
env_config_path = os.path.join(self.beetsdir, b"config.yaml")
1056-
with open(env_config_path, "w") as file:
1033+
with open(self.env_config_path, "w") as file:
10571034
file.write("anoption: overwrite")
10581035

10591036
config.read()
10601037
assert config["anoption"].get() == "overwrite"
10611038

10621039
def test_beetsdir_points_to_file_error(self):
1063-
beetsdir = os.path.join(self.temp_dir, b"beetsfile")
1040+
beetsdir = str(self.temp_dir_path / "beetsfile")
10641041
open(beetsdir, "a").close()
1065-
os.environ["BEETSDIR"] = os.fsdecode(beetsdir)
1042+
os.environ["BEETSDIR"] = beetsdir
10661043
with pytest.raises(ConfigError):
10671044
self.run_command("test")
10681045

10691046
def test_beetsdir_config_does_not_load_default_user_config(self):
1070-
os.environ["BEETSDIR"] = os.fsdecode(self.beetsdir)
1047+
os.environ["BEETSDIR"] = str(self.beetsdir)
10711048

10721049
with open(self.user_config_path, "w") as file:
10731050
file.write("anoption: value")
@@ -1076,35 +1053,22 @@ def test_beetsdir_config_does_not_load_default_user_config(self):
10761053
assert not config["anoption"].exists()
10771054

10781055
def test_default_config_paths_resolve_relative_to_beetsdir(self):
1079-
os.environ["BEETSDIR"] = os.fsdecode(self.beetsdir)
1056+
os.environ["BEETSDIR"] = str(self.beetsdir)
10801057

10811058
config.read()
1082-
self.assert_equal_path(
1083-
util.bytestring_path(config["library"].as_filename()),
1084-
os.path.join(self.beetsdir, b"library.db"),
1085-
)
1086-
self.assert_equal_path(
1087-
util.bytestring_path(config["statefile"].as_filename()),
1088-
os.path.join(self.beetsdir, b"state.pickle"),
1089-
)
1059+
assert config["library"].as_path() == self.beetsdir / "library.db"
1060+
assert config["statefile"].as_path() == self.beetsdir / "state.pickle"
10901061

10911062
def test_beetsdir_config_paths_resolve_relative_to_beetsdir(self):
1092-
os.environ["BEETSDIR"] = os.fsdecode(self.beetsdir)
1063+
os.environ["BEETSDIR"] = str(self.beetsdir)
10931064

1094-
env_config_path = os.path.join(self.beetsdir, b"config.yaml")
1095-
with open(env_config_path, "w") as file:
1065+
with open(self.env_config_path, "w") as file:
10961066
file.write("library: beets.db\n")
10971067
file.write("statefile: state")
10981068

10991069
config.read()
1100-
self.assert_equal_path(
1101-
util.bytestring_path(config["library"].as_filename()),
1102-
os.path.join(self.beetsdir, b"beets.db"),
1103-
)
1104-
self.assert_equal_path(
1105-
util.bytestring_path(config["statefile"].as_filename()),
1106-
os.path.join(self.beetsdir, b"state"),
1107-
)
1070+
assert config["library"].as_path() == self.beetsdir / "beets.db"
1071+
assert config["statefile"].as_path() == self.beetsdir / "state"
11081072

11091073

11101074
class ShowModelChangeTest(IOMixin, unittest.TestCase):

0 commit comments

Comments
 (0)