mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-10 16:48:31 +02:00
Tests for multiple journals
This commit is contained in:
parent
f9bdc13210
commit
4b9b5e827b
6 changed files with 86 additions and 3 deletions
16
features/configs/multiple.json
Normal file
16
features/configs/multiple.json
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
{
|
||||||
|
"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",
|
||||||
|
"work": "features/journals/work.journal",
|
||||||
|
"ideas": "features/journals/nothing.journal"
|
||||||
|
},
|
||||||
|
"tagsymbols": "@"
|
||||||
|
}
|
|
@ -17,6 +17,8 @@ def after_scenario(context, scenario):
|
||||||
for folder in ("configs", "journals"):
|
for folder in ("configs", "journals"):
|
||||||
original = os.path.join("features", folder)
|
original = os.path.join("features", folder)
|
||||||
backup = os.path.join("features", folder+"_backup")
|
backup = os.path.join("features", folder+"_backup")
|
||||||
|
for filename in os.listdir(original):
|
||||||
|
os.remove(os.path.join(original, filename))
|
||||||
for filename in os.listdir(backup):
|
for filename in os.listdir(backup):
|
||||||
shutil.copy2(os.path.join(backup, filename), original)
|
shutil.copy2(os.path.join(backup, filename), original)
|
||||||
shutil.rmtree(backup)
|
shutil.rmtree(backup)
|
||||||
|
|
0
features/journals/work.journal
Normal file
0
features/journals/work.journal
Normal file
36
features/multiple_journals.feature
Normal file
36
features/multiple_journals.feature
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
Feature: Multiple journals
|
||||||
|
|
||||||
|
Scenario: Loading a config with two journals
|
||||||
|
Given we use the config "multiple.json"
|
||||||
|
Then journal "default" should have 2 entries
|
||||||
|
and journal "work" should have 0 entries
|
||||||
|
|
||||||
|
Scenario: Write to default config by default
|
||||||
|
Given we use the config "multiple.json"
|
||||||
|
When we run "jrnl this goes to default"
|
||||||
|
Then journal "default" should have 3 entries
|
||||||
|
and journal "work" should have 0 entries
|
||||||
|
|
||||||
|
Scenario: Write to specified journal
|
||||||
|
Given we use the config "multiple.json"
|
||||||
|
When we run "jrnl work a long day in the office"
|
||||||
|
Then journal "default" should have 2 entries
|
||||||
|
and journal "work" should have 1 entry
|
||||||
|
|
||||||
|
Scenario: Tell user which journal was used
|
||||||
|
Given we use the config "multiple.json"
|
||||||
|
When we run "jrnl work a long day in the office"
|
||||||
|
Then the output should contain "Entry added to work journal"
|
||||||
|
|
||||||
|
Scenario: Write to specified journal with a timestamp
|
||||||
|
Given we use the config "multiple.json"
|
||||||
|
When we run "jrnl work 23 july 2012: a long day in the office"
|
||||||
|
Then journal "default" should have 2 entries
|
||||||
|
and journal "work" should have 1 entry
|
||||||
|
and journal "work" should contain "2012-07-23"
|
||||||
|
|
||||||
|
Scenario: Create new journals as required
|
||||||
|
Given we use the config "multiple.json"
|
||||||
|
Then journal "ideas" should not exist
|
||||||
|
When we run "jrnl ideas 23 july 2012: sell my junk on ebay and make lots of money"
|
||||||
|
Then journal "ideas" should have 1 entry
|
|
@ -1,5 +1,5 @@
|
||||||
from behave import *
|
from behave import *
|
||||||
from jrnl import jrnl
|
from jrnl import jrnl, Journal
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import json
|
import json
|
||||||
|
@ -15,6 +15,16 @@ def read_journal(journal_name="default"):
|
||||||
journal = journal_file.read()
|
journal = journal_file.read()
|
||||||
return journal
|
return journal
|
||||||
|
|
||||||
|
def open_journal(journal_name="default"):
|
||||||
|
with open(jrnl.CONFIG_PATH) as config_file:
|
||||||
|
config = json.load(config_file)
|
||||||
|
journals = config['journals']
|
||||||
|
if type(journals) is dict: # We can override the default config on a by-journal basis
|
||||||
|
config['journal'] = journals.get(journal_name)
|
||||||
|
else: # But also just give them a string to point to the journal file
|
||||||
|
config['journal'] = journal
|
||||||
|
return Journal.Journal(**config)
|
||||||
|
|
||||||
@given('we use the config "{config_file}"')
|
@given('we use the config "{config_file}"')
|
||||||
def set_config(context, config_file):
|
def set_config(context, config_file):
|
||||||
full_path = os.path.join("features/configs", config_file)
|
full_path = os.path.join("features/configs", config_file)
|
||||||
|
@ -52,8 +62,28 @@ def check_output_inline(context, text):
|
||||||
assert text in out
|
assert text in out
|
||||||
|
|
||||||
@then('the journal should contain "{text}"')
|
@then('the journal should contain "{text}"')
|
||||||
@then('journal {journal_name} should contain "{text}"')
|
@then('journal "{journal_name}" should contain "{text}"')
|
||||||
def check_journal_content(context, text, journal_name="default"):
|
def check_journal_content(context, text, journal_name="default"):
|
||||||
journal = read_journal(journal_name)
|
journal = read_journal(journal_name)
|
||||||
assert text in journal
|
assert text in journal
|
||||||
|
|
||||||
|
@then('journal "{journal_name}" should not exist')
|
||||||
|
def journal_doesnt_exist(context, journal_name="default"):
|
||||||
|
with open(jrnl.CONFIG_PATH) as config_file:
|
||||||
|
config = json.load(config_file)
|
||||||
|
journal_path = config['journals'][journal_name]
|
||||||
|
print journal_path
|
||||||
|
assert not os.path.exists(journal_path)
|
||||||
|
|
||||||
|
@then('the journal should have {number:d} entries')
|
||||||
|
@then('the journal should have {number:d} entry')
|
||||||
|
@then('journal "{journal_name}" should have {number:d} entries')
|
||||||
|
@then('journal "{journal_name}" should have {number:d} entry')
|
||||||
|
def check_journal_content(context, number, journal_name="default"):
|
||||||
|
journal = open_journal(journal_name)
|
||||||
|
assert len(journal.entries) == number
|
||||||
|
|
||||||
|
@then('fail')
|
||||||
|
def debug_fail(context):
|
||||||
|
assert False
|
||||||
|
|
||||||
|
|
|
@ -50,7 +50,6 @@ class Journal(object):
|
||||||
'linewrap': 80,
|
'linewrap': 80,
|
||||||
}
|
}
|
||||||
self.config.update(kwargs)
|
self.config.update(kwargs)
|
||||||
|
|
||||||
# Set up date parser
|
# Set up date parser
|
||||||
consts = pdt.Constants(usePyICU=False)
|
consts = pdt.Constants(usePyICU=False)
|
||||||
consts.DOWParseStyle = -1 # "Monday" will be either today or the last Monday
|
consts.DOWParseStyle = -1 # "Monday" will be either today or the last Monday
|
||||||
|
|
Loading…
Add table
Reference in a new issue