Permalink
Browse files

#21 Add implicit @1 to command 'untag'

- Extend interval assertions
- Add interval assertions to tests for command 'tag'
- Add interval assertions to tests for command 'untag'
  • Loading branch information...
lauft committed May 13, 2018
1 parent c595132 commit 10dfa64cfac60d1c01482eaaf91a7c042ea1f8de
Showing with 184 additions and 64 deletions.
  1. +0 −1 src/commands/CmdTag.cpp
  2. +19 −8 src/commands/CmdUntag.cpp
  3. +50 −7 test/basetest/testing.py
  4. +5 −6 test/delete.t
  5. +110 −42 test/tag.t
@@ -103,7 +103,6 @@ int CmdTag (
//TODO validate (cli, rules, database, i);
database.modifyInterval (tracked[tracked.size () - id], i);

// Feedback.
if (rules.getBoolean ("verbose"))
{
std::cout << "Added " << joinQuotedIfNeeded (" ", tags) << " to @" << id << '\n';
@@ -39,15 +39,11 @@ int CmdUntag (
{
// Gather IDs and TAGs.
std::set <int> ids = cli.getIds ();
std::vector<std::string> tags = cli.getTags ();

if (ids.empty ())
throw std::string ("IDs must be specified. See 'timew help untag'.");

std::vector <std::string> tags;
for (auto& arg : cli._args)
if (tags.empty ())
{
if (arg.hasTag ("TAG"))
tags.push_back (arg.attribute ("raw"));
throw std::string ("At least one tag must be specified. See 'timew help untag'.");
}

// Load the data.
@@ -78,7 +74,22 @@ int CmdUntag (
}
}

// Apply tags to ids.
if (ids.empty ())
{
if (tracked.empty ())
{
throw std::string ("There is no active time tracking.");
}

if (!tracked.back ().range.is_open ())
{
throw std::string ("At least one ID must be specified. See 'timew help tag'.");
}

ids.insert (1);
}

// Remove tags from ids.
for (auto& id : ids)
{
if (id > static_cast <int> (tracked.size ()))
@@ -13,19 +13,62 @@ def tap(self, out):


class TestCase(BaseTestCase):
def assertInterval(self, interval, expectedStart=None, expectedEnd=None, expectedTags=None, description=None):
self.assertTrue('start' in interval)
self.assertTrue('end' in interval)
def assertOpenInterval(self, interval,
expectedStart=None,
expectedTags=None,
description="interval"):
self.assertTrue("start" in interval, "{} does not contain a start date".format(description))
self.assertFalse("end" in interval, "{} does contain an end date".format(description))

return self.assertInterval(interval,
expectedStart=expectedStart,
expectedEnd=None,
expectedTags=expectedTags,
description=description)

def assertClosedInterval(self, interval,
expectedStart=None,
expectedEnd=None,
expectedTags=None,
description="interval"):
self.assertTrue("start" in interval, "{} does not contain a start date".format(description))
self.assertTrue("end" in interval, "{} does not contain an end date".format(description))

return self.assertInterval(interval,
expectedStart=expectedStart,
expectedEnd=expectedEnd,
expectedTags=expectedTags,
description=description)

def assertInterval(self, interval,
expectedStart=None,
expectedEnd=None,
expectedTags=None,
description="interval"):
if expectedStart:
self.assertEqual(interval['start'], expectedStart, description)
self.assertEqual(
interval["start"],
expectedStart,
"start time of {} does not match (expected: {}, actual: {})".format(description,
expectedStart,
interval["start"]))

if expectedEnd:
self.assertEqual(interval['end'], expectedEnd, description)
self.assertEqual(
interval["end"],
expectedEnd,
"end time of {} does not match (expected: {}, actual: {})".format(description,
expectedEnd,
interval["end"]))

if expectedTags:
self.assertTrue('tags' in interval)
self.assertEqual(interval['tags'], expectedTags, description)
self.assertTrue("tags" in interval)
self.assertEqual(
interval["tags"],
expectedTags,
"tags of {} do not match (expected: {}, actual: {})". format(description,
expectedTags,
interval["tags"]))


# vim: ai sts=4 et sw=4
@@ -116,12 +116,11 @@ class TestDelete(TestCase):
j = self.t.export()
print(j)
self.assertEqual(len(j), 1)
self.assertInterval(
j[0],
'{:%Y%m%dT%H}0000Z'.format(now_utc-timedelta(hours=5)),
'{:%Y%m%dT%H}0000Z'.format(now_utc-timedelta(hours=4)),
['foo'],
'remaining interval')
self.assertClosedInterval(j[0],
expectedStart='{:%Y%m%dT%H}0000Z'.format(now_utc-timedelta(hours=5)),
expectedEnd='{:%Y%m%dT%H}0000Z'.format(now_utc-timedelta(hours=4)),
expectedTags=['foo'],
description='remaining interval')


if __name__ == "__main__":
Oops, something went wrong.

0 comments on commit 10dfa64

Please sign in to comment.