From 990e0772d01ab2ffb6b6f7aa6bdacaba71c37e77 Mon Sep 17 00:00:00 2001 From: Thomas Lauf Date: Wed, 19 Aug 2020 14:51:23 +0200 Subject: [PATCH] Add tests for stop command - Stop with no datetime (rare case of e.g. `timew stop :all`) - `stop` with tag after `start` without tags --- test/stop.t | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/test/stop.t b/test/stop.t index 34f7b3f2..c68217a4 100755 --- a/test/stop.t +++ b/test/stop.t @@ -58,8 +58,8 @@ class TestStop(TestCase): expectedStart=one_hour_before_utc, expectedEnd=now_utc) - def test_invalid_stop(self): - """Verify stop date after start date is an error""" + def test_stop_with_end_before_start_is_an_error(self): + """Verify stop date before start date is an error""" now_utc = datetime.now().utcnow() one_hour_before_utc = now_utc - timedelta(hours=1) @@ -69,6 +69,11 @@ class TestStop(TestCase): self.assertIn("The end of a date range must be after the start.", err) + j = self.t.export() + + self.assertEqual(len(j), 1) + self.assertOpenInterval(j[0], expectedTags=[]) + def test_stop_all(self): """Start three tags, stop""" self.t("start 5mins ago one two three") @@ -117,6 +122,37 @@ class TestStop(TestCase): self.assertIn("The current interval does not have the 'four' tag.", err) + j = self.t.export() + + self.assertEqual(len(j), 1) + self.assertOpenInterval(j[0], expectedTags=["one", "two", "three"]) + + def test_stop_non_existing_tag(self): + """Start empty, stop with tag""" + self.t("start 5mins ago ") + + code, out, err = self.t.runError("stop bogus") + + self.assertIn("The current interval does not have the 'bogus' tag.", err) + + j = self.t.export() + + self.assertEqual(len(j), 1) + self.assertOpenInterval(j[0], expectedTags=[]) + + def test_stop_with_all_hint_is_an_error(self): + """Verify stop with :all hint is an error""" + self.t("start 5mins ago FOO ") + + code, out, err = self.t.runError("stop :all") + + self.assertIn("No datetime specified.", err) + + j = self.t.export() + + self.assertEqual(len(j), 1) + self.assertOpenInterval(j[0], expectedTags=["FOO"]) + def test_single_interval_enclosing_exclusion(self): """Add one interval that encloses an exclusion, and is therefore flattened""" self.t.configure_exclusions([(time(18, 5, 11), time(9, 11, 50)),