def test_output_no_quota(self) -> None: quota = _QuotaInfo( cluster_name="default", gpu_time_spent=0.0, gpu_time_limit=float("inf"), cpu_time_spent=float((9 * 60 + 19) * 60), cpu_time_limit=float("inf"), ) out = QuotaInfoFormatter()(quota) assert out == "\n".join([ f"{bold_start}GPU:{bold_end} spent: 00h 00m (quota: infinity)", f"{bold_start}CPU:{bold_end} spent: 09h 19m (quota: infinity)", ])
async def show_quota(root: Root, user: Optional[str]) -> None: """ Print quota and remaining computation time for active cluster. """ quotas = await root.client._quota.get(user) cluster_name = root.client.config.cluster_name if cluster_name not in quotas: raise ValueError( f"No quota information available for cluster {cluster_name}.\n" "Please logout and login again.") cluster_quota = quotas[cluster_name] fmt = QuotaInfoFormatter() click.echo(fmt(cluster_quota))
def test_output(self) -> None: quota = _QuotaInfo( cluster_name="default", gpu_time_spent=0.0, gpu_time_limit=0.0, cpu_time_spent=float((9 * 60 + 19) * 60), cpu_time_limit=float((9 * 60 + 39) * 60), ) out = QuotaInfoFormatter()(quota) assert out == "\n".join([ f"{bold_start}GPU:{bold_end} spent: 00h 00m " "(quota: 00h 00m, left: 00h 00m)", f"{bold_start}CPU:{bold_end} spent: 09h 19m " "(quota: 09h 39m, left: 00h 20m)", ])
def test_output_spent_more_than_quota_left_zero(self) -> None: quota = _QuotaInfo( cluster_name="default", gpu_time_spent=float(9 * 60 * 60), gpu_time_limit=float(1 * 60 * 60), cpu_time_spent=float(9 * 60 * 60), cpu_time_limit=float(2 * 60 * 60), ) out = QuotaInfoFormatter()(quota) assert out == "\n".join([ f"{bold_start}GPU:{bold_end} spent: 09h 00m " "(quota: 01h 00m, left: 00h 00m)", f"{bold_start}CPU:{bold_end} spent: 09h 00m " "(quota: 02h 00m, left: 00h 00m)", ])
def test_output_too_many_hours(self) -> None: quota = _QuotaInfo( cluster_name="default", gpu_time_spent=float((1 * 60 + 29) * 60), gpu_time_limit=float((9 * 60 + 59) * 60), cpu_time_spent=float((9999 * 60 + 29) * 60), cpu_time_limit=float((99999 * 60 + 59) * 60), ) out = QuotaInfoFormatter()(quota) assert out == "\n".join([ f"{bold_start}GPU:{bold_end} spent: 01h 29m " "(quota: 09h 59m, left: 08h 30m)", f"{bold_start}CPU:{bold_end} spent: 9999h 29m " "(quota: 99999h 59m, left: 90000h 30m)", ])
def test_format_time_9999h_59m(self) -> None: out = QuotaInfoFormatter()._format_time( total_seconds=float((9999 * 60 + 59) * 60)) assert out == "9999h 59m"
def test_format_time_99h_00m(self) -> None: out = QuotaInfoFormatter()._format_time(total_seconds=float(99 * 60 * 60)) assert out == "99h 00m"
def test_format_time_01h_10m(self) -> None: out = QuotaInfoFormatter()._format_time(total_seconds=float(70 * 60)) assert out == "01h 10m"
def test_format_time_00h_09m(self) -> None: out = QuotaInfoFormatter()._format_time(total_seconds=float(9 * 60)) assert out == "00h 09m"