Skip to content

Commit

Permalink
Fix path manipulations
Browse files Browse the repository at this point in the history
  • Loading branch information
Neraste committed Jan 28, 2025
1 parent eed7322 commit 63e8467
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/dakara_player/font.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def get_user_font_path_list(self):
def load(self):
"""Load the fonts."""
# ensure that the user font directory exists
self.FONT_DIR_USER.expanduser().mkdir_p()
self.FONT_DIR_USER.expanduser().mkdir(parents=True, exists_ok=True)

# get system and user font files
system_font_path_list = self.get_system_font_path_list()
Expand All @@ -173,7 +173,7 @@ def load_font(self, font_file_path, system_font_path_list, user_font_path_list):
of user fonts.
"""
# get font file name
font_file_name = font_file_path.basename()
font_file_name = font_file_path.name

# check if the font is installed at system level
if any(font_file_name in path for path in system_font_path_list):
Expand Down
8 changes: 5 additions & 3 deletions tests/unit/test_font.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,10 @@ def get_font_loader(self):
@patch.object(FontLoaderLinux, "load_font", autospec=True)
@patch.object(FontLoaderLinux, "get_font_path_iterator", autospec=True)
@patch.object(Path, "walkfiles", autospec=True)
@patch.object(Path, "mkdir_p", autospec=True)
@patch.object(Path, "mkdir", autospec=True)
def test_load(
self,
mocked_mkdir_p,
mocked_mkdir,
mocked_walkfiles,
mocked_get_font_path_iterator,
mocked_load_font,
Expand All @@ -149,7 +149,9 @@ def test_load(
font_loader.load()

# assert the call
mocked_mkdir_p.assert_called_once_with(self.user_directory / ".fonts")
mocked_mkdir.assert_called_once_with(
self.user_directory / ".fonts", parents=True, exists_ok=True
)
mocked_walkfiles.assert_has_calls(
[
call(Path("/") / "usr" / "share" / "fonts"),
Expand Down

0 comments on commit 63e8467

Please sign in to comment.