From 6406cfb65124dcb8bf59deb2913375ed8dc518a0 Mon Sep 17 00:00:00 2001 From: Mike Crute Date: Fri, 5 Feb 2010 14:31:34 -0500 Subject: Fixing tags that where bleeding over into category --- kronos/parser.py | 9 ++++----- kronos/tests/test_parser.py | 39 ++++++++------------------------------- 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 def parse_activity(text): + tokens = text.split(' ') + tags = _parse_tags(tokens) + text = _strip_tags(tokens) + description = None - tags = [] if ',' in text: text, description = text.split(',', 1) description = description.strip() - tokens = description.split(' ') - tags = _parse_tags(tokens) - description = _strip_tags(tokens) - category = None if '@' in text: 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): class TestWhenParsingWithTags(object): - def setup(self): - test_input = "my activity@Home, Some cool stuff! #tag1 #tag2" - self.results = parse_activity(test_input) - def test_should_get_tags(self): - assert_equals(self.results.tags, ['tag1', 'tag2']) + test = parse_activity("my activity@Home, Some cool stuff! #tag1 #tag2") + assert_equals(test.tags, ['tag1', 'tag2']) def test_should_not_include_tags_in_description(self): - assert_equals(self.results.description, "Some cool stuff!") - - -# TODO: Implement this functionality when I need it. -class TestWhenParsingWithTimeOffset(object): - - def test_should_understand_minutes(self): - test_input = "my activity@Home, Some cool stuff! 10m" - test_input = "my activity@Home, Some cool stuff! 10M" - - def test_should_understand_hours(self): - test_input = "my activity@Home, Some cool stuff! 10h" - test_input = "my activity@Home, Some cool stuff! 10H" - - def test_should_understand_seconds(self): - test_input = "my activity@Home, Some cool stuff! 10s" - test_input = "my activity@Home, Some cool stuff! 10S" - - -class TestWhenParsingWithAbsoluteTime(object): - - def test_should_understand_military_time(self): - test_input = "my activity@Home, Some cool stuff! 11:30-14:40" + test = parse_activity("my activity@Home, Some cool stuff! #tag1 #tag2") + assert_equals(test.description, "Some cool stuff!") - def test_should_understand_simple_time(self): - test_input = "my activity@Home, Some cool stuff! 11:30AM-2:40PM" - test_input = "my activity@Home, Some cool stuff! 11:30A-2:40P" + def test_should_not_include_tags_in_category(self): + test = parse_activity("my activity@Home #tag1 #tag2") + assert_equals(test.tags, ['tag1', 'tag2']) + assert_equals(test.category, 'Home') -- cgit v1.2.3