Fix summary option output.

This commit is contained in:
Darko Poljak 2016-11-07 08:47:12 +01:00
parent 03fcffb3bf
commit 9adc35f78b
2 changed files with 32 additions and 31 deletions

View file

@ -42,7 +42,7 @@ log = logging.getLogger(__name__)
class Report(object):
"""Create a report on tracked time"""
def __init__(self, project, start_date, end_date,
def __init__(self, project, start_date, end_date,
output_format, regexp, ignore_case):
self.project = project
@ -117,9 +117,10 @@ class Report(object):
report.header()
Report.print_report_time_entries(report_data,
output_format, summary)
if summary:
Report.print_report_time_entries(summary_report,
output_format, summary)
# For summary do not print time entries.
# if summary:
# Report.print_report_time_entries(summary_report,
# output_format, summary)
def _init_date(self, start_date, end_date):
@ -154,7 +155,7 @@ class Report(object):
self.end_date = self.end_date.replace(hour=23,minute=59,second=59)
if self.start_date >= self.end_date:
raise ctt.Error("End date must be after start date (%s >= %s)" %
raise ctt.Error("End date must be after start date (%s >= %s)" %
(self.start_date, self.end_date))
def _init_report_db(self):
@ -180,7 +181,7 @@ class Report(object):
if os.path.exists(comment_filename):
with open(comment_filename, "r") as fd:
comment = fd.read().rstrip('\n')
# If regular expression given, but not matching, skip entry
if self.regexp and not re.search(self.regexp, comment, self.search_flags):
continue
@ -205,7 +206,7 @@ class Report(object):
@staticmethod
def summary(total_time):
hours, minutes, seconds = ctt.user_timedelta(total_time)
hours, minutes, seconds = ctt.user_timedelta(total_time)
print("Total time tracked: %sh %sm %ss." %
(hours, minutes, seconds))

View file

@ -99,7 +99,7 @@ class ReportTestCase(ctt.test.CttTestCase):
def test_print_reports(self):
reports = collections.OrderedDict()
for project in ('foo1', 'foo2'):
rep = report.Report(project, ('2016-04-07',), ('2016-04-08',),
rep = report.Report(project, ('2016-04-07',), ('2016-04-08',),
ctt.REPORTFORMAT, None, None)
report_data = rep.report()
reports[project] = (rep, report_data)
@ -114,25 +114,25 @@ class ReportTestCase(ctt.test.CttTestCase):
output = self._get_output()
self.assertEqual(output, expected_output)
def test_print_reports_summary(self):
reports = collections.OrderedDict()
for project in ('foo1', 'foo2'):
rep = report.Report(project, ('2016-04-07',), ('2016-04-08',),
ctt.REPORTFORMAT, None, None)
report_data = rep.report()
reports[project] = (rep, report_data)
expected_output = (
"2016-04-07-0810 (0:00:10): foo2\n"
"2016-04-07-0826 (0:00:06): foo1\n"
"2016-04-08-1200 (1:23:20): foo1 12"
)
rep.print_reports(reports, ctt.REPORTFORMAT, summary=True)
output = self._get_output()
self.assertEqual(output, expected_output)
# Summary should not print time entries
# def test_print_reports_summary(self):
# reports = collections.OrderedDict()
# for project in ('foo1', 'foo2'):
# rep = report.Report(project, ('2016-04-07',), ('2016-04-08',),
# ctt.REPORTFORMAT, None, None)
# report_data = rep.report()
# reports[project] = (rep, report_data)
# expected_output = (
# "2016-04-07-0810 (0:00:10): foo2\n"
# "2016-04-07-0826 (0:00:06): foo1\n"
# "2016-04-08-1200 (1:23:20): foo1 12"
# )
# rep.print_reports(reports, ctt.REPORTFORMAT, summary=True)
# output = self._get_output()
# self.assertEqual(output, expected_output)
def test__init_date(self):
rep = report.Report('foo1', ('2016-04-07',), ('2016-04-07',),
rep = report.Report('foo1', ('2016-04-07',), ('2016-04-07',),
ctt.REPORTFORMAT, None, None)
expected_start_date = datetime.datetime(2016, 4, 7)
expected_end_date = datetime.datetime(2016, 4, 7, 23, 59, 59)
@ -141,7 +141,7 @@ class ReportTestCase(ctt.test.CttTestCase):
@unittest.expectedFailure
def test__init_date_fail(self):
rep = report.Report('foo1', ('2016-04-08',), ('2016-04-07',),
rep = report.Report('foo1', ('2016-04-08',), ('2016-04-07',),
ctt.REPORTFORMAT, None, None)
def test__init_date_defaults(self):
@ -158,11 +158,11 @@ class ReportTestCase(ctt.test.CttTestCase):
@unittest.expectedFailure
def test__init_report_db_fail(self):
rep = report.Report('unexisting', ('2016-04-07',), ('2016-04-07',),
rep = report.Report('unexisting', ('2016-04-07',), ('2016-04-07',),
ctt.REPORTFORMAT, None, None)
def test__init_report_db(self):
rep = report.Report('foo1', ('2016-04-07',), ('2016-04-07',),
rep = report.Report('foo1', ('2016-04-07',), ('2016-04-07',),
ctt.REPORTFORMAT, None, None)
expected_db = {
'2016-04-07-0826': {
@ -173,7 +173,7 @@ class ReportTestCase(ctt.test.CttTestCase):
self.assertEqual(rep._report_db, expected_db)
def test_header(self):
rep = report.Report('foo1', ('2016-04-07',), ('2016-04-07',),
rep = report.Report('foo1', ('2016-04-07',), ('2016-04-07',),
ctt.REPORTFORMAT, None, None)
rep.header()
output = self._get_output()
@ -186,14 +186,14 @@ class ReportTestCase(ctt.test.CttTestCase):
self.assertEqual(output, "Total time tracked: 0h 0m 10s.")
def test_total_time(self):
rep = report.Report('foo1', ('2016-04-07',), ('2016-04-07',),
rep = report.Report('foo1', ('2016-04-07',), ('2016-04-07',),
ctt.REPORTFORMAT, None, None)
total_time = rep.total_time
expected_total_time = 6.248274
self.assertEqual(total_time, expected_total_time)
def test_report(self):
rep = report.Report('foo1', ('2016-04-07',), ('2016-04-08',),
rep = report.Report('foo1', ('2016-04-07',), ('2016-04-08',),
ctt.REPORTFORMAT, None, None)
expected_entries = {
'2016-04-07-0826': [