-
-
Notifications
You must be signed in to change notification settings - Fork 519
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactored path expansion calls into a new path.py file
This also fixed bugs with relative journal and template paths.
- Loading branch information
1 parent
e6ed64a
commit 7a86bbc
Showing
7 changed files
with
91 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import os.path | ||
|
||
|
||
def home_dir(): | ||
return os.path.expanduser("~") | ||
|
||
|
||
def expand_path(path): | ||
return os.path.expanduser(os.path.expandvars(path)) | ||
|
||
|
||
def absolute_path(path): | ||
return os.path.abspath(expand_path(path)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import pytest | ||
from unittest import mock | ||
from os import path | ||
|
||
from jrnl.path import home_dir | ||
from jrnl.path import expand_path | ||
from jrnl.path import absolute_path | ||
|
||
|
||
@pytest.fixture | ||
def home_dir_str(monkeypatch): | ||
username = "username" | ||
monkeypatch.setenv("USERPROFILE", username) # for windows | ||
monkeypatch.setenv("HOME", username) # for *nix | ||
return username | ||
|
||
|
||
@pytest.fixture | ||
def expand_path_test_data(monkeypatch, home_dir_str): | ||
monkeypatch.setenv("VAR", "var") | ||
return [ | ||
["~", home_dir_str], | ||
[path.join("~", "${VAR}", "$VAR"), path.join(home_dir_str, "var", "var")], | ||
] | ||
|
||
|
||
def cwd(): | ||
"""Used to mock os.getcwd""" | ||
return "currentdir" | ||
|
||
|
||
@pytest.fixture | ||
def absolute_path_test_data(expand_path_test_data): | ||
test_data = [ | ||
[".", cwd()], | ||
[path.join(".", "dir"), path.join(cwd(), "dir")], | ||
[".dot_file", path.join(cwd(), ".dot_file")], | ||
] | ||
for inpath, outpath in expand_path_test_data: | ||
test_data.append([inpath, path.join(cwd(), outpath)]) | ||
return test_data | ||
|
||
|
||
def test_home_dir(home_dir_str): | ||
assert home_dir() == home_dir_str | ||
|
||
|
||
def test_expand_path(expand_path_test_data): | ||
for inpath, outpath in expand_path_test_data: | ||
assert expand_path(inpath) == outpath | ||
|
||
|
||
def test_absolute_path(absolute_path_test_data): | ||
with mock.patch("os.getcwd", cwd): | ||
for inpath, outpath in absolute_path_test_data: | ||
assert absolute_path(inpath) == outpath |