Refactor test

- allow for jitter to stabilize test
- use triple quote strings
This commit is contained in:
Thomas Lauf 2018-03-07 21:45:25 +01:00
parent 55508fd201
commit 946ac0ad68

View file

@ -75,7 +75,15 @@ temp.report.end: 20160101T080000Z
]\
""")
self.assertEqual('\nTotal by Tag, for 2016-01-01 07:00:00 - 2016-01-01 08:00:00\n\nTag Total\n----- ----------\nfoo 1:00:00\n ----------\nTotal 1:00:00\n', out)
self.assertRegexpMatches(out, """
Total by Tag, for 2016-01-01 07:00:00 - 2016-01-01 08:00:00
Tag Total
----- ----------
foo 1:00:0[01]
----------
Total 1:00:0[01]
""")
self.assertEqual('', err)
def test_totals_with_interval_without_tags(self):
@ -89,7 +97,15 @@ temp.report.end: 20160101T080000Z
[{"start":"20160101T070000Z","end":"20160101T080000Z"}]\
""")
self.assertEqual('\nTotal by Tag, for 2016-01-01 07:00:00 - 2016-01-01 08:00:00\n\nTag Total\n----- ----------\n 1:00:00\n ----------\nTotal 1:00:00\n', out)
self.assertRegexpMatches(out, """
Total by Tag, for 2016-01-01 07:00:00 - 2016-01-01 08:00:00
Tag Total
----- ----------
1:00:0[01]
----------
Total 1:00:0[01]
""")
self.assertEqual('', err)
def test_totals_with_interval_with_empty_tag_list(self):
@ -105,32 +121,45 @@ temp.report.end: 20160101T080000Z
]\
""")
self.assertEqual('\nTotal by Tag, for 2016-01-01 07:00:00 - 2016-01-01 08:00:00\n\nTag Total\n----- ----------\n 1:00:00\n ----------\nTotal 1:00:00\n', out)
self.assertRegexpMatches(out, """
Total by Tag, for 2016-01-01 07:00:00 - 2016-01-01 08:00:00
Tag Total
----- ----------
1:00:0[01]
----------
Total 1:00:0[01]
""")
self.assertEqual('', err)
def test_totals_with_open_interval(self):
"""totals extension should handle open interval"""
now = datetime.datetime.now()
now_utc = now.utcnow()
one_hour_before = now - datetime.timedelta(hours=1)
two_hours_before = now - datetime.timedelta(hours=2)
now_utc = now.utcnow()
one_hour_before_utc = now_utc - datetime.timedelta(hours=1)
two_hours_before_utc = now_utc - datetime.timedelta(hours=2)
out, err = self.process.communicate(input="""\
color: off
debug: off
temp.report.start: {:%Y%m%dT%H%M%S}Z
temp.report.start: {0:%Y%m%dT%H%M%S}Z
temp.report.end:
[
{{"start":"{:%Y%m%dT%H%M%S}Z","tags":["foo"]}}
{{"start":"{0:%Y%m%dT%H%M%S}Z","tags":["foo"]}}
]\
""".format(one_hour_before_utc, one_hour_before_utc))
""".format(one_hour_before_utc))
self.assertEqual('\nTotal by Tag, for {:%Y-%m-%d %H:%M:%S} - {:%Y-%m-%d %H:%M:%S}\n\nTag Total\n----- ----------\nfoo 1:00:00\n ----------\nTotal 1:00:00\n'.format(two_hours_before, now), out)
self.assertRegexpMatches(out, """
Total by Tag, for {:%Y-%m-%d %H:%M}:0[01] - {:%Y-%m-%d %H:%M}:0[01]
Tag Total
----- ----------
foo 1:00:0[01]
----------
Total 1:00:0[01]
""".format(two_hours_before, now))
self.assertEqual('', err)