mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-20 13:08:31 +02:00
make format
This commit is contained in:
parent
983c9c8c4b
commit
528ce1efe2
5 changed files with 48 additions and 44 deletions
|
@ -1,5 +1,3 @@
|
||||||
from tests.test_config import expected_override
|
|
||||||
from jrnl.editor import get_text_from_stdin
|
|
||||||
from jrnl.jrnl import run
|
from jrnl.jrnl import run
|
||||||
from jrnl.os_compat import split_args
|
from jrnl.os_compat import split_args
|
||||||
from unittest import mock
|
from unittest import mock
|
||||||
|
@ -12,6 +10,8 @@ import yaml
|
||||||
from yaml.loader import FullLoader
|
from yaml.loader import FullLoader
|
||||||
|
|
||||||
import jrnl
|
import jrnl
|
||||||
|
|
||||||
|
|
||||||
def _mock_time_parse(context):
|
def _mock_time_parse(context):
|
||||||
original_parse = jrnl.time.parse
|
original_parse = jrnl.time.parse
|
||||||
if "now" not in context:
|
if "now" not in context:
|
||||||
|
@ -73,15 +73,13 @@ def config_override(context, key_as_dots: str, override_value: str):
|
||||||
|
|
||||||
@then("the editor {editor} should have been called")
|
@then("the editor {editor} should have been called")
|
||||||
def editor_override(context, editor):
|
def editor_override(context, editor):
|
||||||
|
|
||||||
def _mock_write_in_editor(config):
|
def _mock_write_in_editor(config):
|
||||||
editor = config['editor']
|
editor = config["editor"]
|
||||||
journal = 'features/journals/journal.jrnl'
|
journal = "features/journals/journal.jrnl"
|
||||||
context.tmpfile = journal
|
context.tmpfile = journal
|
||||||
print("%s has been launched" % editor)
|
print("%s has been launched" % editor)
|
||||||
return journal
|
return journal
|
||||||
|
|
||||||
|
|
||||||
# fmt: off
|
# fmt: off
|
||||||
# see: https://github.com/psf/black/issues/664
|
# see: https://github.com/psf/black/issues/664
|
||||||
with \
|
with \
|
||||||
|
@ -105,14 +103,21 @@ def editor_override(context, editor):
|
||||||
context.exit_status = e.code
|
context.exit_status = e.code
|
||||||
# fmt: on
|
# fmt: on
|
||||||
|
|
||||||
|
|
||||||
@then("the stdin prompt must be launched")
|
@then("the stdin prompt must be launched")
|
||||||
def override_editor_to_use_stdin(context):
|
def override_editor_to_use_stdin(context):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with \
|
with mock.patch(
|
||||||
mock.patch('sys.stdin.read', return_value='Zwei peanuts walk into a bar und one of zem was a-salted')as mock_stdin_read, \
|
"sys.stdin.read",
|
||||||
mock.patch("jrnl.install.load_or_install_jrnl", return_value=context.cfg), \
|
return_value="Zwei peanuts walk into a bar und one of zem was a-salted",
|
||||||
mock.patch("jrnl.Journal.open_journal", spec=False, return_value='features/journals/journal.jrnl'):
|
) as mock_stdin_read, mock.patch(
|
||||||
|
"jrnl.install.load_or_install_jrnl", return_value=context.cfg
|
||||||
|
), mock.patch(
|
||||||
|
"jrnl.Journal.open_journal",
|
||||||
|
spec=False,
|
||||||
|
return_value="features/journals/journal.jrnl",
|
||||||
|
):
|
||||||
run(context.parser)
|
run(context.parser)
|
||||||
context.exit_status = 0
|
context.exit_status = 0
|
||||||
mock_stdin_read.assert_called_once()
|
mock_stdin_read.assert_called_once()
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
import argparse
|
import argparse
|
||||||
import re
|
import re
|
||||||
import textwrap
|
import textwrap
|
||||||
import json
|
|
||||||
|
|
||||||
from .commands import postconfig_decrypt
|
from .commands import postconfig_decrypt
|
||||||
from .commands import postconfig_encrypt
|
from .commands import postconfig_encrypt
|
||||||
|
|
|
@ -2,7 +2,6 @@ import shlex
|
||||||
import pytest
|
import pytest
|
||||||
import mock
|
import mock
|
||||||
|
|
||||||
import yaml
|
|
||||||
|
|
||||||
from jrnl.args import parse_args
|
from jrnl.args import parse_args
|
||||||
from jrnl.jrnl import run
|
from jrnl.jrnl import run
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
from features.steps.override import config_override
|
|
||||||
import shlex
|
import shlex
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
@ -6,6 +5,7 @@ import pytest
|
||||||
from jrnl.args import parse_args
|
from jrnl.args import parse_args
|
||||||
from jrnl.args import deserialize_config_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)
|
||||||
args = parse_args(cli)
|
args = parse_args(cli)
|
||||||
|
@ -206,6 +206,7 @@ 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:
|
class TestDeserialization:
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"input_str",
|
"input_str",
|
||||||
|
@ -217,7 +218,6 @@ class TestDeserialization:
|
||||||
)
|
)
|
||||||
def test_deserialize_multiword_strings(self, input_str):
|
def test_deserialize_multiword_strings(self, input_str):
|
||||||
|
|
||||||
|
|
||||||
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()
|
||||||
|
@ -225,17 +225,18 @@ class TestDeserialization:
|
||||||
assert "default" in runtime_config.keys()
|
assert "default" in runtime_config.keys()
|
||||||
|
|
||||||
def test_deserialize_int(self):
|
def test_deserialize_int(self):
|
||||||
input = 'linewrap: 23, default_hour: 19'
|
input = "linewrap: 23, default_hour: 19"
|
||||||
runtime_config = deserialize_config_args(input)
|
runtime_config = deserialize_config_args(input)
|
||||||
assert runtime_config['linewrap'] == 23
|
assert runtime_config["linewrap"] == 23
|
||||||
assert runtime_config['default_hour'] == 19
|
assert runtime_config["default_hour"] == 19
|
||||||
|
|
||||||
def test_deserialize_multiple_datatypes(self):
|
def test_deserialize_multiple_datatypes(self):
|
||||||
input = 'linewrap: 23, encrypt: false, editor:"vi -c startinsert"'
|
input = 'linewrap: 23, encrypt: false, editor:"vi -c startinsert"'
|
||||||
cfg = deserialize_config_args(input)
|
cfg = deserialize_config_args(input)
|
||||||
assert cfg['encrypt'] == False
|
assert cfg["encrypt"] == False
|
||||||
assert cfg['linewrap'] == 23
|
assert cfg["linewrap"] == 23
|
||||||
assert cfg['editor'] == '"vi -c startinsert"'
|
assert cfg["editor"] == '"vi -c startinsert"'
|
||||||
|
|
||||||
|
|
||||||
def test_editor_override():
|
def test_editor_override():
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue