]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph-volume tests.util ensure ints and strings with commas can be converted to ints 25775/head
authorAlfredo Deza <adeza@redhat.com>
Wed, 2 Jan 2019 19:18:14 +0000 (14:18 -0500)
committerAlfredo Deza <adeza@redhat.com>
Tue, 8 Jan 2019 15:40:41 +0000 (10:40 -0500)
Signed-off-by: Alfredo Deza <adeza@redhat.com>
(cherry picked from commit 91bc3a1479c550be7b48128d5755228a2007e4b0)

src/ceph-volume/ceph_volume/tests/util/test_util.py

index edea219fdad915e7a55d3b53c5e135a81b53e3b4..2d3f904f85b3a2bb7dceba2f7e0ee77ab8bf0529 100644 (file)
@@ -23,12 +23,19 @@ class TestStrToInt(object):
         result = util.str_to_int("1,99", round_down=False)
         assert result == 2
 
-    def test_passing_a_float_str(self):
-        result = util.str_to_int("1.99")
+    @pytest.mark.parametrize("value", ['2', 2])
+    def test_passing_an_int(self, value):
+        result = util.str_to_int(value)
+        assert result == 2
+
+    @pytest.mark.parametrize("value", ['1.99', 1.99])
+    def test_passing_a_float(self, value):
+        result = util.str_to_int(value)
         assert result == 1
 
-    def test_passing_a_float_does_not_round(self):
-        result = util.str_to_int("1.99", round_down=False)
+    @pytest.mark.parametrize("value", ['1.99', 1.99])
+    def test_passing_a_float_does_not_round(self, value):
+        result = util.str_to_int(value, round_down=False)
         assert result == 2
 
     def test_text_is_not_an_integer_like(self):
@@ -36,6 +43,11 @@ class TestStrToInt(object):
             util.str_to_int("1.4GB")
         assert str(error.value) == "Unable to convert to integer: '1.4GB'"
 
+    def test_input_is_not_string(self):
+        with pytest.raises(RuntimeError) as error:
+            util.str_to_int(None)
+        assert str(error.value) == "Unable to convert to integer: 'None'"
+
 
 def true_responses(upper_casing=False):
     if upper_casing: