Skip to content

Commit

Permalink
test head and tail range position
Browse files Browse the repository at this point in the history
  • Loading branch information
ederag committed Dec 9, 2019
1 parent 08d76fb commit b890717
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
8 changes: 6 additions & 2 deletions src/hamster/lib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,17 @@ def serialized_range(self, default_day=None):
time_str = "{} - {}".format(time_str, end_time_str)
return time_str

def serialized(self, default_day=None):
def serialized(self, range_pos="head", default_day=None):
"""Return a string fully representing the fact."""
name = self.serialized_name()
datetime = self.serialized_range(default_day)
# no need for space if name or datetime is missing
space = " " if name and datetime else ""
return "{}{}{}".format(datetime, space, name)
assert range_pos in ("head", "tail")
if range_pos == "head":
return "{}{}{}".format(datetime, space, name)
else:
return "{}{}{}".format(name, space, datetime)

def _set(self, **kwds):
"""Modify attributes.
Expand Down
15 changes: 8 additions & 7 deletions tests/stuff_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,13 +248,14 @@ def test_roundtrips(self):
category=category,
description=description,
tags=tags)
fact_str = fact.serialized()
parsed = Fact.parse(fact_str)
self.assertEqual(fact, parsed)
self.assertEqual(parsed.activity, fact.activity)
self.assertEqual(parsed.category, fact.category)
self.assertEqual(parsed.description, fact.description)
self.assertEqual(parsed.tags, fact.tags)
for range_pos in ("head", "tail"):
fact_str = fact.serialized(range_pos=range_pos)
parsed = Fact.parse(fact_str, range_pos=range_pos)
self.assertEqual(fact, parsed)
self.assertEqual(parsed.activity, fact.activity)
self.assertEqual(parsed.category, fact.category)
self.assertEqual(parsed.description, fact.description)
self.assertEqual(parsed.tags, fact.tags)


class TestParsers(unittest.TestCase):
Expand Down

0 comments on commit b890717

Please sign in to comment.