1
0
mirror of https://github.com/mikf/gallery-dl.git synced 2024-11-22 02:32:33 +01:00

remove 'unit' argument from 'util.format_value()'

This commit is contained in:
Mike Fährmann 2021-09-28 23:07:55 +02:00
parent 8c29a6e491
commit c22ff97743
No known key found for this signature in database
GPG Key ID: 5680CA389D365A88
3 changed files with 20 additions and 23 deletions

View File

@ -294,15 +294,15 @@ class TerminalOutput(NullOutput):
def progress(self, bytes_total, bytes_downloaded, bytes_per_second):
if bytes_total is None:
print("\r {:>8} {:>10} \r".format(
util.format_value(bytes_downloaded, "B"),
util.format_value(bytes_per_second, "B/s"),
print("\r {:>7}B {:>7}B/s \r".format(
util.format_value(bytes_downloaded),
util.format_value(bytes_per_second),
), end="")
else:
print("\r{:>3}% {:>8} {:>10} \r".format(
print("\r{:>3}% {:>7}B {:>7}B/s \r".format(
bytes_downloaded * 100 // bytes_total,
util.format_value(bytes_downloaded, "B"),
util.format_value(bytes_per_second, "B/s"),
util.format_value(bytes_downloaded),
util.format_value(bytes_per_second),
), end="")

View File

@ -91,15 +91,15 @@ def generate_token(size=16):
return binascii.hexlify(data).decode()
def format_value(value, unit="B", suffixes="kMGTPEZY"):
def format_value(value, suffixes="kMGTPEZY"):
value = format(value)
value_len = len(value)
index = value_len - 4
if index >= 0:
offset = (value_len - 1) % 3 + 1
return (value[:offset] + "." + value[offset:offset+2] +
suffixes[index // 3] + unit)
return value + unit
suffixes[index // 3])
return value
def combine_dict(a, b):

View File

@ -371,20 +371,17 @@ class TestOther(unittest.TestCase):
self.assertRegex(token, r"^[0-9a-f]+$")
def test_format_value(self):
self.assertEqual(util.format_value(0) , "0B")
self.assertEqual(util.format_value(1) , "1B")
self.assertEqual(util.format_value(12) , "12B")
self.assertEqual(util.format_value(123) , "123B")
self.assertEqual(util.format_value(1234) , "1.23kB")
self.assertEqual(util.format_value(12345) , "12.34kB")
self.assertEqual(util.format_value(123456) , "123.45kB")
self.assertEqual(util.format_value(1234567) , "1.23MB")
self.assertEqual(util.format_value(12345678) , "12.34MB")
self.assertEqual(util.format_value(123456789) , "123.45MB")
self.assertEqual(util.format_value(1234567890), "1.23GB")
self.assertEqual(util.format_value(123 , "B/s"), "123B/s")
self.assertEqual(util.format_value(123456, "B/s"), "123.45kB/s")
self.assertEqual(util.format_value(0) , "0")
self.assertEqual(util.format_value(1) , "1")
self.assertEqual(util.format_value(12) , "12")
self.assertEqual(util.format_value(123) , "123")
self.assertEqual(util.format_value(1234) , "1.23k")
self.assertEqual(util.format_value(12345) , "12.34k")
self.assertEqual(util.format_value(123456) , "123.45k")
self.assertEqual(util.format_value(1234567) , "1.23M")
self.assertEqual(util.format_value(12345678) , "12.34M")
self.assertEqual(util.format_value(123456789) , "123.45M")
self.assertEqual(util.format_value(1234567890), "1.23G")
def test_combine_dict(self):
self.assertEqual(