From d4cb4e64f60ebb9822cc013b5e6260d3f9c27064 Mon Sep 17 00:00:00 2001 From: Manuel Ebert Date: Tue, 6 Aug 2013 17:57:31 -0700 Subject: [PATCH] Tests for filtering --- features/data/journals/tags.journal | 2 +- features/exporting.feature | 52 +++++++++++++++++++++++++++++ features/steps/core.py | 18 ++++++++-- features/tagging.feature | 10 ++++++ 4 files changed, 79 insertions(+), 3 deletions(-) create mode 100644 features/exporting.feature diff --git a/features/data/journals/tags.journal b/features/data/journals/tags.journal index 7b5cdf04..bfd49cf4 100644 --- a/features/data/journals/tags.journal +++ b/features/data/journals/tags.journal @@ -1,4 +1,4 @@ -2013-06-09 15:39 I have an @idea: +2013-04-09 15:39 I have an @idea: (1) write a command line @journal software (2) ??? (3) PROFIT! diff --git a/features/exporting.feature b/features/exporting.feature new file mode 100644 index 00000000..26a0f7b4 --- /dev/null +++ b/features/exporting.feature @@ -0,0 +1,52 @@ +Feature: Expoting a Journal + + Scenario: Exporting to json + Given we use the config "tags.json" + When we run "jrnl --export json" + Then we should get no error + and the output should be + """ + { + "entries": [ + { + "body": "(1) write a command line @journal software\n(2) ???\n(3) PROFIT!", + "date": "2013-04-09", + "time": "15:39", + "title": "I have an @idea:" + }, + { + "body": "As alway's he shared his latest @idea on how to rule the world with me.", + "date": "2013-06-10", + "time": "15:40", + "title": "I met with @dan." + } + ], + "tags": { + "@idea": 2, + "@journal": 1, + "@dan": 1 + } + } + """ + + Scenario: Exporting using filters should only export parts of the journal + Given we use the config "tags.json" + When we run "jrnl -to 'may 2013' --export json" + Then we should get no error + and the output should be + """ + { + "entries": [ + { + "body": "(1) write a command line @journal software\n(2) ???\n(3) PROFIT!", + "date": "2013-04-09", + "time": "15:39", + "title": "I have an @idea:" + } + ], + "tags": { + "@idea": 1, + "@journal": 1 + } + } + """ diff --git a/features/steps/core.py b/features/steps/core.py index b3675c1c..fc9e15ff 100644 --- a/features/steps/core.py +++ b/features/steps/core.py @@ -8,6 +8,20 @@ try: except ImportError: from cStringIO import StringIO +def _parse_args(command): + nargs=[] + concats = [] + for a in command.split()[1:]: + if a.startswith("'"): + concats.append(a.strip("'")) + elif a.endswith("'"): + concats.append(a.strip("'")) + nargs.append(u" ".join(concats)) + concats = [] + else: + nargs.append(a) + return nargs + def read_journal(journal_name="default"): with open(jrnl.CONFIG_PATH) as config_file: config = json.load(config_file) @@ -34,14 +48,14 @@ def set_config(context, config_file): @when('we run "{command}" and enter "{inputs}"') def run_with_input(context, command, inputs=None): text = inputs or context.text - args = command.split()[1:] + args = _parse_args(command) buffer = StringIO(text.strip()) jrnl.util.STDIN = buffer jrnl.cli(args) @when('we run "{command}"') def run(context, command): - args = command.split()[1:] + args = _parse_args(command) jrnl.cli(args or None) diff --git a/features/tagging.feature b/features/tagging.feature index a030d610..a30c1052 100644 --- a/features/tagging.feature +++ b/features/tagging.feature @@ -10,3 +10,13 @@ Feature: Tagging @journal : 1 @dan : 1 """ + + Scenario: Filtering journals should also filter tags + Given we use the config "tags.json" + When we run "jrnl -from 'may 2013' --tags" + Then we should get no error + and the output should be + """ + @idea : 1 + @dan : 1 + """