From 7771d94dee4cd8b3d166eea133198d39d63fd711 Mon Sep 17 00:00:00 2001 From: Thomas Lauf Date: Fri, 10 Aug 2018 18:22:08 +0200 Subject: [PATCH] Update tests --- test/start.t | 30 ++++++++++++++++++++++++++- test/tag.t | 34 +++++++++++++++++++++++++++--- test/tags.t | 58 +++++++++++++++++++++++++++++----------------------- test/track.t | 26 +++++++++++++++++++++++ 4 files changed, 118 insertions(+), 30 deletions(-) diff --git a/test/start.t b/test/start.t index f7538b76..f7c55219 100755 --- a/test/start.t +++ b/test/start.t @@ -30,7 +30,7 @@ import os import sys import unittest -from datetime import time +from datetime import datetime, timedelta, time # Ensure python finds the local simpletap module 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('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__": from simpletap import TAPTestRunner diff --git a/test/tag.t b/test/tag.t index 5d1ab00a..fe919fdd 100755 --- a/test/tag.t +++ b/test/tag.t @@ -172,7 +172,7 @@ 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) + self.assertIn("Added foo bar to @1\nAdded foo bar to @2", out) j = self.t.export() self.assertClosedInterval(j[0], expectedTags=["bar", "foo", "one"]) @@ -181,7 +181,6 @@ class TestTag(TestCase): def test_tag_synthetic_interval(self): """Tag a synthetic interval.""" now = datetime.now() - three_hours_before = now - timedelta(hours=3) four_hours_before = now - timedelta(hours=4) @@ -191,8 +190,8 @@ class TestTag(TestCase): five_hours_before_utc = now_utc - timedelta(hours=5) 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("tag @2 bar") j = self.t.export() @@ -209,6 +208,7 @@ class TestTag(TestCase): description="unmodified interval") def test_tag_with_identical_ids(self): + """Call 'tag' with identical ids""" now_utc = datetime.now().utcnow() one_hour_before_utc = now_utc - timedelta(hours=1) @@ -220,6 +220,34 @@ class TestTag(TestCase): self.assertEquals(len(j), 1) 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__": from simpletap import TAPTestRunner diff --git a/test/tags.t b/test/tags.t index 2856e91a..90ca1dda 100755 --- a/test/tags.t +++ b/test/tags.t @@ -74,36 +74,42 @@ class TestTags(TestCase): self.assertIn('bar', out) -# class TestTagFeedback(TestCase): -# def setUp(self): -# """Executed before each test in the class""" -# self.t = Timew() +class TestTagFeedback(TestCase): + def setUp(self): + """Executed before each test in the class""" + self.t = Timew() -# def test_verbose_new_tag(self): -# """Test verbose feedback for new tag""" -# 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_new_tag(self): + """Test verbose feedback for new tag""" + code, out, err = self.t("start foo bar") -# def test_verbose_repeat_tag(self): -# """Test verbose feedback for repeat tag""" -# 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) + self.assertIn("Note: 'foo' is a new tag.", out) + self.assertIn("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_verbose_repeat_tag(self): + """Test verbose feedback for repeat tag""" + self.t("track yesterday - today foo bar") -# 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) + 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): + """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__": diff --git a/test/track.t b/test/track.t index 6e59d804..d21bbd88 100755 --- a/test/track.t +++ b/test/track.t @@ -99,6 +99,32 @@ class TestTrack(TestCase): 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__": from simpletap import TAPTestRunner