mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-10 16:48:31 +02:00
Tests for filtering
This commit is contained in:
parent
e5ee4e3f97
commit
d4cb4e64f6
4 changed files with 79 additions and 3 deletions
|
@ -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
|
(1) write a command line @journal software
|
||||||
(2) ???
|
(2) ???
|
||||||
(3) PROFIT!
|
(3) PROFIT!
|
||||||
|
|
52
features/exporting.feature
Normal file
52
features/exporting.feature
Normal file
|
@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"""
|
|
@ -8,6 +8,20 @@ try:
|
||||||
except ImportError:
|
except ImportError:
|
||||||
from cStringIO import StringIO
|
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"):
|
def read_journal(journal_name="default"):
|
||||||
with open(jrnl.CONFIG_PATH) as config_file:
|
with open(jrnl.CONFIG_PATH) as config_file:
|
||||||
config = json.load(config_file)
|
config = json.load(config_file)
|
||||||
|
@ -34,14 +48,14 @@ def set_config(context, config_file):
|
||||||
@when('we run "{command}" and enter "{inputs}"')
|
@when('we run "{command}" and enter "{inputs}"')
|
||||||
def run_with_input(context, command, inputs=None):
|
def run_with_input(context, command, inputs=None):
|
||||||
text = inputs or context.text
|
text = inputs or context.text
|
||||||
args = command.split()[1:]
|
args = _parse_args(command)
|
||||||
buffer = StringIO(text.strip())
|
buffer = StringIO(text.strip())
|
||||||
jrnl.util.STDIN = buffer
|
jrnl.util.STDIN = buffer
|
||||||
jrnl.cli(args)
|
jrnl.cli(args)
|
||||||
|
|
||||||
@when('we run "{command}"')
|
@when('we run "{command}"')
|
||||||
def run(context, command):
|
def run(context, command):
|
||||||
args = command.split()[1:]
|
args = _parse_args(command)
|
||||||
jrnl.cli(args or None)
|
jrnl.cli(args or None)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -10,3 +10,13 @@ Feature: Tagging
|
||||||
@journal : 1
|
@journal : 1
|
||||||
@dan : 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
|
||||||
|
"""
|
||||||
|
|
Loading…
Add table
Reference in a new issue