From: Naoki Kambe Date: Fri, 26 Aug 2011 03:01:47 +0000 (+0900) Subject: [1175] fix wrong list-type handling in the function X-Git-Tag: perftcpdns_before_epoll~135 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=c8bbdd1d74ac313d8b57d8debe4f7b75490e5df2;p=thirdparty%2Fkea.git [1175] fix wrong list-type handling in the function get_spec_defaults and add more tests into test_get_spec_defaults --- diff --git a/src/bin/stats/stats.py.in b/src/bin/stats/stats.py.in index 1beebf51f8..7cedfbfe07 100755 --- a/src/bin/stats/stats.py.in +++ b/src/bin/stats/stats.py.in @@ -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", diff --git a/src/bin/stats/tests/b10-stats_test.py b/src/bin/stats/tests/b10-stats_test.py index 7817d2915e..892032dca7 100644 --- a/src/bin/stats/tests/b10-stats_test.py +++ b/src/bin/stats/tests/b10-stats_test.py @@ -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'}])