mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-07-03 15:16:12 +02:00
merge in develop
This commit is contained in:
commit
15b86cae97
30 changed files with 827 additions and 222 deletions
240
tests/bdd/features/change_time.feature
Normal file
240
tests/bdd/features/change_time.feature
Normal file
|
@ -0,0 +1,240 @@
|
|||
Feature: Change entry times in journal
|
||||
Scenario Outline: Change time flag changes single entry timestamp
|
||||
Given we use the config "<config_file>"
|
||||
And we use the password "test" if prompted
|
||||
When we run "jrnl -1"
|
||||
Then the output should contain "2020-09-24 09:14 The third entry finally"
|
||||
When we run "jrnl -1 --change-time '2022-04-23 10:30'" and enter
|
||||
Y
|
||||
When we run "jrnl -99 --short"
|
||||
Then the output should be
|
||||
2020-08-29 11:11 Entry the first.
|
||||
2020-08-31 14:32 A second entry in what I hope to be a long series.
|
||||
2022-04-23 10:30 The third entry finally after weeks without writing.
|
||||
|
||||
Examples: Configs
|
||||
| config_file |
|
||||
| basic_onefile.yaml |
|
||||
| basic_encrypted.yaml |
|
||||
| basic_folder.yaml |
|
||||
# | basic_dayone.yaml | @todo
|
||||
|
||||
Scenario Outline: Change flag changes prompted entries
|
||||
Given we use the config "<config_file>"
|
||||
And we use the password "test" if prompted
|
||||
When we run "jrnl -1"
|
||||
Then the output should contain "2020-09-24 09:14 The third entry finally"
|
||||
When we run "jrnl --change-time '2022-04-23 10:30'" and enter
|
||||
Y
|
||||
N
|
||||
Y
|
||||
When we run "jrnl -99 --short"
|
||||
Then the output should be
|
||||
2020-08-31 14:32 A second entry in what I hope to be a long series.
|
||||
2022-04-23 10:30 Entry the first.
|
||||
2022-04-23 10:30 The third entry finally after weeks without writing.
|
||||
|
||||
Examples: Configs
|
||||
| config_file |
|
||||
| basic_onefile.yaml |
|
||||
| basic_encrypted.yaml |
|
||||
| basic_folder.yaml |
|
||||
# | basic_dayone.yaml | @todo
|
||||
|
||||
|
||||
Scenario Outline: Change time flag with nonsense input changes nothing
|
||||
Given we use the config "<config_file>"
|
||||
When we run "jrnl --change-time now asdfasdf"
|
||||
Then the output should contain "No entries to modify"
|
||||
When we run "jrnl -99 --short"
|
||||
Then the output should be
|
||||
2020-08-29 11:11 Entry the first.
|
||||
2020-08-31 14:32 A second entry in what I hope to be a long series.
|
||||
2020-09-24 09:14 The third entry finally after weeks without writing.
|
||||
|
||||
Examples: Configs
|
||||
| config_file |
|
||||
| basic_onefile.yaml |
|
||||
| basic_folder.yaml |
|
||||
| basic_dayone.yaml |
|
||||
|
||||
|
||||
Scenario Outline: Change time flag with tag only changes tagged entries
|
||||
Given we use the config "<config_file>"
|
||||
When we run "jrnl --change-time '2022-04-23 10:30' @ipsum" and enter
|
||||
Y
|
||||
When we run "jrnl -99 --short"
|
||||
Then the output should be
|
||||
2020-08-31 14:32 A second entry in what I hope to be a long series.
|
||||
2020-09-24 09:14 The third entry finally after weeks without writing.
|
||||
2022-04-23 10:30 Entry the first.
|
||||
|
||||
Examples: Configs
|
||||
| config_file |
|
||||
| basic_onefile.yaml |
|
||||
| basic_folder.yaml |
|
||||
# | basic_dayone.yaml | @todo
|
||||
|
||||
|
||||
Scenario Outline: Change time flag with multiple tags changes all entries matching any of the tags
|
||||
Given we use the config "<config_file>"
|
||||
When we run "jrnl --change-time '2022-04-23 10:30' @ipsum @tagthree" and enter
|
||||
Y
|
||||
Y
|
||||
When we run "jrnl -99 --short"
|
||||
Then the output should be
|
||||
2020-08-31 14:32 A second entry in what I hope to be a long series.
|
||||
2022-04-23 10:30 Entry the first.
|
||||
2022-04-23 10:30 The third entry finally after weeks without writing.
|
||||
|
||||
Examples: Configs
|
||||
| config_file |
|
||||
| basic_onefile.yaml |
|
||||
| basic_folder.yaml |
|
||||
# | basic_dayone.yaml | @todo
|
||||
|
||||
|
||||
Scenario Outline: Change time flag with -and changes boolean AND of tagged entries
|
||||
Given we use the config "<config_file>"
|
||||
When we run "jrnl --change-time '2022-04-23 10:30' -and @tagone @tagtwo" and enter
|
||||
Y
|
||||
When we run "jrnl -99 --short"
|
||||
Then the output should be
|
||||
2020-08-31 14:32 A second entry in what I hope to be a long series.
|
||||
2020-09-24 09:14 The third entry finally after weeks without writing.
|
||||
2022-04-23 10:30 Entry the first.
|
||||
|
||||
Examples: Configs
|
||||
| config_file |
|
||||
| basic_onefile.yaml |
|
||||
| basic_folder.yaml |
|
||||
# | basic_dayone.yaml | @todo
|
||||
|
||||
|
||||
Scenario Outline: Change time flag with -not does not change entries from given tag
|
||||
Given we use the config "<config_file>"
|
||||
When we run "jrnl --change-time '2022-04-23 10:30' @tagone -not @ipsum" and enter
|
||||
Y
|
||||
When we run "jrnl -99 --short"
|
||||
Then the output should be
|
||||
2020-08-29 11:11 Entry the first.
|
||||
2020-08-31 14:32 A second entry in what I hope to be a long series.
|
||||
2022-04-23 10:30 The third entry finally after weeks without writing.
|
||||
|
||||
Examples: Configs
|
||||
| config_file |
|
||||
| basic_onefile.yaml |
|
||||
| basic_folder.yaml |
|
||||
# | basic_dayone.yaml | @todo
|
||||
|
||||
|
||||
Scenario Outline: Change time flag with -from search operator only changes entries since that date
|
||||
Given we use the config "<config_file>"
|
||||
When we run "jrnl --change-time '2022-04-23 10:30' -from 2020-09-01" and enter
|
||||
Y
|
||||
When we run "jrnl -99 --short"
|
||||
Then the output should be
|
||||
2020-08-29 11:11 Entry the first.
|
||||
2020-08-31 14:32 A second entry in what I hope to be a long series.
|
||||
2022-04-23 10:30 The third entry finally after weeks without writing.
|
||||
|
||||
Examples: Configs
|
||||
| config_file |
|
||||
| basic_onefile.yaml |
|
||||
| basic_folder.yaml |
|
||||
# | basic_dayone.yaml | @todo
|
||||
|
||||
|
||||
Scenario Outline: Change time flag with -to only changes entries up to specified date
|
||||
Given we use the config "<config_file>"
|
||||
When we run "jrnl --change-time '2022-04-23 10:30' -to 2020-08-31" and enter
|
||||
Y
|
||||
Y
|
||||
When we run "jrnl -99 --short"
|
||||
Then the output should be
|
||||
2020-09-24 09:14 The third entry finally after weeks without writing.
|
||||
2022-04-23 10:30 Entry the first.
|
||||
2022-04-23 10:30 A second entry in what I hope to be a long series.
|
||||
|
||||
Examples: Configs
|
||||
| config_file |
|
||||
| basic_onefile.yaml |
|
||||
| basic_folder.yaml |
|
||||
# | basic_dayone.yaml | @todo
|
||||
|
||||
|
||||
Scenario Outline: Change time flag with -starred only changes starred entries
|
||||
Given we use the config "<config_file>"
|
||||
When we run "jrnl --change-time '2022-04-23 10:30' -starred" and enter
|
||||
Y
|
||||
When we run "jrnl -99 --short"
|
||||
Then the output should be
|
||||
2020-08-29 11:11 Entry the first.
|
||||
2020-09-24 09:14 The third entry finally after weeks without writing.
|
||||
2022-04-23 10:30 A second entry in what I hope to be a long series.
|
||||
|
||||
Examples: Configs
|
||||
| config_file |
|
||||
| basic_onefile.yaml |
|
||||
| basic_folder.yaml |
|
||||
# | basic_dayone.yaml | @todo
|
||||
|
||||
|
||||
Scenario Outline: Change time flag with -contains only changes entries containing expression
|
||||
Given we use the config "<config_file>"
|
||||
When we run "jrnl --change-time '2022-04-23 10:30' -contains dignissim" and enter
|
||||
Y
|
||||
When we run "jrnl -99 --short"
|
||||
Then the output should be
|
||||
2020-08-31 14:32 A second entry in what I hope to be a long series.
|
||||
2020-09-24 09:14 The third entry finally after weeks without writing.
|
||||
2022-04-23 10:30 Entry the first.
|
||||
|
||||
Examples: Configs
|
||||
| config_file |
|
||||
| basic_onefile.yaml |
|
||||
| basic_folder.yaml |
|
||||
# | basic_dayone.yaml | @todo
|
||||
|
||||
|
||||
Scenario Outline: Change time flag with no enties specified changes nothing
|
||||
Given we use the config "<config_file>"
|
||||
And we use the password "test" if prompted
|
||||
When we run "jrnl --change-time" and enter
|
||||
N
|
||||
N
|
||||
N
|
||||
When we run "jrnl -99 --short"
|
||||
Then the output should be
|
||||
2020-08-29 11:11 Entry the first.
|
||||
2020-08-31 14:32 A second entry in what I hope to be a long series.
|
||||
2020-09-24 09:14 The third entry finally after weeks without writing.
|
||||
|
||||
Examples: Configs
|
||||
| config_file |
|
||||
| basic_onefile.yaml |
|
||||
| basic_folder.yaml |
|
||||
| basic_dayone.yaml |
|
||||
|
||||
|
||||
Scenario Outline: --change-time with --edit modifies selected entries
|
||||
Given we use the config "<config_file>"
|
||||
And we write nothing to the editor if opened
|
||||
And we use the password "test" if prompted
|
||||
When we run "jrnl --change-time '2022-04-23 10:30' --edit" and enter
|
||||
Y
|
||||
N
|
||||
Y
|
||||
Then the error output should contain "No entry to save"
|
||||
And the editor should have been called
|
||||
When we run "jrnl -99 --short"
|
||||
Then the output should be
|
||||
2020-08-31 14:32 A second entry in what I hope to be a long series.
|
||||
2022-04-23 10:30 Entry the first.
|
||||
2022-04-23 10:30 The third entry finally after weeks without writing.
|
||||
|
||||
Examples: Configs
|
||||
| config_file |
|
||||
| basic_onefile.yaml |
|
||||
| basic_folder.yaml |
|
||||
# | basic_dayone.yaml | @todo
|
|
@ -24,10 +24,11 @@ Feature: Encrypting and decrypting journals
|
|||
2013-06-10 15:40 Life is good.
|
||||
|
||||
|
||||
@todo
|
||||
Scenario: Trying to encrypt an already encrypted journal
|
||||
# This should warn the user that the journal is already encrypted
|
||||
|
||||
Given we use the config "encrypted.yaml"
|
||||
When we run "jrnl --encrypt" and enter "bad doggie no biscuit"
|
||||
Then the output should contain "already encrypted. Create a new password."
|
||||
Then we should be prompted for a password
|
||||
|
||||
Scenario Outline: Encrypting a journal
|
||||
Given we use the config "simple.yaml"
|
||||
|
|
|
@ -30,6 +30,24 @@ Feature: Journals iteracting with the file system in a way that users can see
|
|||
Then the journal should exist
|
||||
When we run "jrnl -99 --short"
|
||||
Then the output should contain "This is a new entry in my journal"
|
||||
|
||||
@on_posix
|
||||
Scenario: If the directory for a Folder journal ending in a slash ('/') doesn't exist, then it should be created
|
||||
Given we use the config "missing_directory.yaml"
|
||||
Then the journal "endslash" directory should not exist
|
||||
When we run "jrnl endslash This is a new entry in my journal"
|
||||
Then the journal "endslash" directory should exist
|
||||
When we run "jrnl endslash -1"
|
||||
Then the output should contain "This is a new entry in my journal"
|
||||
|
||||
@on_win
|
||||
Scenario: If the directory for a Folder journal ending in a backslash ('\') doesn't exist, then it should be created
|
||||
Given we use the config "missing_directory.yaml"
|
||||
Then the journal "endbackslash" directory should not exist
|
||||
When we run "jrnl endbackslash This is a new entry in my journal"
|
||||
Then the journal "endbackslash" directory should exist
|
||||
When we run "jrnl endbackslash -1"
|
||||
Then the output should contain "This is a new entry in my journal"
|
||||
|
||||
Scenario: Creating journal with relative path should update to absolute path
|
||||
Given we use no config
|
||||
|
|
|
@ -560,3 +560,19 @@ Feature: Custom formats
|
|||
| basic_encrypted.yaml |
|
||||
| basic_folder.yaml |
|
||||
| basic_dayone.yaml |
|
||||
|
||||
|
||||
Scenario Outline: display_format short and pretty do not crash if specified as config values
|
||||
Given we use the config "<config_file>"
|
||||
And we use the password "test" if prompted
|
||||
When we run "jrnl --config-override display_format short -1"
|
||||
Then we should get no error
|
||||
When we run "jrnl --config-override display_format pretty -1"
|
||||
Then we should get no error
|
||||
|
||||
Examples: configs
|
||||
| config_file |
|
||||
| basic_onefile.yaml |
|
||||
| basic_encrypted.yaml |
|
||||
| basic_folder.yaml |
|
||||
| basic_dayone.yaml |
|
||||
|
|
|
@ -183,6 +183,19 @@ Feature: Searching in a journal
|
|||
| basic_folder.yaml |
|
||||
| basic_dayone.yaml |
|
||||
|
||||
Scenario Outline: Using -not should exclude all entries with that tag
|
||||
# https://github.com/jrnl-org/jrnl/issues/1472
|
||||
Given we use the config "<config_file>"
|
||||
When we run "jrnl -not @tagtwo"
|
||||
Then the output should not contain "@tagtwo"
|
||||
And the editor should not have been called
|
||||
|
||||
Examples: configs
|
||||
| config_file |
|
||||
| basic_onefile.yaml |
|
||||
| basic_folder.yaml |
|
||||
| basic_dayone.yaml |
|
||||
|
||||
Scenario: DayOne tag searching should work with tags containing a mixture of upper and lower case.
|
||||
# https://github.com/jrnl-org/jrnl/issues/354
|
||||
Given we use the config "dayone.yaml"
|
||||
|
|
|
@ -5,6 +5,7 @@ scenarios("features/config_file.feature")
|
|||
scenarios("features/core.feature")
|
||||
scenarios("features/datetime.feature")
|
||||
scenarios("features/delete.feature")
|
||||
scenarios("features/change_time.feature")
|
||||
scenarios("features/encrypt.feature")
|
||||
scenarios("features/file_storage.feature")
|
||||
scenarios("features/format.feature")
|
||||
|
|
|
@ -2,8 +2,10 @@
|
|||
# License: https://www.gnu.org/licenses/gpl-3.0.html
|
||||
|
||||
from pytest import mark
|
||||
from pytest import skip
|
||||
|
||||
from jrnl.os_compat import on_windows
|
||||
from jrnl.os_compat import on_posix
|
||||
|
||||
|
||||
pytest_plugins = [
|
||||
|
@ -15,11 +17,39 @@ pytest_plugins = [
|
|||
|
||||
|
||||
def pytest_bdd_apply_tag(tag, function):
|
||||
# skip markers
|
||||
if tag == "skip_win":
|
||||
marker = mark.skipif(on_windows(), reason="Skip test on Windows")
|
||||
elif tag == "skip_posix":
|
||||
marker = mark.skipif(on_posix(), reason="Skip test on Mac/Linux")
|
||||
|
||||
# only on OS markers
|
||||
elif tag == "on_win":
|
||||
marker = mark.skipif(not on_windows(), reason="Skip test not on Windows")
|
||||
elif tag == "on_posix":
|
||||
marker = mark.skipif(not on_posix(), reason="Skip test not on Mac/Linux")
|
||||
else:
|
||||
# Fall back to pytest-bdd's default behavior
|
||||
return None
|
||||
|
||||
marker(function)
|
||||
return True
|
||||
|
||||
|
||||
def pytest_runtest_setup(item):
|
||||
markers = [mark.name for mark in item.iter_markers()]
|
||||
|
||||
on_win = on_windows()
|
||||
on_nix = on_posix()
|
||||
|
||||
if "skip_win" in markers and on_win:
|
||||
skip("Skip test on Windows")
|
||||
|
||||
if "skip_posix" in markers and on_nix:
|
||||
skip("Skip test on Mac/Linux")
|
||||
|
||||
if "on_win" in markers and not on_win:
|
||||
skip("Skip test not on Windows")
|
||||
|
||||
if "on_posix" in markers and not on_nix:
|
||||
skip("Skip test not on Mac/Linux")
|
||||
|
|
|
@ -5,6 +5,8 @@ encrypt: false
|
|||
highlight: true
|
||||
journals:
|
||||
default: features/journals/missing_directory/simple.journal
|
||||
endslash: features/journals/missing_folder/
|
||||
endbackslash: features\journals\missing_folder\
|
||||
linewrap: 80
|
||||
tagsymbols: "@"
|
||||
template: false
|
||||
|
|
|
@ -213,6 +213,16 @@ def journal_should_not_exist(config_on_disk, should_or_should_not):
|
|||
)
|
||||
|
||||
|
||||
@then(parse('the journal "{journal_name}" directory {should_or_should_not} exist'))
|
||||
def directory_should_not_exist(config_on_disk, should_or_should_not, journal_name):
|
||||
scoped_config = scope_config(config_on_disk, journal_name)
|
||||
expected_path = scoped_config["journal"]
|
||||
we_should = parse_should_or_should_not(should_or_should_not)
|
||||
dir_exists = os.path.isdir(expected_path)
|
||||
|
||||
assert dir_exists == we_should
|
||||
|
||||
|
||||
@then(parse('the content of file "{file_path}" in the cache should be\n{file_content}'))
|
||||
def content_of_file_should_be(file_path, file_content, cache_dir):
|
||||
assert cache_dir["exists"]
|
||||
|
|
|
@ -1,25 +0,0 @@
|
|||
import argparse
|
||||
from unittest import mock
|
||||
|
||||
import pytest
|
||||
|
||||
import jrnl
|
||||
from jrnl.jrnl import _display_search_results
|
||||
|
||||
|
||||
# fmt: off
|
||||
# see: https://github.com/psf/black/issues/664
|
||||
@pytest.mark.parametrize("export_format", [ "pretty", "short","markdown"])
|
||||
#fmt: on
|
||||
@mock.patch.object(argparse, "Namespace", return_value={"export": "markdown", "filename": "irrele.vant"})
|
||||
def test_export_format(mock_args, export_format):
|
||||
|
||||
test_journal = jrnl.Journal.Journal
|
||||
mock_args.export = export_format
|
||||
#fmt: off
|
||||
# see: https://github.com/psf/black/issues/664
|
||||
with mock.patch("builtins.print") as mock_spy_print, \
|
||||
mock.patch('jrnl.Journal.Journal.pprint') as mock_pprint:
|
||||
_display_search_results(mock_args, test_journal)
|
||||
mock_spy_print.assert_called_once_with(mock_pprint())
|
||||
#fmt: on
|
48
tests/unit/test_jrnl.py
Normal file
48
tests/unit/test_jrnl.py
Normal file
|
@ -0,0 +1,48 @@
|
|||
from unittest import mock
|
||||
|
||||
import pytest
|
||||
|
||||
import random
|
||||
import string
|
||||
import jrnl
|
||||
from jrnl.jrnl import _display_search_results
|
||||
from jrnl.args import parse_args
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def random_string():
|
||||
return "".join(random.choices(string.ascii_uppercase + string.digits, k=25))
|
||||
|
||||
|
||||
@pytest.mark.parametrize("export_format", ["pretty", "short"])
|
||||
@mock.patch("builtins.print")
|
||||
@mock.patch("jrnl.Journal.Journal.pprint")
|
||||
def test_display_search_results_pretty_short(mock_pprint, mock_print, export_format):
|
||||
mock_args = parse_args(["--format", export_format])
|
||||
test_journal = mock.Mock(wraps=jrnl.Journal.Journal)
|
||||
|
||||
_display_search_results(mock_args, test_journal)
|
||||
|
||||
mock_print.assert_called_once_with(mock_pprint.return_value)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"export_format", ["markdown", "json", "xml", "yaml", "fancy", "dates"]
|
||||
)
|
||||
@mock.patch("jrnl.plugins.get_exporter")
|
||||
@mock.patch("builtins.print")
|
||||
def test_display_search_results_builtin_plugins(
|
||||
mock_print, mock_exporter, export_format, random_string
|
||||
):
|
||||
test_filename = random_string
|
||||
mock_args = parse_args(["--format", export_format, "--file", test_filename])
|
||||
|
||||
test_journal = mock.Mock(wraps=jrnl.Journal.Journal)
|
||||
mock_export = mock.Mock()
|
||||
mock_exporter.return_value.export = mock_export
|
||||
|
||||
_display_search_results(mock_args, test_journal)
|
||||
|
||||
mock_exporter.assert_called_once_with(export_format)
|
||||
mock_export.assert_called_once_with(test_journal, test_filename)
|
||||
mock_print.assert_called_once_with(mock_export.return_value)
|
|
@ -17,6 +17,7 @@ def expected_args(**kwargs):
|
|||
"contains": None,
|
||||
"debug": False,
|
||||
"delete": False,
|
||||
"change_time": None,
|
||||
"edit": False,
|
||||
"end_date": None,
|
||||
"today_in_history": False,
|
||||
|
@ -58,6 +59,13 @@ def test_delete_alone():
|
|||
assert cli_as_dict("--delete") == expected_args(delete=True)
|
||||
|
||||
|
||||
def test_change_time_alone():
|
||||
assert cli_as_dict("--change-time") == expected_args(change_time="now")
|
||||
assert cli_as_dict("--change-time yesterday") == expected_args(
|
||||
change_time="yesterday"
|
||||
)
|
||||
|
||||
|
||||
def test_diagnostic_alone():
|
||||
from jrnl.commands import preconfig_diagnostic
|
||||
|
||||
|
|
103
tests/unit/test_path.py
Normal file
103
tests/unit/test_path.py
Normal file
|
@ -0,0 +1,103 @@
|
|||
import pytest
|
||||
import random
|
||||
import string
|
||||
|
||||
from os import getenv
|
||||
from unittest.mock import patch
|
||||
|
||||
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 random_test_var(monkeypatch):
|
||||
name = f"JRNL_TEST_{''.join(random.sample(string.ascii_uppercase, 10))}"
|
||||
val = "".join(random.sample(string.ascii_lowercase, 25))
|
||||
monkeypatch.setenv(name, val)
|
||||
return (name, val)
|
||||
|
||||
|
||||
def test_home_dir(home_dir_str):
|
||||
assert home_dir() == home_dir_str
|
||||
|
||||
|
||||
@pytest.mark.on_posix
|
||||
@pytest.mark.parametrize(
|
||||
"path",
|
||||
["~"],
|
||||
)
|
||||
def test_expand_path_actually_expands_mac_linux(path):
|
||||
# makes sure that path isn't being returns as-is
|
||||
assert expand_path(path) != path
|
||||
|
||||
|
||||
@pytest.mark.on_win
|
||||
@pytest.mark.parametrize(
|
||||
"path",
|
||||
["~", "%USERPROFILE%"],
|
||||
)
|
||||
def test_expand_path_actually_expands_windows(path):
|
||||
# makes sure that path isn't being returns as-is
|
||||
assert expand_path(path) != path
|
||||
|
||||
|
||||
@pytest.mark.on_posix
|
||||
@pytest.mark.parametrize(
|
||||
"paths",
|
||||
[
|
||||
["~", "HOME"],
|
||||
],
|
||||
)
|
||||
def test_expand_path_expands_into_correct_value_mac_linux(paths):
|
||||
input_path, expected_path = paths[0], paths[1]
|
||||
assert expand_path(input_path) == getenv(expected_path)
|
||||
|
||||
|
||||
@pytest.mark.on_win
|
||||
@pytest.mark.parametrize(
|
||||
"paths",
|
||||
[
|
||||
["~", "USERPROFILE"],
|
||||
["%USERPROFILE%", "USERPROFILE"],
|
||||
],
|
||||
)
|
||||
def test_expand_path_expands_into_correct_value_windows(paths):
|
||||
input_path, expected_path = paths[0], paths[1]
|
||||
assert expand_path(input_path) == getenv(expected_path)
|
||||
|
||||
|
||||
@pytest.mark.on_posix
|
||||
@pytest.mark.parametrize("_", range(25))
|
||||
def test_expand_path_expands_into_random_env_value_mac_linux(_, random_test_var):
|
||||
var_name, var_value = random_test_var[0], random_test_var[1]
|
||||
assert expand_path(var_name) == var_name
|
||||
assert expand_path(f"${var_name}") == var_value # mac & linux
|
||||
assert expand_path(f"${var_name}") == getenv(var_name)
|
||||
|
||||
|
||||
@pytest.mark.on_win
|
||||
@pytest.mark.parametrize("_", range(25))
|
||||
def test_expand_path_expands_into_random_env_value_windows(_, random_test_var):
|
||||
var_name, var_value = random_test_var[0], random_test_var[1]
|
||||
assert expand_path(var_name) == var_name
|
||||
assert expand_path(f"%{var_name}%") == var_value # windows
|
||||
assert expand_path(f"%{var_name}%") == getenv(var_name)
|
||||
|
||||
|
||||
@patch("jrnl.path.expand_path")
|
||||
@patch("os.path.abspath")
|
||||
def test_absolute_path(mock_abspath, mock_expand_path):
|
||||
test_val = "test_value"
|
||||
|
||||
assert absolute_path(test_val) == mock_abspath.return_value
|
||||
mock_expand_path.assert_called_with(test_val)
|
||||
mock_abspath.assert_called_with(mock_expand_path.return_value)
|
Loading…
Add table
Add a link
Reference in a new issue