def test_calc_log_time_with_offset_minutes_corrections(self, mock): expected = datetime(2020, 1, 1, 0, 10, tzinfo=timezone.utc) actual = calc_log_time(offset_min=10) mock.assert_not_called() self.assertEqual(actual, expected)
def dispatch( log: Log, parser: ArgumentParser, cli_args: Namespace, cfg: ConfigParser ) -> None: """ Dispatch request to Log instance based on CLI arguments and configuration values. """ if cli_args.subcmd == wc.SUBCMD_SESSION: if cli_args.type in [wc.TOKEN_START, wc.TOKEN_STOP]: log.commit( wc.TOKEN_SESSION, cli_args.type, cli_args.offset_minutes, cli_args.time, force=cli_args.force, ) elif cli_args.subcmd == wc.SUBCMD_TASK: if cli_args.type in [wc.TOKEN_START, wc.TOKEN_STOP]: if cli_args.type == wc.TOKEN_START and cli_args.auto_stop: commit_dt = calc_log_time(cli_args.offset_minutes, cli_args.time) log.stop_active_tasks(commit_dt) log.commit( wc.TOKEN_TASK, cli_args.type, cli_args.offset_minutes, cli_args.time, identifier=cli_args.id, ) elif cli_args.type == "list": log.list_tasks() elif cli_args.type == "report": log.task_report(cli_args.id) elif cli_args.subcmd == wc.SUBCMD_STATUS: hours_target = float(cfg.get("workday", "hours_target")) hours_max = float(cfg.get("workday", "hours_max")) fmt = cli_args.fmt query_date = date.today() if cli_args.yesterday: query_date -= timedelta(days=1) elif cli_args.date: query_date = cli_args.date.date() log.status(hours_target, hours_max, query_date=query_date, fmt=fmt) elif cli_args.subcmd == wc.SUBCMD_DOCTOR: log.doctor() elif cli_args.subcmd == wc.SUBCMD_LOG: n = cli_args.number no_pager_max_entries = int(cfg.get("worklog", "no_pager_max_entries")) use_pager = not cli_args.no_pager and (cli_args.all or n > no_pager_max_entries) categories = cli_args.category if not cli_args.all: log.log(cli_args.number, use_pager, categories) else: log.log(-1, use_pager, categories) elif cli_args.subcmd == wc.SUBCMD_REPORT: log.report(cli_args.date_from, cli_args.date_to)
def commit( self, category: str, type_: str, offset_min: int = 0, time: Optional[str] = None, identifier: str = None, force: bool = False, ) -> None: """Commit a session/task change to the logfile.""" log_date = calc_log_time(offset_min, time) self._commit(category, type_, log_date, identifier, force)
def test_calc_log_time_with_time_corrections(self, mock): dt = datetime(2020, 1, 1, tzinfo=timezone.utc) actual = calc_log_time(time="20:21") mock.assert_called_with(dt, "20:21")
def test_calc_log_time_no_corrections(self): expected = datetime(2020, 1, 1, tzinfo=timezone.utc) actual = calc_log_time() self.assertEqual(actual, expected)