mirror of
https://github.com/GothenburgBitFactory/timewarrior.git
synced 2025-06-26 10:54:28 +02:00
Add tests for configurable report range, update man page
Signed-off-by: Thomas Lauf <thomas.lauf@tngtech.com>
This commit is contained in:
parent
c8eee25f5b
commit
55ad661e0d
3 changed files with 70 additions and 6 deletions
|
@ -27,5 +27,6 @@ The value has to be a range hint, see timew-hints(7).
|
|||
Defaults to `:all`
|
||||
|
||||
**reports.**__<name>__**.range**::
|
||||
Set the date range for report _name_, where _name_ is the name of the report executable without its extension (i.e. a report executable 'foo.py' is referred to by 'foo').
|
||||
Set the date range for report _name_, used if no _range_ is given on the command line.
|
||||
Here, _name_ is the name of the report executable without its extension (i.e. a report executable 'foo.py' is referred to by 'foo').
|
||||
The value has to be a range hint, see timew-hints(7).
|
||||
|
|
|
@ -1,4 +1,9 @@
|
|||
#!/usr/bin/env python3
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
import unittest
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
###############################################################################
|
||||
#
|
||||
|
@ -26,11 +31,6 @@
|
|||
#
|
||||
###############################################################################
|
||||
|
||||
import os
|
||||
import unittest
|
||||
|
||||
import sys
|
||||
|
||||
# Ensure python finds the local simpletap module
|
||||
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
|
||||
|
||||
|
@ -57,6 +57,58 @@ class TestExtensions(TestCase):
|
|||
code, out, err = self.t('report ext')
|
||||
self.assertIn('test works', out)
|
||||
|
||||
def test_default_range_is_applied_when_no_range_given_on_command_line(self):
|
||||
"""Default range is applied when no range is given on the command line"""
|
||||
self.t.add_default_extension("debug.py")
|
||||
|
||||
self.t.config("reports.debug.range", "':day'")
|
||||
|
||||
now = datetime.now()
|
||||
now_utc = now.utcnow()
|
||||
|
||||
yesterday_one_hour_before_utc = now_utc - timedelta(hours=1, days=1)
|
||||
yesterday_two_hours_before_utc = now_utc - timedelta(hours=2, days=1)
|
||||
|
||||
self.t("track {:%Y-%m-%dT%H:%M:%S}Z - {:%Y-%m-%dT%H:%M:%S}Z foo".format(yesterday_two_hours_before_utc, yesterday_one_hour_before_utc))
|
||||
self.t("track {:%Y-%m-%dT%H:%M:%S}Z bar".format(now_utc))
|
||||
|
||||
code, out, err = self.t("debug")
|
||||
|
||||
j = json.loads(out)
|
||||
|
||||
self.assertEqual(len(j), 1)
|
||||
self.assertOpenInterval(j[0],
|
||||
expectedStart="{:%Y%m%dT%H%M%S}Z".format(now_utc),
|
||||
expectedTags=["bar"])
|
||||
|
||||
def test_default_range_is_overridden_when_range_given_on_command_line(self):
|
||||
"""Default range is overridden when range is given on the command line"""
|
||||
self.t.add_default_extension("debug.py")
|
||||
|
||||
self.t.config("reports.debug.range", "':day'")
|
||||
|
||||
now = datetime.now()
|
||||
now_utc = now.utcnow()
|
||||
|
||||
yesterday_one_hour_before_utc = now_utc - timedelta(hours=1, days=1)
|
||||
yesterday_two_hours_before_utc = now_utc - timedelta(hours=2, days=1)
|
||||
|
||||
self.t("track {:%Y-%m-%dT%H:%M:%S}Z - {:%Y-%m-%dT%H:%M:%S}Z foo".format(yesterday_two_hours_before_utc, yesterday_one_hour_before_utc))
|
||||
self.t("track {:%Y-%m-%dT%H:%M:%S}Z bar".format(now_utc))
|
||||
|
||||
code, out, err = self.t("debug :all")
|
||||
|
||||
j = json.loads(out)
|
||||
|
||||
self.assertEqual(len(j), 2)
|
||||
self.assertClosedInterval(j[0],
|
||||
expectedStart="{:%Y%m%dT%H%M%S}Z".format(yesterday_two_hours_before_utc),
|
||||
expectedEnd="{:%Y%m%dT%H%M%S}Z".format(yesterday_one_hour_before_utc),
|
||||
expectedTags=["foo"])
|
||||
self.assertOpenInterval(j[1],
|
||||
expectedStart="{:%Y%m%dT%H%M%S}Z".format(now_utc),
|
||||
expectedTags=["bar"])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
from simpletap import TAPTestRunner
|
||||
|
|
11
test/test_extensions/debug.py
Executable file
11
test/test_extensions/debug.py
Executable file
|
@ -0,0 +1,11 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import sys
|
||||
|
||||
for line in sys.stdin:
|
||||
# skip configuration
|
||||
if line == "\n":
|
||||
break
|
||||
|
||||
for line in sys.stdin:
|
||||
print(line.strip())
|
Loading…
Add table
Add a link
Reference in a new issue