Add test for export with tag filter

Signed-off-by: Thomas Lauf <thomas.lauf@tngtech.com>
This commit is contained in:
Thomas Lauf 2020-03-06 16:13:00 +01:00
parent 42872f5168
commit 41c50e009c
2 changed files with 34 additions and 2 deletions

View file

@ -1,6 +1,6 @@
import datetime
import sys import sys
import unittest import unittest
import datetime
class BaseTestCase(unittest.TestCase): class BaseTestCase(unittest.TestCase):
@ -13,6 +13,7 @@ class BaseTestCase(unittest.TestCase):
class TestCase(BaseTestCase): class TestCase(BaseTestCase):
def assertOpenInterval(self, interval, def assertOpenInterval(self, interval,
expectedId=None,
expectedStart=None, expectedStart=None,
expectedTags=None, expectedTags=None,
expectedAnnotation=None, expectedAnnotation=None,
@ -21,6 +22,7 @@ class TestCase(BaseTestCase):
self.assertKeyNotExists(interval, "end", description, "{} does contain an end date") self.assertKeyNotExists(interval, "end", description, "{} does contain an end date")
return self.assertInterval(interval, return self.assertInterval(interval,
expectedId=expectedId,
expectedStart=expectedStart, expectedStart=expectedStart,
expectedEnd=None, expectedEnd=None,
expectedTags=expectedTags, expectedTags=expectedTags,
@ -28,6 +30,7 @@ class TestCase(BaseTestCase):
description=description) description=description)
def assertClosedInterval(self, interval, def assertClosedInterval(self, interval,
expectedId=None,
expectedStart=None, expectedStart=None,
expectedEnd=None, expectedEnd=None,
expectedTags=None, expectedTags=None,
@ -37,6 +40,7 @@ class TestCase(BaseTestCase):
self.assertKeyExists(interval, "end", description, "{} does not contain an end date") self.assertKeyExists(interval, "end", description, "{} does not contain an end date")
return self.assertInterval(interval, return self.assertInterval(interval,
expectedId=expectedId,
expectedStart=expectedStart, expectedStart=expectedStart,
expectedEnd=expectedEnd, expectedEnd=expectedEnd,
expectedTags=expectedTags, expectedTags=expectedTags,
@ -44,11 +48,20 @@ class TestCase(BaseTestCase):
description=description) description=description)
def assertInterval(self, interval, def assertInterval(self, interval,
expectedId=None,
expectedStart=None, expectedStart=None,
expectedEnd=None, expectedEnd=None,
expectedTags=None, expectedTags=None,
expectedAnnotation=None, expectedAnnotation=None,
description="interval"): description="interval"):
if expectedId is not None:
self.assertKeyExists(interval, "id", description, "{} does not contain an id")
self.assertIntervalValue(interval,
"id",
expectedId,
description,
"{} of {} do not match (expected: '{}', actual: '{}')")
if expectedStart: if expectedStart:
self.assertIntervalTimestamp(interval, "start", expectedStart, description) self.assertIntervalTimestamp(interval, "start", expectedStart, description)
@ -62,6 +75,7 @@ class TestCase(BaseTestCase):
expectedTags, expectedTags,
description, description,
"{} of {} do not match (expected: '{}', actual: '{}')") "{} of {} do not match (expected: '{}', actual: '{}')")
if expectedAnnotation: if expectedAnnotation:
self.assertKeyExists(interval, "annotation", description, "{} is not annotated") self.assertKeyExists(interval, "annotation", description, "{} is not annotated")
self.assertIntervalValue(interval, self.assertIntervalValue(interval,

View file

@ -30,7 +30,7 @@ import os
import sys import sys
import unittest import unittest
from datetime import datetime, timedelta, time from datetime import datetime, timedelta
# 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__)))
@ -180,6 +180,24 @@ class TestExport(TestCase):
self.assertEqual(len(j), 1) self.assertEqual(len(j), 1)
self.assertClosedInterval(j[0], expectedTags=["tag with \"quote"]) self.assertClosedInterval(j[0], expectedTags=["tag with \"quote"])
def test_non_contiguous_with_tag_filter(self):
"""Export with tag filter"""
self.t("track Tag1 2017-03-09T08:43:08 - 2017-03-09T09:38:15")
self.t("track Tag2 2017-03-09T11:38:39 - 2017-03-09T11:45:35")
self.t("track Tag1 Tag3 2017-03-09T11:46:21 - 2017-03-09T12:00:17")
self.t("track Tag2 Tag4 2017-03-09T12:01:49 - 2017-03-09T12:28:46")
j = self.t.export("Tag1")
self.assertEqual(len(j), 2)
self.assertClosedInterval(j[0],
expectedId=4,
expectedTags=["Tag1"])
self.assertClosedInterval(j[1],
expectedId=2,
expectedTags=["Tag1", "Tag3"])
if __name__ == "__main__": if __name__ == "__main__":
from simpletap import TAPTestRunner from simpletap import TAPTestRunner