mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-20 04:58:32 +02:00
update unittests for new syntax
This commit is contained in:
parent
3ea043899a
commit
432e76698e
2 changed files with 30 additions and 11 deletions
|
@ -1,3 +1,4 @@
|
||||||
|
import shlex
|
||||||
import pytest
|
import pytest
|
||||||
import mock
|
import mock
|
||||||
|
|
||||||
|
@ -43,7 +44,7 @@ def test_override_configured_editor(
|
||||||
mock_load_or_install.return_value = minimal_config
|
mock_load_or_install.return_value = minimal_config
|
||||||
mock_isatty.return_value = True
|
mock_isatty.return_value = True
|
||||||
|
|
||||||
cli_args = ["--config-override", '{"editor": "nano"}']
|
cli_args = shlex.split('--config-override editor:"nano"')
|
||||||
parser = parse_args(cli_args)
|
parser = parse_args(cli_args)
|
||||||
assert parser.config_override.__len__() == 1
|
assert parser.config_override.__len__() == 1
|
||||||
assert "editor" in parser.config_override.keys()
|
assert "editor" in parser.config_override.keys()
|
||||||
|
@ -84,7 +85,7 @@ def test_override_configured_colors(
|
||||||
):
|
):
|
||||||
mock_load_or_install.return_value = minimal_config
|
mock_load_or_install.return_value = minimal_config
|
||||||
|
|
||||||
cli_args = ["--config-override", '{"colors.body": "blue"}']
|
cli_args = shlex.split('--config-override colors.body:blue')
|
||||||
parser = parse_args(cli_args)
|
parser = parse_args(cli_args)
|
||||||
assert "colors.body" in parser.config_override.keys()
|
assert "colors.body" in parser.config_override.keys()
|
||||||
with mock.patch.object(
|
with mock.patch.object(
|
||||||
|
|
|
@ -36,7 +36,7 @@ def expected_args(**kwargs):
|
||||||
"strict": False,
|
"strict": False,
|
||||||
"tags": False,
|
"tags": False,
|
||||||
"text": [],
|
"text": [],
|
||||||
"config_override": {},
|
"config_override": None,
|
||||||
}
|
}
|
||||||
return {**default_args, **kwargs}
|
return {**default_args, **kwargs}
|
||||||
|
|
||||||
|
@ -206,28 +206,46 @@ def test_version_alone():
|
||||||
|
|
||||||
assert cli_as_dict("--version") == expected_args(preconfig_cmd=preconfig_version)
|
assert cli_as_dict("--version") == expected_args(preconfig_cmd=preconfig_version)
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"input_str",
|
||||||
|
[
|
||||||
|
'editor:"nano", colors.title:blue, default:"/tmp/egg.txt"',
|
||||||
|
'editor:"vi -c startinsert", colors.title:blue, default:"/tmp/egg.txt"',
|
||||||
|
'editor:"nano", colors.title:blue, default:"/tmp/eg\ g.txt"'
|
||||||
|
]
|
||||||
|
)
|
||||||
|
def test_deserialize_config_args(input_str):
|
||||||
|
from jrnl.args import deserialize_config_args
|
||||||
|
|
||||||
|
runtime_config = deserialize_config_args(input_str)
|
||||||
|
assert runtime_config.__class__ == dict
|
||||||
|
assert "editor" in runtime_config.keys()
|
||||||
|
assert "colors.title" in runtime_config.keys()
|
||||||
|
assert "default" in runtime_config.keys()
|
||||||
|
|
||||||
def test_editor_override():
|
def test_editor_override():
|
||||||
|
|
||||||
assert cli_as_dict('--config-override \'{"editor": "nano"}\'') == expected_args(
|
parsed_args = cli_as_dict('--config-override editor:"nano"')
|
||||||
|
assert parsed_args == expected_args(
|
||||||
config_override={"editor": "nano"}
|
config_override={"editor": "nano"}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_color_override():
|
def test_color_override():
|
||||||
assert cli_as_dict(
|
assert cli_as_dict(
|
||||||
'--config-override \'{"colors.body": "blue"}\''
|
'--config-override colors.body:blue'
|
||||||
) == expected_args(config_override={"colors.body": "blue"})
|
) == expected_args(config_override={"colors.body": "blue"})
|
||||||
|
|
||||||
|
|
||||||
def test_multiple_overrides():
|
def test_multiple_overrides():
|
||||||
assert cli_as_dict(
|
parsed_args = cli_as_dict(
|
||||||
'--config-override \'{"colors.title": "green", "editor":"", "journal.scratchpad": "/tmp/scratchpad"}\''
|
'--config-override colors.title:green,editor:"nano",journal.scratchpad:"/tmp/scratchpad"'
|
||||||
) == expected_args(
|
)
|
||||||
|
assert parsed_args == expected_args(
|
||||||
config_override={
|
config_override={
|
||||||
"colors.title": "green",
|
'colors.title': 'green',
|
||||||
"journal.scratchpad": "/tmp/scratchpad",
|
'journal.scratchpad': '/tmp/scratchpad',
|
||||||
"editor": "",
|
'editor': 'nano',
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue