Permalink
Browse files

#9 TI-1: Add testsuite

- Simple test for each undoable interval command
- Refactored assertions
  • Loading branch information...
lauft committed Jul 23, 2018
1 parent cd7755b commit 9d29a14d64236cb871bfd34f5ff00aa06b99d476
Showing with 418 additions and 29 deletions.
  1. +34 −24 test/basetest/testing.py
  2. +3 −5 test/basetest/timew.py
  3. +381 −0 test/undo.t
@@ -2,7 +2,7 @@

import sys
import unittest

import datetime

class BaseTestCase(unittest.TestCase):
def tap(self, out):
@@ -17,8 +17,8 @@ def assertOpenInterval(self, interval,
expectedStart=None,
expectedTags=None,
description="interval"):
self.assertTrue("start" in interval, "{} does not contain a start date".format(description))
self.assertFalse("end" in interval, "{} does contain an end date".format(description))
self.assertKeyExists(interval, "start", description, "{} does not contain a start date")
self.assertKeyNotExists(interval, "end", description, "{} does contain an end date")

return self.assertInterval(interval,
expectedStart=expectedStart,
@@ -31,8 +31,8 @@ def assertClosedInterval(self, interval,
expectedEnd=None,
expectedTags=None,
description="interval"):
self.assertTrue("start" in interval, "{} does not contain a start date".format(description))
self.assertTrue("end" in interval, "{} does not contain an end date".format(description))
self.assertKeyExists(interval, "start", description, "{} does not contain a start date")
self.assertKeyExists(interval, "end", description, "{} does not contain an end date")

return self.assertInterval(interval,
expectedStart=expectedStart,
@@ -46,29 +46,39 @@ def assertInterval(self, interval,
expectedTags=None,
description="interval"):
if expectedStart:
self.assertEqual(
interval["start"],
expectedStart,
"start time of {} does not match (expected: {}, actual: {})".format(description,
expectedStart,
interval["start"]))
self.assertIntervalTimestamp(interval, "start", expectedStart, description)

if expectedEnd:
self.assertEqual(
interval["end"],
expectedEnd,
"end time of {} does not match (expected: {}, actual: {})".format(description,
expectedEnd,
interval["end"]))
self.assertIntervalTimestamp(interval, "end", expectedEnd, description)

if expectedTags:
self.assertTrue("tags" in interval)
self.assertEqual(
interval["tags"],
expectedTags,
"tags of {} do not match (expected: {}, actual: {})". format(description,
expectedTags,
interval["tags"]))
self.assertKeyExists(interval, "tags", description, "{} does not contain tags")
self.assertIntervalValue(interval,
"tags",
expectedTags,
description,
"{} of {} do not match (expected: {}, actual: {})")

def assertKeyExists(self, interval, key, description, message):
self.assertTrue(key in interval, message.format(description))

def assertKeyNotExists(self, interval, key, description, message):
self.assertFalse(key in interval, message.format(description))

def assertIntervalTimestamp(self, interval, key, expected, description):
if isinstance(expected, datetime.datetime):
expected = "{:%Y%m%dT%H%M%SZ}".format(expected)

self.assertIntervalValue(interval,
key,
expected,
description,
"{} time of {} does not match (expected: {}, actual: {})")

def assertIntervalValue(self, interval, key, expected, description, message):
actual = interval[key]
self.assertEqual(actual,
expected,
message.format(key, description, expected, actual))

# vim: ai sts=4 et sw=4
@@ -92,12 +92,11 @@ def timewrc_content(self):
return f.readlines()

def export(self, export_filter=None):
"""Run "task export", return JSON array of exported intervals."""
"""Run "timew export", return JSON array of exported intervals."""
if export_filter is None:
export_filter = ""

code, out, err = self.runSuccess("{0} export"
"".format(export_filter))
code, out, err = self.runSuccess("{0} export".format(export_filter))

return json.loads(out)

@@ -112,8 +111,7 @@ def _split_string_args_if_string(args):

return args

def runSuccess(self, args="", input=None, merge_streams=False,
timeout=5):
def runSuccess(self, args="", input=None, merge_streams=False, timeout=5):
"""Invoke timew with given arguments and fail if exit code != 0
Use runError if you want exit_code to be tested automatically and
Oops, something went wrong.

0 comments on commit 9d29a14

Please sign in to comment.