Esempio n. 1
0
def format_report(report: Dict[str, Any]):
    report = dict(report)
    if "start" not in report:
        return {}
    datetime_format = r"%Y-%m-%d %H:%M:%S"
    report["start"] = report["start"].strftime(datetime_format)
    report["end"] = report["end"].strftime(datetime_format)
    report["time"] = format_timedelta_human(report["time"])
    report["total"] = format_timedelta_human(report["total"])
    return report
Esempio n. 2
0
def elapsed_time(log):
    log.start = datetime.datetime.now()
    try:
        yield
    finally:
        log.end = datetime.datetime.now()
        log.elapsed = log.end - log.start
        time = format_timedelta_human(log.elapsed)
        log.info = f"Elapsed time: {time}"
Esempio n. 3
0
 def message(result):
     dt = format_timedelta_human(datetime.datetime.now() - now)
     return f"Kernel [{self.name}] started ({dt})" if result else "Retrying..."
Esempio n. 4
0
def test_format_timedelta_human():
    assert format_timedelta_human(timedelta(days=1,
                                            seconds=100)) == "24h1min40s"
    assert format_timedelta_human(timedelta(seconds=3670)) == "1h1min10s"
    assert format_timedelta_human(timedelta(seconds=2670)) == "44min30s"
    assert format_timedelta_human(timedelta(seconds=59.564)) == "59.6s"
    assert format_timedelta_human(timedelta(seconds=9.3)) == "9.30s"
    assert format_timedelta_human(timedelta(seconds=0.123)) == "123ms"
    assert format_timedelta_human(timedelta(seconds=0.0453)) == "45.3ms"
    assert format_timedelta_human(timedelta(seconds=0.006544)) == "6.54ms"
    assert format_timedelta_human(timedelta(seconds=3.46e-4)) == "346us"
    assert format_timedelta_human(timedelta(seconds=3.42e-5)) == "34us"
    assert format_timedelta_human(timedelta(seconds=5.934e-6)) == "6us"
    assert format_timedelta_human(timedelta(seconds=5.934e-7)) == "1us"
    assert format_timedelta_human(timedelta(seconds=5.934e-8)) == "<1us"