소스 검색

Handle ValueError in octal_type

Mike Naberezny 11 년 전
부모
커밋
9eeb9d4da9
2개의 변경된 파일17개의 추가작업 그리고 4개의 파일을 삭제
  1. 1 1
      supervisor/datatypes.py
  2. 16 3
      supervisor/tests/test_datatypes.py

+ 1 - 1
supervisor/datatypes.py

@@ -332,7 +332,7 @@ def gid_for_uid(uid):
 def octal_type(arg):
     try:
         return int(arg, 8)
-    except TypeError:
+    except (TypeError, ValueError):
         raise ValueError('%s can not be converted to an octal type' % arg)
 
 def existing_directory(v):

+ 16 - 3
supervisor/tests/test_datatypes.py

@@ -508,8 +508,21 @@ class TestOctalType(unittest.TestCase):
         from supervisor.datatypes import octal_type
         return octal_type(arg)
 
-    def test_it_success(self):
+    def test_success(self):
         self.assertEqual(self._callFUT('10'), 8)
 
-    def test_test_it_failure(self):
-        self.assertRaises(ValueError, self._callFUT, 'noo')
+    def test_raises_for_non_numeric(self):
+        try:
+            self._callFUT('bad')
+            self.fail()
+        except ValueError, e:
+            expected = 'bad can not be converted to an octal type'
+            self.assertEqual(e.args[0], expected)
+
+    def test_raises_for_unconvertable_numeric(self):
+        try:
+            self._callFUT('1.2')
+            self.fail()
+        except ValueError, e:
+            expected = '1.2 can not be converted to an octal type'
+            self.assertEqual(e.args[0], expected)