Change decimal_suffix param to binary_units

This commit is contained in:
amartya-dev 2020-10-14 19:47:22 +05:30
parent ca493491e4
commit 9982ce394a
3 changed files with 10 additions and 10 deletions

View file

@ -20,7 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added highlighting of EUI-48 and EUI-64 (MAC addresses)
- Added Console.pager
- Added Console.out
- Added decimal_suffix in progress download column
- Added binary_units in progress download column
### Changed

View file

@ -294,27 +294,27 @@ class DownloadColumn(ProgressColumn):
"""Renders file size downloaded and total, e.g. '0.5/2.3 GB'.
Args:
decimal_suffix (bool, optional): Flag to renser filesize in desired format, disable to render in binary. Defaults to True.
binary_units (bool, optional): Flag to renser filesize in desired format, disable to render in binary. Defaults to True.
"""
def __init__(self, decimal_suffix: bool = True) -> None:
self.decimal_ssuffix = decimal_suffix
def __init__(self, binary_units: bool = False) -> None:
self.binary_units = binary_units
super().__init__()
def render(self, task: "Task") -> Text:
"""Calculate common unit for completed and total."""
completed = int(task.completed)
total = int(task.total)
if self.decimal_ssuffix:
unit, suffix = filesize.pick_unit_and_suffix(
total, ["bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"], 1000
)
else:
if self.binary_units:
unit, suffix = filesize.pick_unit_and_suffix(
total,
["bytes", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB"],
1024,
)
else:
unit, suffix = filesize.pick_unit_and_suffix(
total, ["bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"], 1000
)
completed_ratio = completed / unit
total_ratio = total / unit
precision = 0 if unit == 1 else 1

View file

@ -90,7 +90,7 @@ def test_download_progress_uses_decimal_units() -> None:
def test_download_progress_uses_binary_units() -> None:
column = DownloadColumn(decimal_suffix=False)
column = DownloadColumn(binary_units=True)
test_task = Task(1, "test", 1024, 512, _get_time=lambda: 1.0)
rendered_progress = str(column.render(test_task))
expected = "0.5/1.0 KiB"