def should_accumulate_stats(self): task = TaskWarrior() task.start('foo', now=datetime.datetime(2021, 12, 31, 8, 0, 0)) task.start('bar', now=datetime.datetime(2021, 12, 31, 8, 2, 0)) task.stop(now=datetime.datetime(2021, 12, 31, 8, 5, 0)) task.start(now=datetime.datetime(2021, 12, 31, 8, 7, 0)) task.start('foo', now=datetime.datetime(2021, 12, 31, 8, 8, 0)) self.assertEqual([(_.passed.total_seconds()/60, _.title) for _ in task.accumulate_stats( stop_datetime=datetime.datetime(2021, 12, 31, 8, 30, 0), )], [ (4, 'bar'), (24, 'foo'), ]) task.rewrite_history( datetime.datetime(2021, 12, 31, 8, 5, 0), datetime.datetime(2021, 12, 31, 8, 7, 0), ['bar', 'bar'] ) self.assertEqual([(_.passed.total_seconds()/60, _.title) for _ in task.accumulate_stats( stop_datetime=datetime.datetime(2021, 12, 31, 8, 30, 0), )], [ (6, 'bar'), (24, 'foo'), ]) task.start('foo', now=datetime.datetime(2021, 12, 31, 8, 10, 0)) self.assertEqual([(_.passed.total_seconds()/60, _.title) for _ in task.accumulate_stats( stop_datetime=datetime.datetime(2021, 12, 31, 8, 30, 0), )], [ (6, 'bar'), (24, 'foo'), ])
def should_rewrite_task_history_with_fill_value(self): task = TaskWarrior(Config(separator='__')) task.start('foo', now=datetime.datetime(2021, 12, 31, 8, 0, 0)) task.start('bar', now=datetime.datetime(2021, 12, 31, 8, 1, 0)) task.stop(now=datetime.datetime(2021, 12, 31, 8, 2, 0)) task.start(now=datetime.datetime(2021, 12, 31, 8, 3, 0)) task.start('foo', now=datetime.datetime(2021, 12, 31, 8, 4, 0)) task.rewrite_history( datetime.datetime(2021, 12, 31, 8, 2, 0), datetime.datetime(2021, 12, 31, 8, 3, 0), ['foo'], fill_value='baz' ) self.assertEqual([_.title for _ in task.get_history()], [ 'foo', 'bar', 'foo', 'baz', 'foo', ])
def should_squeeze_consequent_stats(self): task = TaskWarrior() task.start('foo', now=datetime.datetime(2021, 12, 31, 8, 0, 0)) task.start('bar', now=datetime.datetime(2021, 12, 31, 8, 2, 0)) task.stop(now=datetime.datetime(2021, 12, 31, 8, 5, 0)) task.start(now=datetime.datetime(2021, 12, 31, 8, 7, 0)) task.start('foo', now=datetime.datetime(2021, 12, 31, 8, 8, 0)) self.assertEqual([(_.passed.total_seconds()/60, _.title) for _ in task.get_stats( stop_datetime=datetime.datetime(2021, 12, 31, 8, 30, 0), squeeze=True, )], [ (2, 'foo'), (3, 'bar'), (1, 'bar'), (22, 'foo'), ]) task.rewrite_history( datetime.datetime(2021, 12, 31, 8, 5, 0), datetime.datetime(2021, 12, 31, 8, 7, 0), ['bar', 'bar'] ) self.assertEqual([(_.passed.total_seconds()/60, _.title) for _ in task.get_stats( stop_datetime=datetime.datetime(2021, 12, 31, 8, 30, 0), squeeze=True, )], [ (2, 'foo'), (6, 'bar'), (22, 'foo'), ]) task.start('foo', now=datetime.datetime(2021, 12, 31, 8, 10, 0)) self.assertEqual([(_.passed.total_seconds()/60, _.title) for _ in task.get_stats( stop_datetime=datetime.datetime(2021, 12, 31, 8, 30, 0), squeeze=True, )], [ (2, 'foo'), (6, 'bar'), (22, 'foo'), ])
def should_rewrite_task_history_automatically(self): task = TaskWarrior(Config(separator='__')) task.start('foo', now=datetime.datetime(2021, 12, 31, 8, 0, 0)) task.start('bar', now=datetime.datetime(2021, 12, 31, 8, 1, 0)) task.stop(now=datetime.datetime(2021, 12, 31, 8, 2, 0)) task.start(now=datetime.datetime(2021, 12, 31, 8, 3, 0)) task.start('foo', now=datetime.datetime(2021, 12, 31, 8, 4, 0)) with self.assertRaises(RuntimeError): task.rewrite_history( datetime.datetime(2021, 12, 31, 8, 2, 0), datetime.datetime(2021, 12, 31, 8, 3, 0), ['baz', 'baz', 'excessive'], ) with self.assertRaises(RuntimeError): task.rewrite_history( datetime.datetime(2021, 12, 31, 8, 2, 0), datetime.datetime(2021, 12, 31, 8, 3, 0), ['not enough values'], ) task.rewrite_history( datetime.datetime(2021, 12, 31, 8, 2, 0), datetime.datetime(2021, 12, 31, 8, 3, 0), ['baz', 'baz'], ) self.assertEqual([_.title for _ in task.get_history()], [ 'foo', 'bar', 'baz', 'baz', 'foo', ]) task.rewrite_history( datetime.datetime(2021, 12, 31, 8, 2, 0), datetime.datetime(2021, 12, 31, 8, 3, 0), ['foo', None], ) self.assertEqual([_.title for _ in task.get_history()], [ 'foo', 'bar', 'foo', None, 'foo', ])