Browse Source

[2883] None not acceptable for spec_file_name of the Counters class

Remove condition that spec_file_name is omitted (None is specified). Revise
documentation of Counters and add a unit test to assert an exception raised when
specifying an invalid argument.
Naoki Kambe 11 years ago
parent
commit
8ce213f2e0

+ 2 - 7
src/lib/python/isc/statistics/counters.py

@@ -168,19 +168,14 @@ class Counters():
     def __init__(self, spec_file_name):
         """A constructor for the Counters class. A path to the spec file
         can be specified in spec_file_name, which is required. Statistics data
-        based on statistics spec can be accumulated if spec_file_name is
-        specified. If omitted, a default statistics spec is used. The
-        default statistics spec is defined in a hidden class named
-        _Statistics().
+        based on statistics spec can be accumulated. If an invalid argument
+        including None is specified, ModuleSpecError might be raised.
         """
         self._zones_item_list = []
         self._start_time = {}
         self._disabled = False
         self._rlock = threading.RLock()
         self._statistics_data = {}
-        self._statistics_spec = []
-        if not spec_file_name: return
-        # change the default statistics spec
         self._statistics_spec = \
             isc.config.module_spec_from_file(spec_file_name).\
             get_statistics_spec()

+ 8 - 12
src/lib/python/isc/statistics/tests/counters_test.py

@@ -154,6 +154,14 @@ class TestBasicMethods(unittest.TestCase):
         b = a + ({},)
         self.assertRaises(TypeError, counters._concat, *b)
 
+    def test_none_of_arg_of_counters(self):
+        """Test Counters raises ModuleSpecError when specifying not valid
+        argument"""
+        self.assertRaises(isc.config.module_spec.ModuleSpecError,
+                          counters.Counters, None)
+        self.assertRaises(isc.config.module_spec.ModuleSpecError,
+                          counters.Counters, '/foo/bar')
+
 class BaseTestCounters():
 
     def setUp(self):
@@ -195,18 +203,6 @@ class BaseTestCounters():
         self.assertRaises(isc.cc.data.DataNotFoundError,
                           self.counters.get, '__undefined__')
 
-class TestCounters0(unittest.TestCase, BaseTestCounters):
-    TEST_SPECFILE_LOCATION = None
-    def setUp(self):
-        BaseTestCounters.setUp(self)
-
-    def test_counters(self):
-        self.assertRaises(isc.cc.data.DataNotFoundError, self.counters.inc,
-                          "foo")
-        self.assertRaises(isc.cc.data.DataNotFoundError, self.counters.get,
-                          "foo")
-        self.check_get_statistics()
-
 class TestCounters1(unittest.TestCase, BaseTestCounters):
     TEST_SPECFILE_LOCATION = TESTDATA_SRCDIR + os.sep + 'test_spec1.spec'
     def setUp(self):