From 783603fb1c1d8a1717b3343b8e775b4047d10e70 Mon Sep 17 00:00:00 2001 From: Manuel Ebert Date: Thu, 18 Jul 2013 22:49:22 +0200 Subject: [PATCH] Core testing --- features/configs/basic.json | 14 ++++++++++++++ features/core.feature | 14 ++++++++++++++ features/journals/simple.journal | 5 +++++ features/steps/core.py | 24 ++++++++++++++++++++++++ 4 files changed, 57 insertions(+) create mode 100644 features/configs/basic.json create mode 100644 features/core.feature create mode 100644 features/journals/simple.journal create mode 100644 features/steps/core.py diff --git a/features/configs/basic.json b/features/configs/basic.json new file mode 100644 index 00000000..2dc11d73 --- /dev/null +++ b/features/configs/basic.json @@ -0,0 +1,14 @@ +{ + "default_hour": 9, + "timeformat": "%Y-%m-%d %H:%M", + "linewrap": 80, + "encrypt": false, + "editor": "", + "default_minute": 0, + "highlight": true, + "password": "", + "journals": { + "default": "features/journals/simple.journal" + }, + "tagsymbols": "@" +} diff --git a/features/core.feature b/features/core.feature new file mode 100644 index 00000000..45aa5e26 --- /dev/null +++ b/features/core.feature @@ -0,0 +1,14 @@ +Feature: Basic reading and writing to a journal + + Scenario: Loading a sample journal + Given we use "basic.json" + When we run "jrnl -n 2" + Then we should get no error + Then the output should be + """ + 2013-06-09 15:39 My first entry. + | Everything is alright + + 2013-06-10 15:40 Life is good. + | But I'm better. + """ diff --git a/features/journals/simple.journal b/features/journals/simple.journal new file mode 100644 index 00000000..66d8439c --- /dev/null +++ b/features/journals/simple.journal @@ -0,0 +1,5 @@ +2013-06-09 15:39 My first entry. +Everything is alright + +2013-06-10 15:40 Life is good. +But I'm better. diff --git a/features/steps/core.py b/features/steps/core.py new file mode 100644 index 00000000..44893d41 --- /dev/null +++ b/features/steps/core.py @@ -0,0 +1,24 @@ +from behave import * +from jrnl import Journal, jrnl +import os + +@given('we use "{config_file}"') +def set_config(context, config_file): + full_path = os.path.join("features/configs", config_file) + jrnl.CONFIG_PATH = os.path.abspath(full_path) + +@when('we run "{command}"') +def run(context, command): + args = command.split()[1:] + jrnl.cli(args) + +@then('we should get no error') +def no_error(context): + assert context.failed is False + +@then('the output should be') +def check_output(context): + text = context.text.strip().splitlines() + out = context.stdout_capture.getvalue().strip().splitlines() + for line_text, line_out in zip(text, out): + assert line_text.strip() == line_out.strip()