From 3253e1933a981b865683d46831f87fce060a75b1 Mon Sep 17 00:00:00 2001 From: Alfredo Deza Date: Wed, 2 Jan 2019 14:18:14 -0500 Subject: [PATCH] ceph-volume tests.util ensure ints and strings with commas can be converted to ints Signed-off-by: Alfredo Deza (cherry picked from commit 91bc3a1479c550be7b48128d5755228a2007e4b0) --- .../ceph_volume/tests/util/test_util.py | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/ceph-volume/ceph_volume/tests/util/test_util.py b/src/ceph-volume/ceph_volume/tests/util/test_util.py index edea219fdad91..2d3f904f85b3a 100644 --- a/src/ceph-volume/ceph_volume/tests/util/test_util.py +++ b/src/ceph-volume/ceph_volume/tests/util/test_util.py @@ -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: -- 2.39.5