mirror of
https://github.com/GothenburgBitFactory/timewarrior.git
synced 2025-07-07 20:06:39 +02:00
TI-68: Add tests for modifying synthetic intervals
This commit is contained in:
parent
a5dc0cd385
commit
33e0cd185d
4 changed files with 231 additions and 6 deletions
|
@ -29,7 +29,7 @@
|
|||
import sys
|
||||
import os
|
||||
import unittest
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timedelta
|
||||
# Ensure python finds the local simpletap module
|
||||
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
|
||||
|
||||
|
@ -68,6 +68,42 @@ class TestLengthen(TestCase):
|
|||
code, out, err = self.t.runError("lengthen @1 10mins")
|
||||
self.assertIn('Cannot lengthen open interval @1', err)
|
||||
|
||||
def test_lengthen_synthetic_interval(self):
|
||||
"""Lengthen a synthetic interval."""
|
||||
now = datetime.now()
|
||||
now_utc = now.utcnow()
|
||||
|
||||
three_hours_before = now - timedelta(hours=3)
|
||||
four_hours_before = now - timedelta(hours=4)
|
||||
five_hours_before = now - timedelta(hours=5)
|
||||
|
||||
exclusion = "{:%H}:00-{:%H}:00".format(four_hours_before, three_hours_before)
|
||||
|
||||
self.t.config("exclusions.friday", exclusion)
|
||||
self.t.config("exclusions.thursday", exclusion)
|
||||
self.t.config("exclusions.wednesday", exclusion)
|
||||
self.t.config("exclusions.tuesday", exclusion)
|
||||
self.t.config("exclusions.monday", exclusion)
|
||||
self.t.config("exclusions.sunday", exclusion)
|
||||
self.t.config("exclusions.saturday", exclusion)
|
||||
|
||||
self.t("start {}T{:%H}:45:00".format(now.date(), five_hours_before))
|
||||
|
||||
self.t("lengthen @2 5min")
|
||||
|
||||
j = self.t.export()
|
||||
|
||||
self.assertEqual(len(j), 2)
|
||||
self.assertTrue('start' in j[0])
|
||||
self.assertEqual(j[0]['start'], '{:%Y%m%dT%H}4500Z'.format(now_utc-timedelta(hours=5)), 'start time of lengthened interval does not match')
|
||||
self.assertTrue('end' in j[0])
|
||||
self.assertEqual(j[0]['end'], '{:%Y%m%dT%H}0500Z'.format(now_utc - timedelta(hours=4)), 'end time of lengthened interval does not match')
|
||||
self.assertFalse('tags' in j[0])
|
||||
self.assertTrue('start' in j[1])
|
||||
self.assertEqual(j[1]['start'], '{:%Y%m%dT%H}0000Z'.format(now_utc - timedelta(hours=3)), 'start time of unmodified interval does not match')
|
||||
self.assertFalse('end' in j[1])
|
||||
self.assertFalse('tags' in j[1])
|
||||
|
||||
# TODO Add :adjust tests.
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
76
test/move.t
76
test/move.t
|
@ -29,7 +29,7 @@
|
|||
import sys
|
||||
import os
|
||||
import unittest
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timedelta
|
||||
# Ensure python finds the local simpletap module
|
||||
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
|
||||
|
||||
|
@ -129,6 +129,80 @@ class TestMove(TestCase):
|
|||
ends = [str(x['end']) for x in self.t.export()]
|
||||
self.assertNotIn('20170301T140000Z', ends)
|
||||
|
||||
def test_move_synthetic_interval_into_exclusion(self):
|
||||
"""Move a synthetic interval into exclusion"""
|
||||
now = datetime.now()
|
||||
now_utc = now.utcnow()
|
||||
|
||||
three_hours_before = now - timedelta(hours=3)
|
||||
four_hours_before = now - timedelta(hours=4)
|
||||
five_hours_before = now - timedelta(hours=5)
|
||||
|
||||
exclusion = "{:%H}:00-{:%H}:00".format(four_hours_before, three_hours_before)
|
||||
|
||||
self.t.config("exclusions.friday", exclusion)
|
||||
self.t.config("exclusions.thursday", exclusion)
|
||||
self.t.config("exclusions.wednesday", exclusion)
|
||||
self.t.config("exclusions.tuesday", exclusion)
|
||||
self.t.config("exclusions.monday", exclusion)
|
||||
self.t.config("exclusions.sunday", exclusion)
|
||||
self.t.config("exclusions.saturday", exclusion)
|
||||
|
||||
self.t("start {}T{:%H}:45:00".format(now.date(), five_hours_before))
|
||||
|
||||
self.t("move @2 {}T{:%H}:50:00".format(now.date(), five_hours_before))
|
||||
|
||||
j = self.t.export()
|
||||
|
||||
self.assertEqual(len(j), 2)
|
||||
self.assertTrue('start' in j[0])
|
||||
self.assertEqual(j[0]['start'], '{:%Y%m%dT%H}5000Z'.format(now_utc-timedelta(hours=5)), 'start time of lengthened interval does not match')
|
||||
self.assertTrue('end' in j[0])
|
||||
self.assertEqual(j[0]['end'], '{:%Y%m%dT%H}0500Z'.format(now_utc - timedelta(hours=4)), 'end time of lengthened interval does not match')
|
||||
self.assertFalse('tags' in j[0])
|
||||
self.assertTrue('start' in j[1])
|
||||
self.assertEqual(j[1]['start'], '{:%Y%m%dT%H}0000Z'.format(now_utc - timedelta(hours=3)), 'start time of unmodified interval does not match')
|
||||
self.assertFalse('end' in j[1])
|
||||
self.assertFalse('tags' in j[1])
|
||||
|
||||
def test_move_synthetic_interval_away_from_exclusion(self):
|
||||
"""Move a synthetic interval away from exclusion"""
|
||||
now = datetime.now()
|
||||
now_utc = now.utcnow()
|
||||
|
||||
three_hours_before = now - timedelta(hours=3)
|
||||
four_hours_before = now - timedelta(hours=4)
|
||||
five_hours_before = now - timedelta(hours=5)
|
||||
|
||||
exclusion = "{:%H}:00-{:%H}:00".format(four_hours_before, three_hours_before)
|
||||
|
||||
self.t.config("exclusions.friday", exclusion)
|
||||
self.t.config("exclusions.thursday", exclusion)
|
||||
self.t.config("exclusions.wednesday", exclusion)
|
||||
self.t.config("exclusions.tuesday", exclusion)
|
||||
self.t.config("exclusions.monday", exclusion)
|
||||
self.t.config("exclusions.sunday", exclusion)
|
||||
self.t.config("exclusions.saturday", exclusion)
|
||||
|
||||
self.t("start {}T{:%H}:45:00".format(now.date(), five_hours_before))
|
||||
|
||||
self.t("move @2 {}T{:%H}:40:00".format(now.date(), five_hours_before))
|
||||
|
||||
j = self.t.export()
|
||||
|
||||
self.assertEqual(len(j), 2)
|
||||
self.assertTrue('start' in j[0])
|
||||
self.assertEqual(j[0]['start'], '{:%Y%m%dT%H}4000Z'.format(now_utc-timedelta(hours=5)), 'start time of lengthened interval does not match')
|
||||
self.assertTrue('end' in j[0])
|
||||
self.assertEqual(j[0]['end'], '{:%Y%m%dT%H}5500Z'.format(now_utc - timedelta(hours=5)), 'end time of lengthened interval does not match')
|
||||
self.assertFalse('tags' in j[0])
|
||||
self.assertTrue('start' in j[1])
|
||||
self.assertEqual(j[1]['start'], '{:%Y%m%dT%H}0000Z'.format(now_utc - timedelta(hours=3)), 'start time of unmodified interval does not match')
|
||||
self.assertFalse('end' in j[1])
|
||||
self.assertFalse('tags' in j[1])
|
||||
|
||||
|
||||
|
||||
# TODO Add :adjust tests.
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
import sys
|
||||
import os
|
||||
import unittest
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timedelta
|
||||
# Ensure python finds the local simpletap module
|
||||
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
|
||||
|
||||
|
@ -84,8 +84,44 @@ class TestShorten(TestCase):
|
|||
self.t("move @1 20170308T113000")
|
||||
self.t("shorten @1 5min") # Does not work.
|
||||
|
||||
# TODO Add :adjust tests.
|
||||
def test_shorten_synthetic_interval(self):
|
||||
"""Shorten a synthetic interval."""
|
||||
now = datetime.now()
|
||||
now_utc = now.utcnow()
|
||||
|
||||
three_hours_before = now - timedelta(hours=3)
|
||||
four_hours_before = now - timedelta(hours=4)
|
||||
five_hours_before = now - timedelta(hours=5)
|
||||
|
||||
exclusion = "{:%H}:00-{:%H}:00".format(four_hours_before, three_hours_before)
|
||||
|
||||
self.t.config("exclusions.friday", exclusion)
|
||||
self.t.config("exclusions.thursday", exclusion)
|
||||
self.t.config("exclusions.wednesday", exclusion)
|
||||
self.t.config("exclusions.tuesday", exclusion)
|
||||
self.t.config("exclusions.monday", exclusion)
|
||||
self.t.config("exclusions.sunday", exclusion)
|
||||
self.t.config("exclusions.saturday", exclusion)
|
||||
|
||||
self.t("start {}T{:%H}:45:00".format(now.date(), five_hours_before))
|
||||
|
||||
self.t("shorten @2 5min")
|
||||
|
||||
j = self.t.export()
|
||||
|
||||
self.assertEqual(len(j), 2)
|
||||
self.assertTrue('start' in j[0])
|
||||
self.assertEqual(j[0]['start'], '{:%Y%m%dT%H}4500Z'.format(now_utc - timedelta(hours=5)), 'start time of lengthened interval does not match')
|
||||
self.assertTrue('end' in j[0])
|
||||
self.assertEqual(j[0]['end'], '{:%Y%m%dT%H}5500Z'.format(now_utc - timedelta(hours=5)), 'end time of lengthened interval does not match')
|
||||
self.assertFalse('tags' in j[0])
|
||||
self.assertTrue('start' in j[1])
|
||||
self.assertEqual(j[1]['start'], '{:%Y%m%dT%H}0000Z'.format(now_utc - timedelta(hours=3)), 'start time of unmodified interval does not match')
|
||||
self.assertFalse('end' in j[1])
|
||||
self.assertFalse('tags' in j[1])
|
||||
|
||||
|
||||
# TODO Add :adjust tests.
|
||||
class TestBug6(TestCase):
|
||||
def setUp(self):
|
||||
"""Executed before each test in the class"""
|
||||
|
|
81
test/tag.t
81
test/tag.t
|
@ -29,7 +29,7 @@
|
|||
import sys
|
||||
import os
|
||||
import unittest
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timedelta
|
||||
# Ensure python finds the local simpletap module
|
||||
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
|
||||
|
||||
|
@ -94,6 +94,46 @@ class TestTag(TestCase):
|
|||
code, out, err = self.t("tag @1 @2 foo bar")
|
||||
self.assertIn('Added foo bar to @1\nAdded foo bar to @2', out)
|
||||
|
||||
def test_tag_synthetic_interval(self):
|
||||
"""Tag a synthetic interval."""
|
||||
now = datetime.now()
|
||||
now_utc = now.utcnow()
|
||||
|
||||
three_hours_before = now - timedelta(hours=3)
|
||||
four_hours_before = now - timedelta(hours=4)
|
||||
five_hours_before = now - timedelta(hours=5)
|
||||
|
||||
exclusion = "{:%H}:00-{:%H}:00".format(four_hours_before, three_hours_before)
|
||||
|
||||
self.t.config("exclusions.friday", exclusion)
|
||||
self.t.config("exclusions.thursday", exclusion)
|
||||
self.t.config("exclusions.wednesday", exclusion)
|
||||
self.t.config("exclusions.tuesday", exclusion)
|
||||
self.t.config("exclusions.monday", exclusion)
|
||||
self.t.config("exclusions.sunday", exclusion)
|
||||
self.t.config("exclusions.saturday", exclusion)
|
||||
|
||||
self.t("start {}T{:%H}:45:00 foo".format(now.date(), five_hours_before))
|
||||
|
||||
self.t("tag @2 bar")
|
||||
|
||||
j = self.t.export()
|
||||
|
||||
self.assertEqual(len(j), 2)
|
||||
self.assertTrue('start' in j[0])
|
||||
self.assertEqual(j[0]['start'], '{:%Y%m%dT%H}4500Z'.format(now_utc-timedelta(hours=5)), 'start time of modified interval does not match')
|
||||
self.assertTrue('end' in j[0])
|
||||
self.assertEqual(j[0]['end'], '{:%Y%m%dT%H}0000Z'.format(now_utc - timedelta(hours=4)), 'end time of modified interval does not match')
|
||||
self.assertTrue('tags' in j[0])
|
||||
self.assertEqual(j[0]['tags'], ['bar', 'foo'], 'tags of modified interval do not match')
|
||||
self.assertTrue('start' in j[1])
|
||||
self.assertEqual(j[1]['start'], '{:%Y%m%dT%H}0000Z'.format(now_utc - timedelta(hours=3)), 'start time of unmodified interval does not match')
|
||||
self.assertFalse('end' in j[1])
|
||||
self.assertTrue('tags' in j[1])
|
||||
self.assertEqual(j[1]['tags'], ['foo'], 'tags of unmodified interval do not match')
|
||||
|
||||
|
||||
|
||||
class TestUntag(TestCase):
|
||||
def setUp(self):
|
||||
"""Executed before each test in the class"""
|
||||
|
@ -137,6 +177,45 @@ class TestUntag(TestCase):
|
|||
code, out, err = self.t("untag @1 @2 foo bar")
|
||||
self.assertIn('Removed foo bar from @1\nRemoved foo bar from @2', out)
|
||||
|
||||
def test_untag_synthetic_interval(self):
|
||||
"""Untag a synthetic interval."""
|
||||
now = datetime.now()
|
||||
now_utc = now.utcnow()
|
||||
|
||||
three_hours_before = now - timedelta(hours=3)
|
||||
four_hours_before = now - timedelta(hours=4)
|
||||
five_hours_before = now - timedelta(hours=5)
|
||||
|
||||
exclusion = "{:%H}:00-{:%H}:00".format(four_hours_before, three_hours_before)
|
||||
|
||||
self.t.config("exclusions.friday", exclusion)
|
||||
self.t.config("exclusions.thursday", exclusion)
|
||||
self.t.config("exclusions.wednesday", exclusion)
|
||||
self.t.config("exclusions.tuesday", exclusion)
|
||||
self.t.config("exclusions.monday", exclusion)
|
||||
self.t.config("exclusions.sunday", exclusion)
|
||||
self.t.config("exclusions.saturday", exclusion)
|
||||
|
||||
self.t("start {}T{:%H}:45:00 foo bar".format(now.date(), five_hours_before))
|
||||
|
||||
self.t("untag @2 foo")
|
||||
|
||||
j = self.t.export()
|
||||
|
||||
self.assertEqual(len(j), 2)
|
||||
self.assertTrue('start' in j[0])
|
||||
self.assertEqual(j[0]['start'], '{:%Y%m%dT%H}4500Z'.format(now_utc-timedelta(hours=5)), 'start time of modified interval does not match')
|
||||
self.assertTrue('end' in j[0])
|
||||
self.assertEqual(j[0]['end'], '{:%Y%m%dT%H}0000Z'.format(now_utc - timedelta(hours=4)), 'end time of modified interval does not match')
|
||||
self.assertTrue('tags' in j[0])
|
||||
self.assertEqual(j[0]['tags'], ['bar'], 'tags of modified interval do not match')
|
||||
self.assertTrue('start' in j[1])
|
||||
self.assertEqual(j[1]['start'], '{:%Y%m%dT%H}0000Z'.format(now_utc - timedelta(hours=3)), 'start time of unmodified interval does not match')
|
||||
self.assertFalse('end' in j[1])
|
||||
self.assertTrue('tags' in j[1])
|
||||
self.assertEqual(j[1]['tags'], ['bar', 'foo'], 'tags of unmodified interval do not match')
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
from simpletap import TAPTestRunner
|
||||
unittest.main(testRunner=TAPTestRunner())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue