From 41c50e009cd24bd214898f1230fa0769029e7520 Mon Sep 17 00:00:00 2001 From: Thomas Lauf Date: Fri, 6 Mar 2020 16:13:00 +0100 Subject: [PATCH] Add test for export with tag filter Signed-off-by: Thomas Lauf --- test/basetest/testing.py | 16 +++++++++++++++- test/export.t | 20 +++++++++++++++++++- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/test/basetest/testing.py b/test/basetest/testing.py index cbee4772..fa52ff36 100644 --- a/test/basetest/testing.py +++ b/test/basetest/testing.py @@ -1,6 +1,6 @@ +import datetime import sys import unittest -import datetime class BaseTestCase(unittest.TestCase): @@ -13,6 +13,7 @@ class BaseTestCase(unittest.TestCase): class TestCase(BaseTestCase): def assertOpenInterval(self, interval, + expectedId=None, expectedStart=None, expectedTags=None, expectedAnnotation=None, @@ -21,6 +22,7 @@ class TestCase(BaseTestCase): self.assertKeyNotExists(interval, "end", description, "{} does contain an end date") return self.assertInterval(interval, + expectedId=expectedId, expectedStart=expectedStart, expectedEnd=None, expectedTags=expectedTags, @@ -28,6 +30,7 @@ class TestCase(BaseTestCase): description=description) def assertClosedInterval(self, interval, + expectedId=None, expectedStart=None, expectedEnd=None, expectedTags=None, @@ -37,6 +40,7 @@ class TestCase(BaseTestCase): self.assertKeyExists(interval, "end", description, "{} does not contain an end date") return self.assertInterval(interval, + expectedId=expectedId, expectedStart=expectedStart, expectedEnd=expectedEnd, expectedTags=expectedTags, @@ -44,11 +48,20 @@ class TestCase(BaseTestCase): description=description) def assertInterval(self, interval, + expectedId=None, expectedStart=None, expectedEnd=None, expectedTags=None, expectedAnnotation=None, 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: self.assertIntervalTimestamp(interval, "start", expectedStart, description) @@ -62,6 +75,7 @@ class TestCase(BaseTestCase): expectedTags, description, "{} of {} do not match (expected: '{}', actual: '{}')") + if expectedAnnotation: self.assertKeyExists(interval, "annotation", description, "{} is not annotated") self.assertIntervalValue(interval, diff --git a/test/export.t b/test/export.t index 5a53dfa3..17867cbe 100755 --- a/test/export.t +++ b/test/export.t @@ -30,7 +30,7 @@ import os import sys import unittest -from datetime import datetime, timedelta, time +from datetime import datetime, timedelta # Ensure python finds the local simpletap module sys.path.append(os.path.dirname(os.path.abspath(__file__))) @@ -180,6 +180,24 @@ class TestExport(TestCase): self.assertEqual(len(j), 1) 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__": from simpletap import TAPTestRunner