Anonymous committed a4be588

Add a testcase for the TupleComp class

Comments (0)

Files changed (1)


 from test import support
 from io import StringIO
 from os import remove
+from functools import cmp_to_key
     def test_add(self):
+        """Add stats object to a stats created from an empty stream
+        """
         stream = StringIO()
         stats = pstats.Stats(stream=stream)
         stats.add(self.stats, self.stats)
         with self.assertRaises(TypeError):
+    def test_sorting_produce_correct_order(self):
+        # can create a fake stats maybe to show the order
+        self.stats.sort_stats("stdname")
+class TupleCompTestCase(unittest.TestCase):
+    def test_tuple_comp_compare_is_correct(self):
+        """Test the internal class TupleComp, to see if the order
+        generated on the tuples is correct
+        """
+        comp_list = [(0, 1), (1, -1), (2, 1)]
+        tup = pstats.TupleComp(comp_list)
+        to_sort = [(1, 3, 4), (2, 3, 1), (5, 4, 3)]
+        desired = to_sort[:]
+        to_sort.sort(key=cmp_to_key(
+        self.assertEqual(to_sort, desired)
+        #TODO: add some failing test, to prove how this tuplecomp really works
 def test_main():
+        TupleCompTestCase,
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.