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): class Report(object):
"""Create a report on tracked time""" """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): output_format, regexp, ignore_case):
self.project = project self.project = project
@ -117,9 +117,10 @@ class Report(object):
report.header() report.header()
Report.print_report_time_entries(report_data, Report.print_report_time_entries(report_data,
output_format, summary) output_format, summary)
if summary: # For summary do not print time entries.
Report.print_report_time_entries(summary_report, # if summary:
output_format, summary) # Report.print_report_time_entries(summary_report,
# output_format, summary)
def _init_date(self, start_date, end_date): 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) self.end_date = self.end_date.replace(hour=23,minute=59,second=59)
if self.start_date >= self.end_date: 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)) (self.start_date, self.end_date))
def _init_report_db(self): def _init_report_db(self):
@ -180,7 +181,7 @@ class Report(object):
if os.path.exists(comment_filename): if os.path.exists(comment_filename):
with open(comment_filename, "r") as fd: with open(comment_filename, "r") as fd:
comment = fd.read().rstrip('\n') comment = fd.read().rstrip('\n')
# If regular expression given, but not matching, skip entry # If regular expression given, but not matching, skip entry
if self.regexp and not re.search(self.regexp, comment, self.search_flags): if self.regexp and not re.search(self.regexp, comment, self.search_flags):
continue continue
@ -205,7 +206,7 @@ class Report(object):
@staticmethod @staticmethod
def summary(total_time): 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." % print("Total time tracked: %sh %sm %ss." %
(hours, minutes, seconds)) (hours, minutes, seconds))

View file

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