move files into a package structure

This commit is contained in:
2022-02-06 16:02:54 +01:00
parent 8bb4ca0563
commit 5428553a1e
28 changed files with 23 additions and 26 deletions

29
raven/util/conversion.py Normal file
View File

@@ -0,0 +1,29 @@
import unittest
def humanbytes(bytes: int) -> str:
"""non-localized conversion of bytes to human readable strings"""
powers = {0: 'bytes', 1: 'KB', 2: 'MB', 3: 'GB', 4: 'TB', 5: 'PB', 6: 'EB'}
power = 1
result = "%d bytes" % bytes
while bytes >= 1024 ** power and power in powers:
result = "%.3f" % (bytes / (1024 ** power))
result = result.rstrip("0")
result = result.rstrip(".")
result = result + " " + powers[power]
power = power + 1
return result
class TestLogFileModel(unittest.TestCase):
def test_humanbytes(self):
inputs = {
0: "0 bytes",
1023: "1023 bytes",
1024: "1 KB",
1048575: "1023.999 KB",
1048576: "1 MB",
}
for input in inputs.keys():
actual = humanbytes(input)
self.assertEqual(inputs[input], actual)