From 0366f880d5222251ce4b6833fa556d11d1e47229 Mon Sep 17 00:00:00 2001 From: Davanum Srinivas Date: Sun, 1 Feb 2015 15:00:48 -0500 Subject: [PATCH] Better check for integer range to account for 0 We should be using "if value is not None" to better check for the condition where the value is 0 and 0 is not in the valid range. Co-Authored-By: Longjie_Cao Closes-Bug: #1416212 Change-Id: Ie5c81f1916e301619955364b040bdc7a9275e29c --- oslo_config/tests/test_types.py | 1 + oslo_config/types.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/oslo_config/tests/test_types.py b/oslo_config/tests/test_types.py index 1d8e160c..3824adb9 100644 --- a/oslo_config/tests/test_types.py +++ b/oslo_config/tests/test_types.py @@ -208,6 +208,7 @@ class IntegerTypeTests(TypeTestHelper, unittest.TestCase): t(123) t(300) t(456) + self.assertRaises(ValueError, t, 0) self.assertRaises(ValueError, t, 457) diff --git a/oslo_config/types.py b/oslo_config/types.py index 9b646e25..ed40dfc2 100644 --- a/oslo_config/types.py +++ b/oslo_config/types.py @@ -144,7 +144,7 @@ class Integer(ConfigType): else: value = int(value) - if value: + if value is not None: self._check_range(value) return value