def test_human_readable_bytes(args, kwargs, expected): """ Test the `human_readable_bytes` function. Arguments: args: Positional arguments passed to the function. kwargs: Keyword arguments passed to the function. expected: The expected result. """ assert human_readable_bytes(*args, **kwargs) == expected
def verified_length_string(self, human_readable: bool = True) -> str: """ Return the verified length as string. Arguments: human_readable: Return in human readable format or not. Returns: The verified length string. """ if human_readable: return human_readable_bytes(self.verified_length, delim=" ") return str(self.verified_length) + " B"
def upload_speed_string(self, human_readable: bool = True) -> str: """ Return the upload speed as string. Arguments: human_readable: Return in human readable format or not. Returns: The upload speed string. """ if human_readable: return human_readable_bytes(self.upload_speed, delim=" ", postfix="/s") return str(self.upload_speed) + " B/s"
def test_human_readable_bytes_0_digits(): assert human_readable_bytes(0, digits=0) == "0B"
def test_human_readable_bytes(): assert human_readable_bytes(0) == "0.00B"
def test_human_readable_tera_bytes(): assert human_readable_bytes(2048 * 1024 * 1024 * 1024) == "2.00TiB"
def test_human_readable_giga_bytes(): assert human_readable_bytes(2048 * 1024 * 1024) == "2.00GiB"
def test_human_readable_mebi_bytes(): assert human_readable_bytes(2048 * 1024) == "2.00MiB"
def test_human_readable_kibi_bytes(): assert human_readable_bytes(2048) == "2.00KiB"
def test_human_readable_bytes_all_kwargs(): assert human_readable_bytes(1024, digits=0, delim=" ", postfix="/s") == "1 KiB/s"
def test_human_readable_bytes_with_postfix(): assert human_readable_bytes(0, digits=0, delim=" ", postfix="/s") == "0 B/s"
def test_human_readable_bytes_space_delim(): assert human_readable_bytes(0, digits=0, delim=" ") == "0 B"