Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_naturaldelta_minimum_unit_explicit(minimum_unit, seconds, expected):
# Arrange
delta = dt.timedelta(seconds=seconds)
# Act / Assert
assert humanize.naturaldelta(delta, minimum_unit=minimum_unit) == expected
def nd_nomonths(d):
return humanize.naturaldelta(d, months=False)
if args.show_thread_logs:
strip_child_logger_info(line[:-1])
sys.stdout.buffer.flush()
output.write(line)
process.wait()
if process.returncode:
raise subprocess.CalledProcessError(0, " ".join(command))
eachJob["status"] = True
except:
logger.exception("Failed to execute openfpga flow - " +
eachJob["name"])
if not args.continue_on_fail:
os._exit(1)
eachJob["endtime"] = time.time()
timediff = timedelta(seconds=(eachJob["endtime"]-eachJob["starttime"]))
timestr = humanize.naturaldelta(timediff) if "humanize" in sys.modules \
else str(timediff)
logger.info("%s Finished with returncode %d, Time Taken %s " %
(thread_name, process.returncode, timestr))
eachJob["finished"] = True
no_of_finished_job = sum([not eachJ["finished"] for eachJ in job_list])
logger.info("***** %d runs pending *****" % (no_of_finished_job))
def delta_ago(self):
dt = datetime.utcnow() - self.date
return humanize.naturaldelta(dt)
def update_remaining(self):
if self.last_message.get('estimated_finish'):
estimated_remaining = self.last_message['estimated_finish'] - datetime.now(timezone.utc)
if estimated_remaining < timedelta(seconds=5):
estimated_remaining_str = 'a few seconds'
else:
estimated_remaining_str = humanize.naturaldelta(estimated_remaining)
self.estimated_completion.value_label.set_text(estimated_remaining_str)
self.estimated_completion.show_all()
def get_humanized_exec_time(end, start):
""" Return the time it took a function to run in a human friendly way
:param end: time exactly after method was applied
:param start: time right before method was applied
:return: execution time in human friendly way
"""
exec_time = end - start
exec_time_humanize = humanize.naturaldelta(exec_time)
if exec_time_humanize == "a moment":
exec_time_humanize = f"{exec_time} seconds."
return f"\t* Step Took {exec_time_humanize}"
@Plugin.command('uptime', level=-1)
def command_uptime(self, event):
event.msg.reply('Rowboat was started {}'.format(
humanize.naturaldelta(datetime.utcnow() - self.startup)
))
def summarise_usage():
wall_time = humanize.naturaldelta(time.time() - __before)
user_time = humanize.naturaldelta(os.times().user)
sys_time = os.times().system
if resource is None:
# Don't report max memory on Windows. We could do this using the psutil lib, via
# psutil.Process(os.getpid()).get_ext_memory_info().peak_wset if demand exists
maxmem_str = ""
else:
max_mem = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss
if sys.platform != "darwin":
max_mem *= 1024 # Linux and other OSs (e.g. freeBSD) report maxrss in kb
maxmem_str = "; max memory={}".format(
humanize.naturalsize(max_mem, binary=True)
)
logger.info("wall time = {}".format(wall_time))
logger.info("rusage: user={}; sys={:.2f}s".format(user_time, sys_time) + maxmem_str)
def deltafy(ts):
return humanize.naturaldelta(ts)
def format_duration(self, seconds):
time_format = self._settings.get(["time_format"], merged=True)
if seconds == None:
return "N/A"
delta = datetime.timedelta(seconds=seconds)
time_format = self._settings.get(["time_format"], merged=True)
if time_format == "FUZZY":
return humanize.naturaldelta(delta)
elif time_format == "EXACT":
return octoprint.util.get_formatted_timedelta(delta)
else:
return self.humanize_duration(seconds)