]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
ceph-volume: add tests for size_from_human_readable()
authorMohamad Gebai <mgebai@suse.com>
Mon, 1 Apr 2019 23:24:42 +0000 (19:24 -0400)
committerMohamad Gebai <mgebai@suse.com>
Fri, 12 Apr 2019 16:54:08 +0000 (12:54 -0400)
Signed-off-by: Mohamad Gebai <mgebai@suse.com>
src/ceph-volume/ceph_volume/tests/util/test_disk.py

index 3fae20094f64b9b60afc9ad4c96295064ead5877..68068a809ef9856c12f92b017083d15227fa9bfe 100644 (file)
@@ -208,6 +208,45 @@ class TestHumanReadableSize(object):
         assert result == '81.20 TB'
 
 
+class TestSizeFromHumanReadable(object):
+
+    def test_bytes(self):
+        result = disk.size_from_human_readable('2')
+        assert result == disk.Size(b=2)
+
+    def test_kilobytes(self):
+        result = disk.size_from_human_readable('2 K')
+        assert result == disk.Size(kb=2)
+
+    def test_megabytes(self):
+        result = disk.size_from_human_readable('2 M')
+        assert result == disk.Size(mb=2)
+
+    def test_gigabytes(self):
+        result = disk.size_from_human_readable('2 G')
+        assert result == disk.Size(gb=2)
+
+    def test_terrabytes(self):
+        result = disk.size_from_human_readable('2 T')
+        assert result == disk.Size(tb=2)
+
+    def test_case(self):
+        result = disk.size_from_human_readable('2 t')
+        assert result == disk.Size(tb=2)
+
+    def test_space(self):
+        result = disk.size_from_human_readable('2T')
+        assert result == disk.Size(tb=2)
+
+    def test_float(self):
+        result = disk.size_from_human_readable('2.0')
+        assert result == disk.Size(b=2)
+        result = disk.size_from_human_readable('2.0T')
+        assert result == disk.Size(tb=2)
+        result = disk.size_from_human_readable('1.8T')
+        assert result == disk.Size(tb=1.8)
+
+
 class TestGetDevices(object):
 
     def setup_paths(self, tmpdir):