summaryrefslogtreecommitdiffstats
path: root/tests/test_filesize.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_filesize.py')
-rw-r--r--tests/test_filesize.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/tests/test_filesize.py b/tests/test_filesize.py
new file mode 100644
index 0000000..937ef73
--- /dev/null
+++ b/tests/test_filesize.py
@@ -0,0 +1,15 @@
+from rich import filesize
+
+
+def test_traditional():
+ assert filesize.decimal(0) == "0 bytes"
+ assert filesize.decimal(1) == "1 byte"
+ assert filesize.decimal(2) == "2 bytes"
+ assert filesize.decimal(1000) == "1.0 kB"
+ assert filesize.decimal(1.5 * 1000 * 1000) == "1.5 MB"
+
+
+def test_pick_unit_and_suffix():
+ units = ["bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"]
+ assert filesize.pick_unit_and_suffix(50, units, 1024) == (1, "bytes")
+ assert filesize.pick_unit_and_suffix(2048, units, 1024) == (1024, "KB")