Skip to content

Commit da5ec00

Browse files
authored
[Test] Fix path tests on windows (#5803)
## Description Fixes #5802. Today, tests fail on most Windows machines because we hard-code `D:` as the root drive, but most machines use `C:`. This change uses the same normalization function in the test assertion to ensure the drives match. ## To Do - [ ] ~~Documentation.~~ - [x] Changelog. - [x] Tests. (this is a tests change) ## What changed? * Updated tests to generate the drive name via normalization, instead of hard-coding `D:`. * Updated the `Item::destination()` method to document the `relative_to_libdir` param. ## How tested? * [x] Tests pass locally.
1 parent 60f24cd commit da5ec00

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

beets/library.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1084,7 +1084,9 @@ def destination(
10841084
(i.e., where the file ought to be).
10851085
10861086
The path is returned as a bytestring. ``basedir`` can override the
1087-
library's base directory for the destination.
1087+
library's base directory for the destination. If ``relative_to_libdir``
1088+
is true, returns just the fragment of the path underneath the library
1089+
base directory.
10881090
"""
10891091
db = self._check_db()
10901092
basedir = basedir or db.directory

docs/changelog.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ Bug fixes:
2828
* :doc:`plugins/musicbrainz`: fix regression where user configured
2929
``extra_tags`` have been read incorrectly.
3030
:bug:`5788`
31+
* tests: Fix library tests failing on Windows when run from outside ``D:/``.
32+
:bug:`5802`
3133

3234
For packagers:
3335

test/test_library.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
from beets.test import _common
3535
from beets.test._common import item
3636
from beets.test.helper import BeetsTestCase, ItemInDBTestCase
37-
from beets.util import as_string, bytestring_path, syspath
37+
from beets.util import as_string, bytestring_path, normpath, syspath
3838

3939
# Shortcut to path normalization.
4040
np = util.normpath
@@ -553,16 +553,22 @@ def test_both_artist_and_albumartist_empty(self):
553553
class PathFormattingMixin:
554554
"""Utilities for testing path formatting."""
555555

556+
i: beets.library.Item
557+
lib: beets.library.Library
558+
556559
def _setf(self, fmt):
557560
self.lib.path_formats.insert(0, ("default", fmt))
558561

559562
def _assert_dest(self, dest, i=None):
560563
if i is None:
561564
i = self.i
562565

566+
# Handle paths on Windows.
563567
if os.path.sep != "/":
564568
dest = dest.replace(b"/", os.path.sep.encode())
565-
dest = b"D:" + dest
569+
570+
# Paths are normalized based on the CWD.
571+
dest = normpath(dest)
566572

567573
actual = i.destination()
568574

0 commit comments

Comments
 (0)