mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-07-12 09:56:14 +02:00
Add config overrides steps to pytest
This requires some patching around the config object, which now happens in every test. Co-authored-by: Micah Jerome Ellison <micah.jerome.ellison@gmail.com>
This commit is contained in:
parent
e16e3a1f62
commit
9cd2250a61
8 changed files with 138 additions and 39 deletions
|
@ -15,6 +15,7 @@ from jrnl.config import scope_config
|
|||
from .helpers import assert_equal_tags_ignoring_order
|
||||
from .helpers import does_directory_contain_files
|
||||
from .helpers import parse_should_or_should_not
|
||||
from .helpers import get_nested_val
|
||||
|
||||
|
||||
@then("we should get no error")
|
||||
|
@ -110,10 +111,10 @@ def should_see_the_message(text, cli_run):
|
|||
)
|
||||
@then(parse('the config {should_or_should_not} contain "{some_yaml}"'))
|
||||
@then(parse("the config {should_or_should_not} contain\n{some_yaml}"))
|
||||
def config_var(config_data, journal_name, should_or_should_not, some_yaml):
|
||||
def config_var_on_disk(config_on_disk, journal_name, should_or_should_not, some_yaml):
|
||||
we_should = parse_should_or_should_not(should_or_should_not)
|
||||
|
||||
actual = config_data
|
||||
actual = config_on_disk
|
||||
if journal_name:
|
||||
actual = actual["journals"][journal_name]
|
||||
|
||||
|
@ -121,6 +122,7 @@ def config_var(config_data, journal_name, should_or_should_not, some_yaml):
|
|||
|
||||
actual_slice = actual
|
||||
if type(actual) is dict:
|
||||
# `expected` objects formatted in yaml only compare one level deep
|
||||
actual_slice = {key: actual.get(key, None) for key in expected.keys()}
|
||||
|
||||
if we_should:
|
||||
|
@ -129,6 +131,40 @@ def config_var(config_data, journal_name, should_or_should_not, some_yaml):
|
|||
assert expected != actual_slice
|
||||
|
||||
|
||||
@then(
|
||||
parse(
|
||||
'the config in memory for journal "{journal_name}" {should_or_should_not} contain "{some_yaml}"'
|
||||
)
|
||||
)
|
||||
@then(
|
||||
parse(
|
||||
'the config in memory for journal "{journal_name}" {should_or_should_not} contain\n{some_yaml}'
|
||||
)
|
||||
)
|
||||
@then(parse('the config in memory {should_or_should_not} contain "{some_yaml}"'))
|
||||
@then(parse("the config in memory {should_or_should_not} contain\n{some_yaml}"))
|
||||
def config_var_in_memory(
|
||||
config_in_memory, journal_name, should_or_should_not, some_yaml
|
||||
):
|
||||
we_should = parse_should_or_should_not(should_or_should_not)
|
||||
|
||||
actual = config_in_memory["overrides"]
|
||||
if journal_name:
|
||||
actual = actual["journals"][journal_name]
|
||||
|
||||
expected = yaml.load(some_yaml, Loader=yaml.SafeLoader)
|
||||
|
||||
actual_slice = actual
|
||||
if type(actual) is dict:
|
||||
# `expected` objects formatted in yaml only compare one level deep
|
||||
actual_slice = {key: get_nested_val(actual, key) for key in expected.keys()}
|
||||
|
||||
if we_should:
|
||||
assert expected == actual_slice
|
||||
else:
|
||||
assert expected != actual_slice
|
||||
|
||||
|
||||
@then("we should be prompted for a password")
|
||||
def password_was_called(cli_run):
|
||||
assert cli_run["mocks"]["getpass"].called
|
||||
|
@ -145,15 +181,15 @@ def assert_dir_contains_files(file_list, cache_dir):
|
|||
|
||||
|
||||
@then(parse("the journal directory should contain\n{file_list}"))
|
||||
def journal_directory_should_contain(config_data, file_list):
|
||||
scoped_config = scope_config(config_data, "default")
|
||||
def journal_directory_should_contain(config_on_disk, file_list):
|
||||
scoped_config = scope_config(config_on_disk, "default")
|
||||
|
||||
assert does_directory_contain_files(file_list, scoped_config["journal"])
|
||||
|
||||
|
||||
@then(parse('journal "{journal_name}" should not exist'))
|
||||
def journal_directory_should_not_exist(config_data, journal_name):
|
||||
scoped_config = scope_config(config_data, journal_name)
|
||||
def journal_directory_should_not_exist(config_on_disk, journal_name):
|
||||
scoped_config = scope_config(config_on_disk, journal_name)
|
||||
|
||||
assert not does_directory_contain_files(
|
||||
scoped_config["journal"], "."
|
||||
|
@ -161,8 +197,8 @@ def journal_directory_should_not_exist(config_data, journal_name):
|
|||
|
||||
|
||||
@then(parse("the journal {should_or_should_not} exist"))
|
||||
def journal_should_not_exist(config_data, should_or_should_not):
|
||||
scoped_config = scope_config(config_data, "default")
|
||||
def journal_should_not_exist(config_on_disk, should_or_should_not):
|
||||
scoped_config = scope_config(config_on_disk, "default")
|
||||
expected_path = scoped_config["journal"]
|
||||
|
||||
contains_files = does_directory_contain_files(expected_path, ".")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue