summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Crute <mcrute@gmail.com>2010-02-05 14:31:34 -0500
committerMike Crute <mcrute@gmail.com>2010-02-05 14:31:34 -0500
commit6406cfb65124dcb8bf59deb2913375ed8dc518a0 (patch)
treecbe9b38286cc57496b7e6718af21a9ed644eb5f9
parent4f7c446b853e333caaf1b28b668ffbc1b011b78f (diff)
downloadkronos-6406cfb65124dcb8bf59deb2913375ed8dc518a0.tar.bz2
kronos-6406cfb65124dcb8bf59deb2913375ed8dc518a0.tar.xz
kronos-6406cfb65124dcb8bf59deb2913375ed8dc518a0.zip
Fixing tags that where bleeding over into category
-rw-r--r--kronos/parser.py9
-rw-r--r--kronos/tests/test_parser.py39
2 files changed, 12 insertions, 36 deletions
diff --git a/kronos/parser.py b/kronos/parser.py
index 147682f..cf848e0 100644
--- a/kronos/parser.py
+++ b/kronos/parser.py
@@ -11,16 +11,15 @@ from kronos.model import Activity
11 11
12 12
13def parse_activity(text): 13def parse_activity(text):
14 tokens = text.split(' ')
15 tags = _parse_tags(tokens)
16 text = _strip_tags(tokens)
17
14 description = None 18 description = None
15 tags = []
16 if ',' in text: 19 if ',' in text:
17 text, description = text.split(',', 1) 20 text, description = text.split(',', 1)
18 description = description.strip() 21 description = description.strip()
19 22
20 tokens = description.split(' ')
21 tags = _parse_tags(tokens)
22 description = _strip_tags(tokens)
23
24 category = None 23 category = None
25 if '@' in text: 24 if '@' in text:
26 text, category = text.split('@', 1) 25 text, category = text.split('@', 1)
diff --git a/kronos/tests/test_parser.py b/kronos/tests/test_parser.py
index 8a82a65..b08152a 100644
--- a/kronos/tests/test_parser.py
+++ b/kronos/tests/test_parser.py
@@ -50,38 +50,15 @@ class TestWhenParsingBasicFormat(object):
50 50
51class TestWhenParsingWithTags(object): 51class TestWhenParsingWithTags(object):
52 52
53 def setup(self):
54 test_input = "my activity@Home, Some cool stuff! #tag1 #tag2"
55 self.results = parse_activity(test_input)
56
57 def test_should_get_tags(self): 53 def test_should_get_tags(self):
58 assert_equals(self.results.tags, ['tag1', 'tag2']) 54 test = parse_activity("my activity@Home, Some cool stuff! #tag1 #tag2")
55 assert_equals(test.tags, ['tag1', 'tag2'])
59 56
60 def test_should_not_include_tags_in_description(self): 57 def test_should_not_include_tags_in_description(self):
61 assert_equals(self.results.description, "Some cool stuff!") 58 test = parse_activity("my activity@Home, Some cool stuff! #tag1 #tag2")
62 59 assert_equals(test.description, "Some cool stuff!")
63
64# TODO: Implement this functionality when I need it.
65class TestWhenParsingWithTimeOffset(object):
66
67 def test_should_understand_minutes(self):
68 test_input = "my activity@Home, Some cool stuff! 10m"
69 test_input = "my activity@Home, Some cool stuff! 10M"
70
71 def test_should_understand_hours(self):
72 test_input = "my activity@Home, Some cool stuff! 10h"
73 test_input = "my activity@Home, Some cool stuff! 10H"
74
75 def test_should_understand_seconds(self):
76 test_input = "my activity@Home, Some cool stuff! 10s"
77 test_input = "my activity@Home, Some cool stuff! 10S"
78
79
80class TestWhenParsingWithAbsoluteTime(object):
81
82 def test_should_understand_military_time(self):
83 test_input = "my activity@Home, Some cool stuff! 11:30-14:40"
84 60
85 def test_should_understand_simple_time(self): 61 def test_should_not_include_tags_in_category(self):
86 test_input = "my activity@Home, Some cool stuff! 11:30AM-2:40PM" 62 test = parse_activity("my activity@Home #tag1 #tag2")
87 test_input = "my activity@Home, Some cool stuff! 11:30A-2:40P" 63 assert_equals(test.tags, ['tag1', 'tag2'])
64 assert_equals(test.category, 'Home')