Skip to content

Commit

Permalink
Test xdg_data_home function
Browse files Browse the repository at this point in the history
  • Loading branch information
JakobGM committed May 14, 2018
1 parent e61811c commit 6ad9764
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
2 changes: 1 addition & 1 deletion astrality/executed_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def xdg_data_home(application: str) -> Path:
config_directory=Path('/'),
)
application_data_home = xdg_data_home / application
application_data_home.mkdir(exist_ok=True)
application_data_home.mkdir(parents=True, exist_ok=True)
return application_data_home


Expand Down
24 changes: 23 additions & 1 deletion astrality/tests/test_executed_actions.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
"""Tests for astrality.executed_actions.ExecutedActions."""

import os
from pathlib import Path
import logging

from astrality.executed_actions import ExecutedActions
from astrality.executed_actions import ExecutedActions, xdg_data_home


def test_that_executed_action_path_is_monkeypatched_in_all_files():
Expand All @@ -15,6 +17,26 @@ def test_that_executed_action_path_is_monkeypatched_in_all_files():
assert 'test' in path.parents[3].name


def test_xdg_data_home_default_location():
"""Default location for XDG_DATA_HOME should be respected."""
default_dir = xdg_data_home('astrality')
assert default_dir == Path('~/.local/share/astrality').expanduser()
assert default_dir.is_dir()


def test_xdg_data_home_using_environment_variable(monkeypatch, tmpdir):
"""XDG_DATA_HOME environment variables should be respected."""
custom_data_home = Path(tmpdir, 'data')
monkeypatch.setattr(
os,
'environ',
{'XDG_DATA_HOME': str(custom_data_home)},
)
data_home = xdg_data_home('astrality')
assert data_home == custom_data_home / 'astrality'
assert data_home.is_dir()


def test_that_actions_are_saved_to_file(caplog):
"""Saved actions should be persisted properly."""
action_option = {'shell': 'echo setup'}
Expand Down

0 comments on commit 6ad9764

Please sign in to comment.