Skip to content

Commit

Permalink
Speedwagon-497 Save System information to File exits with an unhandle…
Browse files Browse the repository at this point in the history
…d exception
  • Loading branch information
henryborchers committed Dec 7, 2023
1 parent 6c9a846 commit 3757256
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
4 changes: 4 additions & 0 deletions speedwagon/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ def emit(self, record: logging.LogRecord) -> None:


def get_desktop_path() -> str:
"""Locate user's desktop.
Throws FileNotFoundError if unsuccessful
"""
home = pathlib.Path.home()
desktop_path = home / "Desktop"
if os.path.exists(desktop_path):
Expand Down
31 changes: 31 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import os

import pytest

from speedwagon import utils
import pathlib


def test_get_desktop_path_finds_valid(monkeypatch):
fake_home = os.path.join("usr", "home")
monkeypatch.setattr(
pathlib.Path, "home", lambda: pathlib.Path(fake_home)
)

def exists(path):
return str(path) == os.path.join(fake_home, "Desktop")

monkeypatch.setattr(os.path, "exists", exists)
assert utils.get_desktop_path()


def test_get_desktop_path_not_found_throws(monkeypatch):
fake_home = os.path.join("usr", "home")

monkeypatch.setattr(
pathlib.Path, "home", lambda: pathlib.Path(fake_home)
)

monkeypatch.setattr(os.path, "exists", lambda _: False)
with pytest.raises(FileNotFoundError):
utils.get_desktop_path()

0 comments on commit 3757256

Please sign in to comment.