Permalink
Browse files

Update tests

  • Loading branch information...
lauft committed Aug 10, 2018
1 parent a02b98f commit b15695dab08608046ed7e41890b193005f16a11c
Showing with 122 additions and 34 deletions.
  1. +29 −1 test/start.t
  2. +31 −3 test/tag.t
  3. +36 −30 test/tags.t
  4. +26 −0 test/track.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
@@ -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
@@ -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()

# 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_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)

# 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)
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_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)

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__":
@@ -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

0 comments on commit b15695d

Please sign in to comment.