mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-10 16:48:31 +02:00
Mock stdin
This commit is contained in:
parent
e75c24c696
commit
13f8e668dc
5 changed files with 43 additions and 44 deletions
|
@ -4,7 +4,7 @@ Feature: Basic reading and writing to a journal
|
||||||
Given we use the config "basic.json"
|
Given we use the config "basic.json"
|
||||||
When we run "jrnl -n 2"
|
When we run "jrnl -n 2"
|
||||||
Then we should get no error
|
Then we should get no error
|
||||||
And the output should be
|
and the output should be
|
||||||
"""
|
"""
|
||||||
2013-06-09 15:39 My first entry.
|
2013-06-09 15:39 My first entry.
|
||||||
| Everything is alright
|
| Everything is alright
|
||||||
|
@ -27,3 +27,10 @@ Feature: Basic reading and writing to a journal
|
||||||
When we run "jrnl -n 1"
|
When we run "jrnl -n 1"
|
||||||
Then the output should contain "🌞"
|
Then the output should contain "🌞"
|
||||||
and the output should contain "🐘"
|
and the output should contain "🐘"
|
||||||
|
|
||||||
|
Scenario: Writing an entry at the prompt
|
||||||
|
Given we use the config "basic.json"
|
||||||
|
When we run "jrnl" and enter "25 jul 2013: I saw Elvis. He's alive."
|
||||||
|
Then we should get no error
|
||||||
|
and the journal should contain "2013-07-25 09:00 I saw Elvis."
|
||||||
|
and the journal should contain "He's alive."
|
||||||
|
|
|
@ -1,16 +1,36 @@
|
||||||
from behave import *
|
from behave import *
|
||||||
from jrnl import Journal, jrnl
|
from jrnl import jrnl
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
|
import json
|
||||||
|
import StringIO
|
||||||
|
|
||||||
|
def read_journal(journal_name="default"):
|
||||||
|
with open(jrnl.CONFIG_PATH) as config_file:
|
||||||
|
config = json.load(config_file)
|
||||||
|
with open(config['journals'][journal_name]) as journal_file:
|
||||||
|
journal = journal_file.read()
|
||||||
|
return journal
|
||||||
|
|
||||||
@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)
|
jrnl.CONFIG_PATH = os.path.abspath(full_path)
|
||||||
|
|
||||||
|
@when('we run "{command}" and enter')
|
||||||
|
@when('we run "{command}" and enter "{inputs}"')
|
||||||
|
def run_with_input(context, command, inputs=None):
|
||||||
|
text = inputs or context.text
|
||||||
|
args = command.split()[1:]
|
||||||
|
buffer = StringIO.StringIO(text.strip())
|
||||||
|
jrnl.util.STDIN = buffer
|
||||||
|
jrnl.cli(args)
|
||||||
|
|
||||||
@when('we run "{command}"')
|
@when('we run "{command}"')
|
||||||
def run(context, command):
|
def run(context, command):
|
||||||
args = command.split()[1:]
|
args = command.split()[1:]
|
||||||
jrnl.cli(args)
|
jrnl.cli(args or None)
|
||||||
|
|
||||||
|
|
||||||
@then('we should get no error')
|
@then('we should get no error')
|
||||||
def no_error(context):
|
def no_error(context):
|
||||||
|
@ -24,7 +44,14 @@ def check_output(context):
|
||||||
assert line_text.strip() == line_out.strip()
|
assert line_text.strip() == line_out.strip()
|
||||||
|
|
||||||
@then('the output should contain "{text}"')
|
@then('the output should contain "{text}"')
|
||||||
def check_output(context, text):
|
def check_output_inline(context, text):
|
||||||
out = context.stdout_capture.getvalue()
|
out = context.stdout_capture.getvalue()
|
||||||
print out
|
print out
|
||||||
assert text in out
|
assert text in out
|
||||||
|
|
||||||
|
@then('the journal should contain "{text}"')
|
||||||
|
@then('journal {journal_name} should contain "{text}"')
|
||||||
|
def check_journal_content(context, text, journal_name="default"):
|
||||||
|
journal = read_journal(journal_name)
|
||||||
|
assert text in journal
|
||||||
|
|
||||||
|
|
|
@ -149,8 +149,6 @@ def cli(manual_args=None):
|
||||||
mode_compose, mode_export = guess_mode(args, config)
|
mode_compose, mode_export = guess_mode(args, config)
|
||||||
|
|
||||||
# open journal file or folder
|
# open journal file or folder
|
||||||
|
|
||||||
|
|
||||||
if os.path.isdir(config['journal']) and ( config['journal'].endswith(".dayone") or \
|
if os.path.isdir(config['journal']) and ( config['journal'].endswith(".dayone") or \
|
||||||
config['journal'].endswith(".dayone/")):
|
config['journal'].endswith(".dayone/")):
|
||||||
journal = Journal.DayOne(**config)
|
journal = Journal.DayOne(**config)
|
||||||
|
|
10
jrnl/util.py
10
jrnl/util.py
|
@ -4,14 +4,14 @@ import sys
|
||||||
import os
|
import os
|
||||||
from tzlocal import get_localzone
|
from tzlocal import get_localzone
|
||||||
|
|
||||||
|
STDIN = sys.stdin
|
||||||
|
STDOUT = sys.stdout
|
||||||
|
|
||||||
__cached_tz = None
|
__cached_tz = None
|
||||||
|
|
||||||
def py23_input(msg):
|
def py23_input(msg):
|
||||||
if sys.version_info[0] == 3:
|
STDOUT.write(msg)
|
||||||
try: return input(msg)
|
return STDIN.readline().strip()
|
||||||
except SyntaxError: return ""
|
|
||||||
else:
|
|
||||||
return raw_input(msg)
|
|
||||||
|
|
||||||
def get_local_timezone():
|
def get_local_timezone():
|
||||||
"""Returns the Olson identifier of the local timezone.
|
"""Returns the Olson identifier of the local timezone.
|
||||||
|
|
|
@ -1,33 +0,0 @@
|
||||||
#!/usr/bin/env python
|
|
||||||
# encoding: utf-8
|
|
||||||
|
|
||||||
import unittest
|
|
||||||
|
|
||||||
class TestClasses(unittest.TestCase):
|
|
||||||
"""Test the behavior of the classes.
|
|
||||||
|
|
||||||
tests related to the Journal and the Entry Classes which can
|
|
||||||
be tested withouth command-line interaction
|
|
||||||
"""
|
|
||||||
|
|
||||||
def setUp(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def test_colon_in_textbody(self):
|
|
||||||
"""colons should not cause problems in the text body"""
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class TestCLI(unittest.TestCase):
|
|
||||||
"""test the command-line interaction part of the program"""
|
|
||||||
|
|
||||||
def setUp(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def test_something(self):
|
|
||||||
"""first test"""
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
unittest.main()
|
|
Loading…
Add table
Reference in a new issue