Add tests for colors in configs

- Identifying invalid color configs
- Upgrading config from no colors -> colors
This commit is contained in:
Aaron Lichtman 2019-11-06 02:49:47 +01:00
parent 8053d250f4
commit eb1ed3c0cd
No known key found for this signature in database
GPG key ID: 22368077DE9F9903
5 changed files with 54 additions and 7 deletions

View file

@ -58,3 +58,12 @@ Feature: Basic reading and writing to a journal
When we run "jrnl -on 2013-06-10 -s" When we run "jrnl -on 2013-06-10 -s"
Then the output should be "2013-06-10 15:40 Life is good." Then the output should be "2013-06-10 15:40 Life is good."
Scenario: Invalid color configuration
Given we use the config "invalid_color.yaml"
When we run "jrnl -on 2013-06-10 -s"
Then the output should be
"""
[ERROR: date set to invalid color: not-a-color]
[ERROR: title set to invalid color: also-not-a-color]
2013-06-10 15:40 Life is good.
"""

View file

@ -0,0 +1,15 @@
default_hour: 9
default_minute: 0
editor: ""
encrypt: false
highlight: true
journals:
default: features/journals/simple.journal
linewrap: 80
tagsymbols: "@"
template: false
timeformat: "%Y-%m-%d %H:%M"
indent_character: "|"
colors:
date: not-a-color
title: also-not-a-color

View file

@ -0,0 +1,12 @@
default_hour: 9
default_minute: 0
editor: ""
encrypt: false
highlight: true
journals:
default: features/journals/simple.journal
linewrap: 80
tagsymbols: "@"
template: false
timeformat: "%Y-%m-%d %H:%M"
indent_character: "|"

View file

@ -8,6 +8,7 @@ from dateutil import parser as date_parser
from ansiwrap import strip_color from ansiwrap import strip_color
from collections import defaultdict from collections import defaultdict
import os import os
import ast
import json import json
import yaml import yaml
import keyring import keyring
@ -234,12 +235,17 @@ def journal_doesnt_exist(context, journal_name="default"):
@then('the config should have "{key}" set to "{value}"') @then('the config should have "{key}" set to "{value}"')
@then('the config for journal "{journal}" should have "{key}" set to "{value}"') @then('the config for journal "{journal}" should have "{key}" set to "{value}"')
def config_var(context, key, value, journal=None): def config_var(context, key, value, journal=None):
if not value[0] == "{":
t, value = value.split(":") t, value = value.split(":")
value = { value = {
"bool": lambda v: v.lower() == "true", "bool": lambda v: v.lower() == "true",
"int": int, "int": int,
"str": str "str": str
}[t](value) }[t](value)
else:
# Handle value being a dictionary
value = ast.literal_eval(value)
config = util.load_config(install.CONFIG_FILE_PATH) config = util.load_config(install.CONFIG_FILE_PATH)
if journal: if journal:
config = config["journals"][journal] config = config["journals"][journal]

View file

@ -21,3 +21,8 @@ Feature: Upgrading Journals from 1.x.x to 2.x.x
""" """
Then we should see the message "Password" Then we should see the message "Password"
and the output should contain "2013-06-10 15:40 Life is good" and the output should contain "2013-06-10 15:40 Life is good"
Scenario: Upgrading a config without colors to colors
Given we use the config "no_colors.yaml"
When we run "jrnl -n 1"
Then the config should have "colors" set to "{'date':'red', 'title':'blue'}"