]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/ceph-volume/ceph_volume/tests/util/test_arg_validators.py
import quincy beta 17.1.0
[ceph.git] / ceph / src / ceph-volume / ceph_volume / tests / util / test_arg_validators.py
index 1e8a49e2624c246b0a2f9ff03008dc00283eee8a..b76f8f6e4176f567e2f8651e6fcea4f0fe34b258 100644 (file)
@@ -87,3 +87,33 @@ class TestValidDevice(object):
     def test_path_is_invalid(self, fake_call, patch_bluestore_label):
         with pytest.raises(argparse.ArgumentError):
             self.validator('/device/does/not/exist')
+
+
+class TestValidFraction(object):
+
+    def setup(self):
+        self.validator = arg_validators.ValidFraction()
+
+    def test_fraction_is_valid(self, fake_call):
+        result = self.validator('0.8')
+        assert result == 0.8
+
+    def test_fraction_not_float(self, fake_call):
+        with pytest.raises(ValueError):
+            self.validator('xyz')
+
+    def test_fraction_is_nan(self, fake_call):
+        with pytest.raises(argparse.ArgumentError):
+            self.validator('NaN')
+
+    def test_fraction_is_negative(self, fake_call):
+        with pytest.raises(argparse.ArgumentError):
+            self.validator('-1.0')
+
+    def test_fraction_is_zero(self, fake_call):
+        with pytest.raises(argparse.ArgumentError):
+            self.validator('0.0')
+
+    def test_fraction_is_greater_one(self, fake_call):
+        with pytest.raises(argparse.ArgumentError):
+            self.validator('1.1')