Commits

andrea_crotti  committed 68b0922

Add more unit testing for the utility functions

  • Participants
  • Parent commits 892884b
  • Branches pstats

Comments (0)

Files changed (1)

File Lib/test/test_pstats.py

 
 from test import support
 from io import StringIO
-from os import remove
+from os import remove, path
 from functools import cmp_to_key
 
 
-
 class AddCallersTestCase(unittest.TestCase):
     """Tests for pstats.add_callers helper."""
 
         desired = [(1, 3, 4), (2, 3, 1), (5, 4, 3)]
         to_sort.sort(key=cmp_to_key(tup.compare))
         self.assertEqual(to_sort, desired)
+        #TODO: add more tests and make some fail too
+
+
+class UtilsTestCase(unittest.TestCase):
+    def test_count_calls(self):
+        dic = {
+            1: 2, 3: 5
+        }
+        dic_null = {
+            1: 0, 2: 0
+        }
+        self.assertEqual(pstats.count_calls(dic), 7)
+        self.assertEqual(pstats.count_calls(dic_null), 0)
+
+    def test_f8(self):
+        self.assertEqual(pstats.f8(2.3232), '   2.323')
+        self.assertEqual(pstats.f8(0), '   0.000')
+
+    def test_func_name(self):
+        func = ('file', 10, 'name')
+        self.assertEqual(pstats.func_get_function_name(func), 'name')
+
+    def test_strip_path(self):
+        # we should not test for the implementation but sometimes is good to do so
+        func = (path.join('long', 'path'), 10, 'name')
+        desired = ('path', 10, 'name')
+        self.assertEqual(pstats.func_strip_path(func), desired)
 
 
 def test_main():
         AddCallersTestCase,
         StatsTestCase,
         TupleCompTestCase,
+        UtilsTestCase
     )