diff --git a/features/core.feature b/features/core.feature index ab86da42..dd072ba4 100644 --- a/features/core.feature +++ b/features/core.feature @@ -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. + """ diff --git a/features/data/configs/invalid_color.yaml b/features/data/configs/invalid_color.yaml new file mode 100644 index 00000000..4c2c78fc --- /dev/null +++ b/features/data/configs/invalid_color.yaml @@ -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 diff --git a/features/data/configs/no_colors.yaml b/features/data/configs/no_colors.yaml new file mode 100644 index 00000000..9111b561 --- /dev/null +++ b/features/data/configs/no_colors.yaml @@ -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: "|" diff --git a/features/steps/core.py b/features/steps/core.py index ab9b90c6..fbe8fa08 100644 --- a/features/steps/core.py +++ b/features/steps/core.py @@ -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] diff --git a/features/upgrade.feature b/features/upgrade.feature index bce026b8..587102eb 100644 --- a/features/upgrade.feature +++ b/features/upgrade.feature @@ -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'}"