mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-07-04 23:46:14 +02:00
organize deserialization unittests
This commit is contained in:
parent
3b74c2dec0
commit
abbb2c502f
1 changed files with 28 additions and 16 deletions
|
@ -4,7 +4,7 @@ import shlex
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from jrnl.args import parse_args
|
from jrnl.args import parse_args
|
||||||
|
from jrnl.args import deserialize_config_args
|
||||||
|
|
||||||
def cli_as_dict(str):
|
def cli_as_dict(str):
|
||||||
cli = shlex.split(str)
|
cli = shlex.split(str)
|
||||||
|
@ -206,24 +206,36 @@ 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)
|
||||||
|
|
||||||
|
class TestDeserialization:
|
||||||
|
@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_multiword_strings(self,input_str):
|
||||||
|
|
||||||
@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)
|
runtime_config = deserialize_config_args(input_str)
|
||||||
assert runtime_config.__class__ == dict
|
assert runtime_config.__class__ == dict
|
||||||
assert "editor" in runtime_config.keys()
|
assert "editor" in runtime_config.keys()
|
||||||
assert "colors.title" in runtime_config.keys()
|
assert "colors.title" in runtime_config.keys()
|
||||||
assert "default" in runtime_config.keys()
|
assert "default" in runtime_config.keys()
|
||||||
|
|
||||||
|
def test_deserialize_int(self):
|
||||||
|
input = 'linewrap: 23, default_hour: 19'
|
||||||
|
runtime_config = deserialize_config_args(input)
|
||||||
|
assert runtime_config['linewrap'] == 23
|
||||||
|
assert runtime_config['default_hour'] == 19
|
||||||
|
|
||||||
|
def test_deserialize_multiple_datatypes(self):
|
||||||
|
input = 'linewrap: 23, encrypt: false, editor:"vi -c startinsert"'
|
||||||
|
cfg = deserialize_config_args(input)
|
||||||
|
assert cfg['encrypt'] == False
|
||||||
|
assert cfg['linewrap'] == 23
|
||||||
|
assert cfg['editor'] == '"vi -c startinsert"'
|
||||||
|
|
||||||
def test_editor_override():
|
def test_editor_override():
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue