BIND 10 trac2298_1, updated. bd422245ff8a1a51e4fd1d70ef4399f5590f28ae [2298] add a test for sorting

BIND 10 source code commits bind10-changes at lists.isc.org
Tue Oct 30 09:45:16 UTC 2012


The branch, trac2298_1 has been updated
       via  bd422245ff8a1a51e4fd1d70ef4399f5590f28ae (commit)
       via  f3c3c9b8017a1a9d68135feeb17f395ead12d1ff (commit)
       via  c0b0bf7fe9ac14dbec16310cc84228be1f9cd6d5 (commit)
       via  5fdb1fac02d282ee35f364313ea666ba34812972 (commit)
       via  aa388838a075450e4dffe09e882fa00e6397d9e3 (commit)
       via  3d0e3eca7a2e35bdffe6beedeabe170ff10c9853 (commit)
      from  17fb05b7b88ffdb2aacef30904b5e9c2fbe04fe5 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit bd422245ff8a1a51e4fd1d70ef4399f5590f28ae
Author: Naoki Kambe <kambe at jprs.co.jp>
Date:   Mon Oct 29 20:41:20 2012 +0900

    [2298] add a test for sorting

commit f3c3c9b8017a1a9d68135feeb17f395ead12d1ff
Author: Naoki Kambe <kambe at jprs.co.jp>
Date:   Mon Oct 29 20:54:19 2012 +0900

    [2298] in case of dict change the way to sort by key name

commit c0b0bf7fe9ac14dbec16310cc84228be1f9cd6d5
Author: Naoki Kambe <kambe at jprs.co.jp>
Date:   Tue Oct 30 18:14:49 2012 +0900

    [2298] add comments in test_item_name_list()

commit 5fdb1fac02d282ee35f364313ea666ba34812972
Author: Naoki Kambe <kambe at jprs.co.jp>
Date:   Tue Oct 30 18:00:44 2012 +0900

    [2298] update the docstring of item_name_list()

commit aa388838a075450e4dffe09e882fa00e6397d9e3
Author: Naoki Kambe <kambe at jprs.co.jp>
Date:   Mon Oct 29 20:55:44 2012 +0900

    [2298] use '%d' in formatting an integer instead of '%s'

commit 3d0e3eca7a2e35bdffe6beedeabe170ff10c9853
Author: Naoki Kambe <kambe at jprs.co.jp>
Date:   Mon Oct 29 20:43:23 2012 +0900

    [2298] It was ok to assume the argument identifier to be a string

-----------------------------------------------------------------------

Summary of changes:
 src/bin/stats/stats_httpd.py.in             |   51 ++++++++++++++++++++-------
 src/bin/stats/tests/b10-stats-httpd_test.py |   25 +++++++++++++
 2 files changed, 64 insertions(+), 12 deletions(-)

-----------------------------------------------------------------------
diff --git a/src/bin/stats/stats_httpd.py.in b/src/bin/stats/stats_httpd.py.in
index 1dcfd34..21061db 100644
--- a/src/bin/stats/stats_httpd.py.in
+++ b/src/bin/stats/stats_httpd.py.in
@@ -73,27 +73,54 @@ XSD_NAMESPACE = 'http://bind10.isc.org/bind10'
 isc.util.process.rename()
 
 def item_name_list(element, identifier):
-    """Returns list of items. The first argument elemet is dict-type
-    value to traverse, the second argument is a string separated
-    '/'. This is a start porint to traverse. At the end in the
-    method. The list to be returned is sorted. """
+    """Return a list of strings. The strings are string expression of
+    the first argument element which is dict type. The second argument
+    identifier is a string for specifying the strings which are
+    returned from this method as a list. For example, if we specify as
+
+      item_name_list({'a': {'aa': [0, 1]}, 'b': [0, 1]}, 'a/aa'),
+
+    then it returns
+
+      ['a/aa', 'a/aa[0]', 'a/aa[1]'].
+
+    If an empty string is specified in the second argument, all
+    possible strings are returned as a list.  In that example if we
+    specify an empty string in the second argument, then it returns
+
+      ['a', 'a/aa', 'a/aa[0]', 'a/aa[1]', 'b', 'b[0]', 'b[1]'].
+
+    The key name of element which is in the first argument is sorted.
+    Even if we specify as
+
+      item_name_list({'xx': 0, 'a': 1, 'x': 2}, ''),
+
+    then it returns
+
+      ['a', 'x', 'xx'].
+
+    This method internally invokes isc.cc.data.find(). The arguments
+    of this method are passed to isc.cc.data.find(). So an exception
+    DataNotFoundError or DataTypeError might be raised via
+    isc.cc.data.find() depending on the arguments. See details of
+    isc.cc.data.find() for more information about exceptions"""
     elem = isc.cc.data.find(element, identifier)
     ret = []
-    ident = ''
-    if identifier and len(str(identifier)) > 0:
-        ident = str(identifier)
+    ident = identifier
+    if ident:
         ret.append(ident)
     if type(elem) is dict:
-        if len(ident) > 0:
-            ident = '%s/' % ident
-        for (key, value) in elem.items():
+        if ident:
+            ident = ident + '/'
+        keys = list(elem.keys())
+        keys.sort()
+        for key in keys:
             idstr = '%s%s' % (ident, key)
             ret += item_name_list(element, idstr)
     elif type(elem) is list:
         for i in range(0, len(elem)):
-            idstr = '%s[%s]' % (ident, i)
+            idstr = '%s[%d]' % (ident, i)
             ret += item_name_list(element, idstr)
-    ret.sort()
     return ret
 
 class HttpHandler(http.server.BaseHTTPRequestHandler):
diff --git a/src/bin/stats/tests/b10-stats-httpd_test.py b/src/bin/stats/tests/b10-stats-httpd_test.py
index dda66e8..aa5f456 100644
--- a/src/bin/stats/tests/b10-stats-httpd_test.py
+++ b/src/bin/stats/tests/b10-stats-httpd_test.py
@@ -116,8 +116,10 @@ def is_ipv6_enabled(address='::1', port=8001):
 class TestItemNameList(unittest.TestCase):
 
     def test_item_name_list(self):
+        # for a one-element list
         self.assertEqual(['a'],
                          stats_httpd.item_name_list({'a':1}, 'a'))
+        # for a dict under a dict
         self.assertEqual(['a','a/b'],
                          stats_httpd.item_name_list({'a':{'b':1}}, 'a'))
         self.assertEqual(['a/b'],
@@ -128,18 +130,21 @@ class TestItemNameList(unittest.TestCase):
                          stats_httpd.item_name_list({'a':{'b':{'c':1}}}, 'a/b'))
         self.assertEqual(['a/b/c'],
                          stats_httpd.item_name_list({'a':{'b':{'c':1}}}, 'a/b/c'))
+        # for a list under a dict
         self.assertEqual(['a[2]'],
                          stats_httpd.item_name_list({'a':[1,2,3]}, 'a[2]'))
         self.assertEqual(['a', 'a[0]', 'a[1]', 'a[2]'],
                          stats_httpd.item_name_list({'a':[1,2,3]}, 'a'))
         self.assertEqual(['a', 'a[0]', 'a[1]', 'a[2]'],
                          stats_httpd.item_name_list({'a':[1,2,3]}, ''))
+        # for a list under adict under a dict
         self.assertEqual(['a', 'a/b', 'a/b[0]', 'a/b[1]', 'a/b[2]'],
                          stats_httpd.item_name_list({'a':{'b':[1,2,3]}}, 'a'))
         self.assertEqual(['a', 'a/b', 'a/b[0]', 'a/b[1]', 'a/b[2]'],
                          stats_httpd.item_name_list({'a':{'b':[1,2,3]}}, ''))
         self.assertEqual(['a/b', 'a/b[0]', 'a/b[1]', 'a/b[2]'],
                          stats_httpd.item_name_list({'a':{'b':[1,2,3]}}, 'a/b'))
+        # for a mixed case of the above
         self.assertEqual(['a', 'a/b', 'a/b[0]', 'a/b[1]', 'a/b[2]', 'a/c'],
                          stats_httpd.item_name_list(
                 {'a':{'b':[1,2,3], 'c':1}}, 'a'))
@@ -149,20 +154,40 @@ class TestItemNameList(unittest.TestCase):
         self.assertEqual(['a/c'],
                          stats_httpd.item_name_list(
                 {'a':{'b':[1,2,3], 'c':1}}, 'a/c'))
+        # for specifying a wrong identifier which is not found in
+        # element
         self.assertRaises(isc.cc.data.DataNotFoundError,
                          stats_httpd.item_name_list, {'x':1}, 'a')
+        # for specifying a string in element and an empty string in
+        # identifier
         self.assertEqual([],
                          stats_httpd.item_name_list('a', ''))
+        # for specifying empty strings in element and identifier
         self.assertEqual([],
                          stats_httpd.item_name_list('', ''))
+        # for specifying wrong element, which is an non-empty string,
+        # and an non-empty string in identifier
         self.assertRaises(isc.cc.data.DataTypeError,
                          stats_httpd.item_name_list, 'a', 'a')
+        # for specifying None in element and identifier
         self.assertRaises(isc.cc.data.DataTypeError,
                          stats_httpd.item_name_list, None, None)
+        # for specifying non-dict in element
         self.assertRaises(isc.cc.data.DataTypeError,
                          stats_httpd.item_name_list, [1,2,3], 'a')
         self.assertRaises(isc.cc.data.DataTypeError,
                          stats_httpd.item_name_list, [1,2,3], '')
+        # for checking key names sorted which consist of element
+        num = 11
+        keys = [ 'a', 'aa', 'b' ]
+        keys.sort(reverse=True)
+        dictlist = dict([ (k, list(range(num))) for k in keys ])
+        keys.sort()
+        ans = []
+        for k in keys:
+            ans += [k] + [ '%s[%d]' % (k, i) for i in range(num) ]
+        self.assertEqual(ans,
+                         stats_httpd.item_name_list(dictlist, ''))
 
 class TestHttpHandler(unittest.TestCase):
     """Tests for HttpHandler class"""



More information about the bind10-changes mailing list