Tests for new structure

This commit is contained in:
Manuel Ebert 2013-11-29 10:23:16 -08:00
parent f22ddd706b
commit bf9adeb28a
3 changed files with 16 additions and 10 deletions

View file

@ -34,3 +34,9 @@ Feature: Basic reading and writing to a journal
Then we should get no error Then we should get no error
and the journal should contain "2013-07-25 09:00 I saw Elvis." and the journal should contain "2013-07-25 09:00 I saw Elvis."
and the journal should contain "He's alive." and the journal should contain "He's alive."
Scenario: Displaying the version number
Given we use the config "basic.json"
When we run "jrnl -v"
Then we should get no error
Then the output should contain "version"

View file

@ -1,7 +1,7 @@
from behave import * from behave import *
import shutil import shutil
import os import os
from jrnl import jrnl import jrnl
try: try:
from io import StringIO from io import StringIO
except ImportError: except ImportError:

View file

@ -1,5 +1,5 @@
from behave import * from behave import *
from jrnl import jrnl, Journal, util from jrnl import cli, Journal, util
from dateutil import parser as date_parser from dateutil import parser as date_parser
import os import os
import sys import sys
@ -27,14 +27,14 @@ def _parse_args(command):
return nargs return nargs
def read_journal(journal_name="default"): def read_journal(journal_name="default"):
with open(jrnl.CONFIG_PATH) as config_file: with open(cli.CONFIG_PATH) as config_file:
config = json.load(config_file) config = json.load(config_file)
with open(config['journals'][journal_name]) as journal_file: with open(config['journals'][journal_name]) as journal_file:
journal = journal_file.read() journal = journal_file.read()
return journal return journal
def open_journal(journal_name="default"): def open_journal(journal_name="default"):
with open(jrnl.CONFIG_PATH) as config_file: with open(cli.CONFIG_PATH) as config_file:
config = json.load(config_file) config = json.load(config_file)
journal_conf = config['journals'][journal_name] journal_conf = config['journals'][journal_name]
if type(journal_conf) is dict: # We can override the default config on a by-journal basis if type(journal_conf) is dict: # We can override the default config on a by-journal basis
@ -46,7 +46,7 @@ def open_journal(journal_name="default"):
@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)
jrnl.CONFIG_PATH = os.path.abspath(full_path) cli.CONFIG_PATH = os.path.abspath(full_path)
@when('we run "{command}" and enter') @when('we run "{command}" and enter')
@when('we run "{command}" and enter "{inputs}"') @when('we run "{command}" and enter "{inputs}"')
@ -54,9 +54,9 @@ def run_with_input(context, command, inputs=None):
text = inputs or context.text text = inputs or context.text
args = _parse_args(command) args = _parse_args(command)
buffer = StringIO(text.strip()) buffer = StringIO(text.strip())
jrnl.util.STDIN = buffer util.STDIN = buffer
try: try:
jrnl.cli(args or None) cli.run(args or None)
context.exit_status = 0 context.exit_status = 0
except SystemExit as e: except SystemExit as e:
context.exit_status = e.code context.exit_status = e.code
@ -65,7 +65,7 @@ def run_with_input(context, command, inputs=None):
def run(context, command): def run(context, command):
args = _parse_args(command) args = _parse_args(command)
try: try:
jrnl.cli(args or None) cli.run(args or None)
context.exit_status = 0 context.exit_status = 0
except SystemExit as e: except SystemExit as e:
context.exit_status = e.code context.exit_status = e.code
@ -154,7 +154,7 @@ def check_journal_content(context, text, journal_name="default"):
@then('journal "{journal_name}" should not exist') @then('journal "{journal_name}" should not exist')
def journal_doesnt_exist(context, journal_name="default"): def journal_doesnt_exist(context, journal_name="default"):
with open(jrnl.CONFIG_PATH) as config_file: with open(cli.CONFIG_PATH) as config_file:
config = json.load(config_file) config = json.load(config_file)
journal_path = config['journals'][journal_name] journal_path = config['journals'][journal_name]
assert not os.path.exists(journal_path) assert not os.path.exists(journal_path)
@ -168,7 +168,7 @@ def config_var(context, key, value, journal=None):
"int": int, "int": int,
"str": str "str": str
}[t](value) }[t](value)
with open(jrnl.CONFIG_PATH) as config_file: with open(cli.CONFIG_PATH) as config_file:
config = json.load(config_file) config = json.load(config_file)
if journal: if journal:
config = config["journals"][journal] config = config["journals"][journal]