]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[1175] fix wrong list-type handling in the function
authorNaoki Kambe <kambe@jprs.co.jp>
Fri, 26 Aug 2011 03:01:47 +0000 (12:01 +0900)
committerNaoki Kambe <kambe@jprs.co.jp>
Mon, 3 Oct 2011 02:52:51 +0000 (11:52 +0900)
get_spec_defaults and add more tests into test_get_spec_defaults

src/bin/stats/stats.py.in
src/bin/stats/tests/b10-stats_test.py

index 1beebf51f8f4f463f9a0f67dcabfd30b33be8c89..7cedfbfe0739f6471942e2e1fe7f50c15a8c55c9 100755 (executable)
@@ -88,7 +88,7 @@ def get_spec_defaults(spec):
         elif item_type == "list":
             return spec.get(
                     "item_default",
-                    [ _get_spec_defaults(s) for s in spec["list_item_spec"] ])
+                    [ _get_spec_defaults(spec["list_item_spec"]) ])
         elif item_type == "map":
             return spec.get(
                     "item_default",
index 7817d2915eb4fe852264d74681444ab1b9e86066..892032dca7a9815cd468bb2a3534771a215dc491 100644 (file)
@@ -43,9 +43,7 @@ class TestUtilties(unittest.TestCase):
         { 'item_name': 'test_bool1', 'item_type': 'boolean', 'item_default': True       },
         { 'item_name': 'test_str1',  'item_type': 'string',  'item_default': 'ABCD'     },
         { 'item_name': 'test_list1', 'item_type': 'list',    'item_default': [1,2,3],
-          'list_item_spec' : [ { 'item_name': 'one',   'item_type': 'integer' },
-                               { 'item_name': 'two',   'item_type': 'integer' },
-                               { 'item_name': 'three', 'item_type': 'integer' } ] },
+          'list_item_spec' : { 'item_name': 'number',   'item_type': 'integer' } },
         { 'item_name': 'test_map1',  'item_type': 'map',     'item_default': {'a':1,'b':2,'c':3},
           'map_item_spec'  : [ { 'item_name': 'a',   'item_type': 'integer'},
                                { 'item_name': 'b',   'item_type': 'integer'},
@@ -55,14 +53,18 @@ class TestUtilties(unittest.TestCase):
         { 'item_name': 'test_bool2', 'item_type': 'boolean' },
         { 'item_name': 'test_str2',  'item_type': 'string'  },
         { 'item_name': 'test_list2', 'item_type': 'list',
-          'list_item_spec' : [ { 'item_name': 'one',   'item_type': 'integer' },
-                               { 'item_name': 'two',   'item_type': 'integer' },
-                               { 'item_name': 'three', 'item_type': 'integer' } ] },
+          'list_item_spec' : { 'item_name': 'number',   'item_type': 'integer' } },
         { 'item_name': 'test_map2',  'item_type': 'map',
           'map_item_spec'  : [ { 'item_name': 'A', 'item_type': 'integer'},
                                { 'item_name': 'B', 'item_type': 'integer'},
                                { 'item_name': 'C', 'item_type': 'integer'} ] },
-        { 'item_name': 'test_none',  'item_type': 'none'    }
+        { 'item_name': 'test_none',  'item_type': 'none'    },
+        { 'item_name': 'test_list3', 'item_type': 'list',    'item_default': ["one","two","three"],
+          'list_item_spec' : { 'item_name': 'number', 'item_type': 'string' } },
+        { 'item_name': 'test_map3',  'item_type': 'map',     'item_default': {'a':'one','b':'two','c':'three'},
+          'map_item_spec'  : [ { 'item_name': 'a', 'item_type': 'string'},
+                               { 'item_name': 'b', 'item_type': 'string'},
+                               { 'item_name': 'c', 'item_type': 'string'} ] }
         ]
 
     def setUp(self):
@@ -85,9 +87,11 @@ class TestUtilties(unittest.TestCase):
                 'test_real2' : 0.0,
                 'test_bool2' : False,
                 'test_str2'  : "",
-                'test_list2' : [0,0,0],
+                'test_list2' : [0],
                 'test_map2'  : { 'A' : 0, 'B' : 0, 'C' : 0 },
-                'test_none'  : None })
+                'test_none'  : None,
+                'test_list3' : [ "one", "two", "three" ],
+                'test_map3'  : { 'a' : 'one', 'b' : 'two', 'c' : 'three' } })
         self.assertEqual(stats.get_spec_defaults(None), {})
         self.assertRaises(KeyError, stats.get_spec_defaults, [{'item_name':'Foo'}])