mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-20 21:18:32 +02:00
Add tests for colors in configs
- Identifying invalid color configs - Upgrading config from no colors -> colors
This commit is contained in:
parent
8053d250f4
commit
eb1ed3c0cd
5 changed files with 54 additions and 7 deletions
|
@ -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.
|
||||||
|
"""
|
||||||
|
|
15
features/data/configs/invalid_color.yaml
Normal file
15
features/data/configs/invalid_color.yaml
Normal 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
|
12
features/data/configs/no_colors.yaml
Normal file
12
features/data/configs/no_colors.yaml
Normal 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: "|"
|
|
@ -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):
|
||||||
t, value = value.split(":")
|
if not value[0] == "{":
|
||||||
value = {
|
t, value = value.split(":")
|
||||||
"bool": lambda v: v.lower() == "true",
|
value = {
|
||||||
"int": int,
|
"bool": lambda v: v.lower() == "true",
|
||||||
"str": str
|
"int": int,
|
||||||
}[t](value)
|
"str": str
|
||||||
|
}[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]
|
||||||
|
|
|
@ -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'}"
|
||||||
|
|
Loading…
Add table
Reference in a new issue