mirror of
https://github.com/GothenburgBitFactory/timewarrior.git
synced 2025-06-26 10:54:28 +02:00
Update tests
This commit is contained in:
parent
9b5793206f
commit
7771d94dee
4 changed files with 118 additions and 30 deletions
30
test/start.t
30
test/start.t
|
@ -30,7 +30,7 @@ import os
|
||||||
import sys
|
import sys
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from datetime import time
|
from datetime import datetime, timedelta, time
|
||||||
|
|
||||||
# Ensure python finds the local simpletap module
|
# Ensure python finds the local simpletap module
|
||||||
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
|
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
|
||||||
|
@ -192,6 +192,34 @@ class TestStart(TestCase):
|
||||||
self.assertIn('1150Z', j[1]['start'])
|
self.assertIn('1150Z', j[1]['start'])
|
||||||
self.assertIn('4422Z', j[1]['end'])
|
self.assertIn('4422Z', j[1]['end'])
|
||||||
|
|
||||||
|
def test_start_with_new_tag(self):
|
||||||
|
"""Call 'start' with new tag"""
|
||||||
|
now_utc = datetime.now().utcnow()
|
||||||
|
|
||||||
|
two_hours_before_utc = now_utc - timedelta(hours=2)
|
||||||
|
one_hour_before_utc = now_utc - timedelta(hours=1)
|
||||||
|
|
||||||
|
self.t("track {:%Y-%m-%dT%H:%M:%S} - {:%Y-%m-%dT%H:%M:%S} foo".format(two_hours_before_utc, one_hour_before_utc))
|
||||||
|
code, out, err = self.t("start {:%Y-%m-%dT%H:%M:%S} bar".format(now_utc))
|
||||||
|
|
||||||
|
self.assertIn("Note: 'bar' is a new tag", out)
|
||||||
|
self.assertIn("Tracking bar", out)
|
||||||
|
|
||||||
|
def test_start_with_previous_tag(self):
|
||||||
|
"""Call 'start' with previous tag"""
|
||||||
|
now_utc = datetime.now().utcnow()
|
||||||
|
|
||||||
|
three_hours_before_utc = now_utc - timedelta(hours=3)
|
||||||
|
two_hours_before_utc = now_utc - timedelta(hours=2)
|
||||||
|
one_hour_before_utc = now_utc - timedelta(hours=1)
|
||||||
|
|
||||||
|
self.t("track {:%Y-%m-%dT%H:%M:%S} - {:%Y-%m-%dT%H:%M:%S} bar".format(three_hours_before_utc, two_hours_before_utc))
|
||||||
|
self.t("track {:%Y-%m-%dT%H:%M:%S} - {:%Y-%m-%dT%H:%M:%S} foo".format(two_hours_before_utc, one_hour_before_utc))
|
||||||
|
code, out, err = self.t("start {:%Y-%m-%dT%H:%M:%S} bar".format(now_utc))
|
||||||
|
|
||||||
|
self.assertNotIn("Note: 'bar' is a new tag", out)
|
||||||
|
self.assertIn("Tracking bar", out)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
from simpletap import TAPTestRunner
|
from simpletap import TAPTestRunner
|
||||||
|
|
34
test/tag.t
34
test/tag.t
|
@ -172,7 +172,7 @@ class TestTag(TestCase):
|
||||||
|
|
||||||
code, out, err = self.t("tag @1 @2 foo bar")
|
code, out, err = self.t("tag @1 @2 foo bar")
|
||||||
|
|
||||||
self.assertIn('Added foo bar to @1\nAdded foo bar to @2', out)
|
self.assertIn("Added foo bar to @1\nAdded foo bar to @2", out)
|
||||||
|
|
||||||
j = self.t.export()
|
j = self.t.export()
|
||||||
self.assertClosedInterval(j[0], expectedTags=["bar", "foo", "one"])
|
self.assertClosedInterval(j[0], expectedTags=["bar", "foo", "one"])
|
||||||
|
@ -181,7 +181,6 @@ class TestTag(TestCase):
|
||||||
def test_tag_synthetic_interval(self):
|
def test_tag_synthetic_interval(self):
|
||||||
"""Tag a synthetic interval."""
|
"""Tag a synthetic interval."""
|
||||||
now = datetime.now()
|
now = datetime.now()
|
||||||
|
|
||||||
three_hours_before = now - timedelta(hours=3)
|
three_hours_before = now - timedelta(hours=3)
|
||||||
four_hours_before = now - timedelta(hours=4)
|
four_hours_before = now - timedelta(hours=4)
|
||||||
|
|
||||||
|
@ -191,8 +190,8 @@ class TestTag(TestCase):
|
||||||
five_hours_before_utc = now_utc - timedelta(hours=5)
|
five_hours_before_utc = now_utc - timedelta(hours=5)
|
||||||
|
|
||||||
self.t.configure_exclusions((four_hours_before.time(), three_hours_before.time()))
|
self.t.configure_exclusions((four_hours_before.time(), three_hours_before.time()))
|
||||||
|
|
||||||
self.t("start {:%Y-%m-%dT%H:%M:%S}Z foo".format(five_hours_before_utc))
|
self.t("start {:%Y-%m-%dT%H:%M:%S}Z foo".format(five_hours_before_utc))
|
||||||
|
|
||||||
self.t("tag @2 bar")
|
self.t("tag @2 bar")
|
||||||
|
|
||||||
j = self.t.export()
|
j = self.t.export()
|
||||||
|
@ -209,6 +208,7 @@ class TestTag(TestCase):
|
||||||
description="unmodified interval")
|
description="unmodified interval")
|
||||||
|
|
||||||
def test_tag_with_identical_ids(self):
|
def test_tag_with_identical_ids(self):
|
||||||
|
"""Call 'tag' with identical ids"""
|
||||||
now_utc = datetime.now().utcnow()
|
now_utc = datetime.now().utcnow()
|
||||||
one_hour_before_utc = now_utc - timedelta(hours=1)
|
one_hour_before_utc = now_utc - timedelta(hours=1)
|
||||||
|
|
||||||
|
@ -220,6 +220,34 @@ class TestTag(TestCase):
|
||||||
self.assertEquals(len(j), 1)
|
self.assertEquals(len(j), 1)
|
||||||
self.assertClosedInterval(j[0], expectedTags=["foo"])
|
self.assertClosedInterval(j[0], expectedTags=["foo"])
|
||||||
|
|
||||||
|
def test_tag_with_new_tag(self):
|
||||||
|
"""Call 'tag' with new tag"""
|
||||||
|
now_utc = datetime.now().utcnow()
|
||||||
|
|
||||||
|
two_hours_before_utc = now_utc - timedelta(hours=2)
|
||||||
|
one_hour_before_utc = now_utc - timedelta(hours=1)
|
||||||
|
|
||||||
|
self.t("track {:%Y-%m-%dT%H:%M:%S} - {:%Y-%m-%dT%H:%M:%S} foo".format(two_hours_before_utc, one_hour_before_utc))
|
||||||
|
code, out, err = self.t("tag @1 bar")
|
||||||
|
|
||||||
|
self.assertIn("Note: 'bar' is a new tag", out)
|
||||||
|
self.assertIn("Added bar to @1", out)
|
||||||
|
|
||||||
|
def test_tag_with_previous_tag(self):
|
||||||
|
"""Call 'tag' with previous tag"""
|
||||||
|
now_utc = datetime.now().utcnow()
|
||||||
|
|
||||||
|
three_hours_before_utc = now_utc - timedelta(hours=3)
|
||||||
|
two_hours_before_utc = now_utc - timedelta(hours=2)
|
||||||
|
one_hour_before_utc = now_utc - timedelta(hours=1)
|
||||||
|
|
||||||
|
self.t("track {:%Y-%m-%dT%H:%M:%S} - {:%Y-%m-%dT%H:%M:%S} bar".format(three_hours_before_utc, two_hours_before_utc))
|
||||||
|
self.t("track {:%Y-%m-%dT%H:%M:%S} - {:%Y-%m-%dT%H:%M:%S} foo".format(two_hours_before_utc, one_hour_before_utc))
|
||||||
|
code, out, err = self.t("tag @1 bar")
|
||||||
|
|
||||||
|
self.assertNotIn("Note: 'bar' is a new tag", out)
|
||||||
|
self.assertIn("Added bar to @1", out)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
from simpletap import TAPTestRunner
|
from simpletap import TAPTestRunner
|
||||||
|
|
58
test/tags.t
58
test/tags.t
|
@ -74,36 +74,42 @@ class TestTags(TestCase):
|
||||||
self.assertIn('bar', out)
|
self.assertIn('bar', out)
|
||||||
|
|
||||||
|
|
||||||
# class TestTagFeedback(TestCase):
|
class TestTagFeedback(TestCase):
|
||||||
# def setUp(self):
|
def setUp(self):
|
||||||
# """Executed before each test in the class"""
|
"""Executed before each test in the class"""
|
||||||
# self.t = Timew()
|
self.t = Timew()
|
||||||
|
|
||||||
# def test_verbose_new_tag(self):
|
def test_verbose_new_tag(self):
|
||||||
# """Test verbose feedback for new tag"""
|
"""Test verbose feedback for new tag"""
|
||||||
# code, out, err = self.t("start foo bar")
|
code, out, err = self.t("start foo bar")
|
||||||
# self.assertIn("Note: 'foo' is a new tag.", out)
|
|
||||||
# self.assertIn("Note: 'bar' is a new tag.", out)
|
|
||||||
|
|
||||||
# def test_verbose_repeat_tag(self):
|
self.assertIn("Note: 'foo' is a new tag.", out)
|
||||||
# """Test verbose feedback for repeat tag"""
|
self.assertIn("Note: 'bar' is a new tag.", out)
|
||||||
# self.t("track yesterday - today foo bar")
|
|
||||||
# code, out, err = self.t("start bar baz")
|
|
||||||
# self.assertNotIn("Note: 'bar' is a new tag.", out)
|
|
||||||
# self.assertIn("Note: 'baz' is a new tag.", out)
|
|
||||||
|
|
||||||
# def test_quiet_new_tag(self):
|
def test_verbose_repeat_tag(self):
|
||||||
# """Test quiet feedback for new tag"""
|
"""Test verbose feedback for repeat tag"""
|
||||||
# code, out, err = self.t("start foo bar :quiet")
|
self.t("track yesterday - today foo bar")
|
||||||
# self.assertNotIn("Note: 'foo' is a new tag.", out)
|
|
||||||
# self.assertNotIn("Note: 'bar' is a new tag.", out)
|
|
||||||
|
|
||||||
# def test_quiet_repeat_tag(self):
|
code, out, err = self.t("start bar baz")
|
||||||
# """Test quiet feedback for repeat tag"""
|
|
||||||
# self.t("track yesterday - today foo bar")
|
self.assertNotIn("Note: 'bar' is a new tag.", out)
|
||||||
# code, out, err = self.t("start bar baz :quiet")
|
self.assertIn("Note: 'baz' is a new tag.", out)
|
||||||
# self.assertNotIn("Note: 'foo' is a new tag.", out)
|
|
||||||
# self.assertNotIn("Note: 'bar' is a new tag.", out)
|
def test_quiet_new_tag(self):
|
||||||
|
"""Test quiet feedback for new tag"""
|
||||||
|
code, out, err = self.t("start foo bar :quiet")
|
||||||
|
|
||||||
|
self.assertNotIn("Note: 'foo' is a new tag.", out)
|
||||||
|
self.assertNotIn("Note: 'bar' is a new tag.", out)
|
||||||
|
|
||||||
|
def test_quiet_repeat_tag(self):
|
||||||
|
"""Test quiet feedback for repeat tag"""
|
||||||
|
self.t("track yesterday - today foo bar")
|
||||||
|
|
||||||
|
code, out, err = self.t("start bar baz :quiet")
|
||||||
|
|
||||||
|
self.assertNotIn("Note: 'foo' is a new tag.", out)
|
||||||
|
self.assertNotIn("Note: 'bar' is a new tag.", out)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
26
test/track.t
26
test/track.t
|
@ -99,6 +99,32 @@ class TestTrack(TestCase):
|
||||||
|
|
||||||
self.assertTrue(len(j) > 0)
|
self.assertTrue(len(j) > 0)
|
||||||
|
|
||||||
|
def test_track_with_new_tag(self):
|
||||||
|
"""Call 'track' with new tag"""
|
||||||
|
now_utc = datetime.now().utcnow()
|
||||||
|
|
||||||
|
two_hours_before_utc = now_utc - timedelta(hours=2)
|
||||||
|
one_hour_before_utc = now_utc - timedelta(hours=1)
|
||||||
|
|
||||||
|
self.t("track {:%Y-%m-%dT%H:%M:%S} - {:%Y-%m-%dT%H:%M:%S} foo".format(two_hours_before_utc, one_hour_before_utc))
|
||||||
|
code, out, err = self.t("track {:%Y-%m-%dT%H:%M:%S} - {:%Y-%m-%dT%H:%M:%S} bar".format(one_hour_before_utc, now_utc))
|
||||||
|
|
||||||
|
self.assertIn("Note: 'bar' is a new tag", out)
|
||||||
|
self.assertIn("Recorded bar", out)
|
||||||
|
|
||||||
|
def test_track_with_previous_tag(self):
|
||||||
|
"""Call 'track' with previous tag"""
|
||||||
|
now_utc = datetime.now().utcnow()
|
||||||
|
|
||||||
|
two_hours_before_utc = now_utc - timedelta(hours=2)
|
||||||
|
one_hour_before_utc = now_utc - timedelta(hours=1)
|
||||||
|
|
||||||
|
self.t("track {:%Y-%m-%dT%H:%M:%S} - {:%Y-%m-%dT%H:%M:%S} bar".format(two_hours_before_utc, one_hour_before_utc))
|
||||||
|
code, out, err = self.t("track {:%Y-%m-%dT%H:%M:%S} - {:%Y-%m-%dT%H:%M:%S} bar".format(one_hour_before_utc, now_utc))
|
||||||
|
|
||||||
|
self.assertNotIn("Note: 'bar' is a new tag", out)
|
||||||
|
self.assertIn("Recorded bar", out)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
from simpletap import TAPTestRunner
|
from simpletap import TAPTestRunner
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue