Browse Source

[trac930] modify b10-stats_test.py
- set the constant variables in the setUp method in the TestUtilties class,
and compare values returned from the functions with these constants in
testing methods.

[trac930] remove the tearDown method which has no test case in the TestCallback
class

Naoki Kambe 13 years ago
parent
commit
e18a678b62
1 changed files with 10 additions and 8 deletions
  1. 10 8
      src/bin/stats/tests/b10-stats_test.py

+ 10 - 8
src/bin/stats/tests/b10-stats_test.py

@@ -56,6 +56,13 @@ class TestUtilties(unittest.TestCase):
         { 'item_name': 'test_none',  'item_type': 'none'    }
         { 'item_name': 'test_none',  'item_type': 'none'    }
         ]
         ]
 
 
+    def setUp(self):
+        self.const_timestamp = 1308730448.965706
+        self.const_timetuple = (2011, 6, 22, 8, 14, 8, 2, 173, 0)
+        self.const_datetime = '2011-06-22T08:14:08Z'
+        stats.time = lambda : self.const_timestamp
+        stats.gmtime = lambda : self.const_timetuple
+
     def test_get_spec_defaults(self):
     def test_get_spec_defaults(self):
         self.assertEqual(
         self.assertEqual(
             stats.get_spec_defaults(self.items), {
             stats.get_spec_defaults(self.items), {
@@ -76,14 +83,12 @@ class TestUtilties(unittest.TestCase):
         self.assertRaises(KeyError, stats.get_spec_defaults, [{'item_name':'Foo'}])
         self.assertRaises(KeyError, stats.get_spec_defaults, [{'item_name':'Foo'}])
 
 
     def test_get_timestamp(self):
     def test_get_timestamp(self):
-        self.assertEqual(stats.get_timestamp(), 1308730448.965706)
+        self.assertEqual(stats.get_timestamp(), self.const_timestamp)
 
 
     def test_get_datetime(self):
     def test_get_datetime(self):
-        stats.time = lambda : 1308730448.965706
-        stats.gmtime = lambda : (2011, 6, 22, 8, 14, 8, 2, 173, 0)
-        self.assertEqual(stats.get_datetime(), '2011-06-22T08:14:08Z')
+        self.assertEqual(stats.get_datetime(), self.const_datetime)
         self.assertNotEqual(stats.get_datetime(
         self.assertNotEqual(stats.get_datetime(
-                (2011, 6, 22, 8, 23, 40, 2, 173, 0)), '2011-06-22T08:14:08Z')
+                (2011, 6, 22, 8, 23, 40, 2, 173, 0)), self.const_datetime)
 
 
 class TestCallback(unittest.TestCase):
 class TestCallback(unittest.TestCase):
     def setUp(self):
     def setUp(self):
@@ -108,9 +113,6 @@ class TestCallback(unittest.TestCase):
             args=self.dummy_args
             args=self.dummy_args
             )
             )
 
 
-    def tearDown(self):
-        pass
-
     def test_init(self):
     def test_init(self):
         self.assertEqual((self.cback1.command, self.cback1.args, self.cback1.kwargs),
         self.assertEqual((self.cback1.command, self.cback1.args, self.cback1.kwargs),
                          (self.dummy_func, self.dummy_args, self.dummy_kwargs))
                          (self.dummy_func, self.dummy_args, self.dummy_kwargs))