Tests for parsing DayOne entries without Timezone

This commit is contained in:
Manuel Ebert 2013-08-17 13:19:54 -07:00
parent 552d2a00ff
commit 2a981d51e2
3 changed files with 22 additions and 7 deletions

View file

@ -3,7 +3,7 @@
<plist version="1.0">
<dict>
<key>Creation Date</key>
<date>2013-08-17T18:37:50Z</date>
<date>2013-01-17T18:37:50Z</date>
<key>Creator</key>
<dict>
<key>Device Agent</key>
@ -18,7 +18,7 @@
<string>Day One (Mac)/1.8</string>
</dict>
<key>Entry Text</key>
<string>This is a DayOne entry.</string>
<string>This is a DayOne entry without Timezone.</string>
<key>Starred</key>
<false/>
<key>Tags</key>

View file

@ -2,7 +2,7 @@ Feature: DayOne Ingetration
Scenario: Loading a DayOne Journal
Given we use the config "dayone.json"
When we run "jrnl -until now"
When we run "jrnl -from 'feb 2013'"
Then we should get no error
and the output should be
"""
@ -11,10 +11,14 @@ Feature: DayOne Ingetration
2013-06-17 20:38 This entry has a location.
2013-07-17 11:38 This entry is starred!
2013-08-17 11:37 This is a DayOne entry.
"""
Scenario: Entries without timezone information will be intepreted in the current timezone
Given we use the config "dayone.json"
When we run "jrnl -until 'feb 2013'"
Then we should get no error
and the output should contain "2013-01-17T18:37Z" in the local time
Scenario: Writing into Dayone
Given we use the config "dayone.json"
When we run "jrnl 01 may 1979: Being born hurts."

View file

@ -1,8 +1,10 @@
from behave import *
from jrnl import jrnl, Journal
from jrnl import jrnl, Journal, util
from dateutil import parser as date_parser
import os
import sys
import json
import pytz
try:
from io import StringIO
except ImportError:
@ -73,7 +75,7 @@ def check_output_json(context):
def check_output_field(context, field, number=1):
out = context.stdout_capture.getvalue()
out_json = json.loads(out)
assert field in out_json [field, out_json]
assert field in out_json, [field, out_json]
assert len(out_json[field]) == number, len(out_json[field])
@then('"{field}" in the json output should not contain "{key}"')
@ -97,6 +99,15 @@ def check_output(context):
for line_text, line_out in zip(text, out):
assert line_text.strip() == line_out.strip(), [line_text.strip(), line_out.strip()]
@then('the output should contain "{text}" in the local time')
def check_output_time_inline(context, text):
out = context.stdout_capture.getvalue()
local_tz = pytz.timezone(util.get_local_timezone())
utc_time = date_parser.parse(text)
date = utc_time + local_tz._utcoffset
local_date = date.strftime("%Y-%m-%d %H:%M")
assert local_date in out, local_date
@then('the output should contain "{text}"')
def check_output_inline(context, text):
out = context.stdout_capture.getvalue()