mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-10 16:48:31 +02:00
Merge 59049a87f0
into cd48d4e41d
This commit is contained in:
commit
7c4364f12b
2 changed files with 42 additions and 9 deletions
18
jrnl.py
18
jrnl.py
|
@ -323,17 +323,8 @@ class Journal:
|
||||||
def new_entry(self, raw, date=None):
|
def new_entry(self, raw, date=None):
|
||||||
"""Constructs a new entry from some raw text input.
|
"""Constructs a new entry from some raw text input.
|
||||||
If a date is given, it will parse and use this, otherwise scan for a date in the input first."""
|
If a date is given, it will parse and use this, otherwise scan for a date in the input first."""
|
||||||
if not date:
|
|
||||||
if raw.find(":") > 0:
|
|
||||||
date = self.parse_date(raw[:raw.find(":")])
|
|
||||||
if date: # Parsed successfully, strip that from the raw text
|
|
||||||
raw = raw[raw.find(":")+1:].strip()
|
|
||||||
|
|
||||||
if not date: # Still nothing? Meh, just live in the moment.
|
|
||||||
date = self.parse_date("now")
|
|
||||||
|
|
||||||
# Split raw text into title and body
|
# Split raw text into title and body
|
||||||
body = ""
|
|
||||||
title_end = len(raw)
|
title_end = len(raw)
|
||||||
for separator in ".?!":
|
for separator in ".?!":
|
||||||
sep_pos = raw.find(separator)
|
sep_pos = raw.find(separator)
|
||||||
|
@ -341,6 +332,15 @@ class Journal:
|
||||||
title_end = sep_pos
|
title_end = sep_pos
|
||||||
title = raw[:title_end+1]
|
title = raw[:title_end+1]
|
||||||
body = raw[title_end+1:].strip()
|
body = raw[title_end+1:].strip()
|
||||||
|
|
||||||
|
if not date:
|
||||||
|
if title.find(":") > 0:
|
||||||
|
date = self.parse_date(title[:title.find(":")])
|
||||||
|
if date: # Parsed successfully, strip that from the raw text
|
||||||
|
title = title[title.find(":")+1:].strip()
|
||||||
|
if not date: # Still nothing? Meh, just live in the moment.
|
||||||
|
date = self.parse_date("now")
|
||||||
|
|
||||||
self.entries.append(Entry(self, date, title, body))
|
self.entries.append(Entry(self, date, title, body))
|
||||||
self.sort()
|
self.sort()
|
||||||
|
|
||||||
|
|
33
test_jrnl.py
Normal file
33
test_jrnl.py
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
#!/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