mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-20 04:58:32 +02:00
make format
This commit is contained in:
parent
bf89109525
commit
3b74c2dec0
3 changed files with 23 additions and 22 deletions
15
jrnl/args.py
15
jrnl/args.py
|
@ -17,14 +17,16 @@ from .plugins import EXPORT_FORMATS
|
||||||
from .plugins import IMPORT_FORMATS
|
from .plugins import IMPORT_FORMATS
|
||||||
from .plugins import util
|
from .plugins import util
|
||||||
|
|
||||||
def deserialize_config_args(input: str) -> dict:
|
|
||||||
_kvpairs = input.strip(' ').split(',')
|
def deserialize_config_args(input: str) -> dict:
|
||||||
runtime_modifications = {}
|
_kvpairs = input.strip(" ").split(",")
|
||||||
for _p in _kvpairs:
|
runtime_modifications = {}
|
||||||
l,r = _p.strip().split(':')
|
for _p in _kvpairs:
|
||||||
|
l, r = _p.strip().split(":")
|
||||||
runtime_modifications[l] = r
|
runtime_modifications[l] = r
|
||||||
return runtime_modifications
|
return runtime_modifications
|
||||||
|
|
||||||
|
|
||||||
class WrappingFormatter(argparse.RawTextHelpFormatter):
|
class WrappingFormatter(argparse.RawTextHelpFormatter):
|
||||||
"""Used in help screen"""
|
"""Used in help screen"""
|
||||||
|
|
||||||
|
@ -349,6 +351,5 @@ def parse_args(args=[]):
|
||||||
num = re.compile(r"^-(\d+)$")
|
num = re.compile(r"^-(\d+)$")
|
||||||
args = [num.sub(r"-n \1", arg) for arg in args]
|
args = [num.sub(r"-n \1", arg) for arg in args]
|
||||||
|
|
||||||
|
|
||||||
parsed_args = parser.parse_intermixed_args(args)
|
parsed_args = parser.parse_intermixed_args(args)
|
||||||
return parsed_args
|
return parsed_args
|
||||||
|
|
|
@ -85,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 = shlex.split('--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(
|
||||||
|
|
|
@ -206,35 +206,35 @@ 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(
|
@pytest.mark.parametrize(
|
||||||
"input_str",
|
"input_str",
|
||||||
[
|
[
|
||||||
'editor:"nano", colors.title:blue, default:"/tmp/egg.txt"',
|
'editor:"nano", colors.title:blue, default:"/tmp/egg.txt"',
|
||||||
'editor:"vi -c startinsert", 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"'
|
'editor:"nano", colors.title:blue, default:"/tmp/eg\ g.txt"',
|
||||||
]
|
],
|
||||||
)
|
)
|
||||||
def test_deserialize_config_args(input_str):
|
def test_deserialize_config_args(input_str):
|
||||||
from jrnl.args import deserialize_config_args
|
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_editor_override():
|
def test_editor_override():
|
||||||
|
|
||||||
parsed_args = cli_as_dict('--config-override editor:"nano"')
|
parsed_args = cli_as_dict('--config-override editor:"nano"')
|
||||||
assert parsed_args == expected_args(
|
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") == expected_args(
|
||||||
'--config-override colors.body:blue'
|
config_override={"colors.body": "blue"}
|
||||||
) == expected_args(config_override={"colors.body": "blue"})
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_multiple_overrides():
|
def test_multiple_overrides():
|
||||||
|
@ -243,9 +243,9 @@ def test_multiple_overrides():
|
||||||
)
|
)
|
||||||
assert parsed_args == 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': 'nano',
|
"editor": "nano",
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue