mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-20 04:58: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"
|
||||
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 collections import defaultdict
|
||||
import os
|
||||
import ast
|
||||
import json
|
||||
import yaml
|
||||
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 for journal "{journal}" should have "{key}" set to "{value}"')
|
||||
def config_var(context, key, value, journal=None):
|
||||
t, value = value.split(":")
|
||||
value = {
|
||||
"bool": lambda v: v.lower() == "true",
|
||||
"int": int,
|
||||
"str": str
|
||||
}[t](value)
|
||||
if not value[0] == "{":
|
||||
t, value = value.split(":")
|
||||
value = {
|
||||
"bool": lambda v: v.lower() == "true",
|
||||
"int": int,
|
||||
"str": str
|
||||
}[t](value)
|
||||
else:
|
||||
# Handle value being a dictionary
|
||||
value = ast.literal_eval(value)
|
||||
|
||||
config = util.load_config(install.CONFIG_FILE_PATH)
|
||||
if journal:
|
||||
config = config["journals"][journal]
|
||||
|
|
|
@ -13,7 +13,7 @@ Feature: Upgrading Journals from 1.x.x to 2.x.x
|
|||
|
||||
Scenario: Upgrading a journal encrypted with jrnl 1.x
|
||||
Given we use the config "encrypted_old.json"
|
||||
When we run "jrnl -n 1" and enter
|
||||
When we run "jrnl -n 1" and enter
|
||||
"""
|
||||
Y
|
||||
bad doggie no biscuit
|
||||
|
@ -21,3 +21,8 @@ Feature: Upgrading Journals from 1.x.x to 2.x.x
|
|||
"""
|
||||
Then we should see the message "Password"
|
||||
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