mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-20 13:08:31 +02:00
behavior test for format --pretty
This commit is contained in:
parent
eca002ac29
commit
1f8351a9f0
3 changed files with 43 additions and 3 deletions
|
@ -1,4 +1,9 @@
|
||||||
Feature: Custom formats
|
Feature: Custom formats
|
||||||
|
Scenario: Pretty Printing aka the Default
|
||||||
|
Given We use the config "pretty.yaml"
|
||||||
|
When we run "jrnl --format pretty -3"
|
||||||
|
Then we should get no error
|
||||||
|
And the output should be pretty printed
|
||||||
|
|
||||||
Scenario Outline: JSON format
|
Scenario Outline: JSON format
|
||||||
Given we use the config "<config>.yaml"
|
Given we use the config "<config>.yaml"
|
||||||
|
|
|
@ -15,6 +15,7 @@ from behave import when
|
||||||
import keyring
|
import keyring
|
||||||
import toml
|
import toml
|
||||||
import yaml
|
import yaml
|
||||||
|
from yaml.loader import FullLoader, Loader
|
||||||
|
|
||||||
import jrnl.time
|
import jrnl.time
|
||||||
from jrnl import Journal
|
from jrnl import Journal
|
||||||
|
@ -393,7 +394,8 @@ def all_input_was_used(context):
|
||||||
@when('we run "{command}" and pipe "{text}"')
|
@when('we run "{command}" and pipe "{text}"')
|
||||||
def run(context, command, text=""):
|
def run(context, command, text=""):
|
||||||
text = text or context.text or ""
|
text = text or context.text or ""
|
||||||
|
with open(context.config_path) as f:
|
||||||
|
context.jrnl_config = yaml.load(f,Loader=yaml.FullLoader)
|
||||||
if "cache_dir" in context and context.cache_dir is not None:
|
if "cache_dir" in context and context.cache_dir is not None:
|
||||||
cache_dir = os.path.join("features", "cache", context.cache_dir)
|
cache_dir = os.path.join("features", "cache", context.cache_dir)
|
||||||
command = command.format(cache_dir=cache_dir)
|
command = command.format(cache_dir=cache_dir)
|
||||||
|
@ -423,6 +425,7 @@ def run(context, command, text=""):
|
||||||
patch("sys.stdin.read", side_effect=lambda: text), \
|
patch("sys.stdin.read", side_effect=lambda: text), \
|
||||||
patch("jrnl.time.parse", side_effect=_mock_time_parse(context)), \
|
patch("jrnl.time.parse", side_effect=_mock_time_parse(context)), \
|
||||||
patch("jrnl.config.get_config_path", side_effect=lambda: context.config_path), \
|
patch("jrnl.config.get_config_path", side_effect=lambda: context.config_path), \
|
||||||
|
patch("jrnl.install.load_or_install_jrnl",return_value = context.jrnl_config), \
|
||||||
patch("jrnl.install.get_config_path", side_effect=lambda: context.config_path) \
|
patch("jrnl.install.get_config_path", side_effect=lambda: context.config_path) \
|
||||||
:
|
:
|
||||||
context.editor = mock_editor
|
context.editor = mock_editor
|
||||||
|
|
|
@ -1,15 +1,47 @@
|
||||||
# Copyright (C) 2012-2021 jrnl contributors
|
# Copyright (C) 2012-2021 jrnl contributors
|
||||||
# License: https://www.gnu.org/licenses/gpl-3.0.html
|
# License: https://www.gnu.org/licenses/gpl-3.0.html
|
||||||
|
|
||||||
|
from jrnl import color
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
import random
|
import random
|
||||||
import string
|
import string
|
||||||
from xml.etree import ElementTree
|
from xml.etree import ElementTree
|
||||||
|
from colorama import Fore, Style
|
||||||
from behave import given
|
from behave import given
|
||||||
from behave import then
|
from behave import then
|
||||||
|
import colorama
|
||||||
|
|
||||||
|
def style_text(to_bold: bool, text_color: colorama.Fore, text_to_print: str):
|
||||||
|
"""Generate colorized and styled text for expected output. Its purpose is the same as Entry.colorize
|
||||||
|
|
||||||
|
:param to_bold: Flag whether the text should be bolded
|
||||||
|
:type to_bold: bool
|
||||||
|
:param text_color: Valid colorama.Fore color for the text
|
||||||
|
:type text_color: colorama.Fore
|
||||||
|
:param text_to_print: Message contents
|
||||||
|
:type text_to_print: str
|
||||||
|
:return: Styled and colored output
|
||||||
|
:rtype: str
|
||||||
|
"""
|
||||||
|
if to_bold:
|
||||||
|
text_style = Style.BRIGHT
|
||||||
|
else:
|
||||||
|
text_style = Style.NORMAL
|
||||||
|
text_color = getattr(colorama.Fore,text_color.upper(), None)
|
||||||
|
return text_style + text_color + text_to_print + Style.RESET_ALL
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@then("the output should be pretty printed")
|
||||||
|
def check_export_pretty(context):
|
||||||
|
out = context.stdout_capture.getvalue()
|
||||||
|
lines = out.splitlines()
|
||||||
|
|
||||||
|
# As per the configuration,
|
||||||
|
expected_colorized_title = style_text(True, context.jrnl_config['colors']['date'].upper(), '2013-06-09 15:39') + ' ' + style_text(True, context.jrnl_config['colors']['title'].upper(), 'My first entry.')
|
||||||
|
assert lines[0] == expected_colorized_title
|
||||||
|
|
||||||
|
|
||||||
@then("the output should be parsable as json")
|
@then("the output should be parsable as json")
|
||||||
|
|
Loading…
Add table
Reference in a new issue