Commits

Joe LaFata committed d933b2f

make a function static
fix a test

  • Participants
  • Parent commits 6f1f0e6

Comments (0)

Files changed (2)

src/tests/test_unitbench.py

         eq_(plus2(8), 10)
         eq_(sum23(), 5)
         eq_(adder(7, 9), 16)
-        eq_(len(fp.results), 4)
+        eq_(adder(1, 1), 2)
+        eq_(len(fp.results), 3)
     
 class TestBenchmark(TestCase):
     def test_warmup(self):
 class FunctionProfiler(BenchBase):
     __slots__ = ["repeats", "warmup", "results"]
     
+    @staticmethod
+    def _args_to_str(self, *args, **kwargs):
+        value = ''
+        if len(args) + len(kwargs) == 0:
+            value = 'None'
+        elif len(kwargs) == 0:
+            value = '(' + str(args) + ')'
+        elif len(args) == 0:
+            value = '(' + str(kwargs) + ')'
+        else:
+            value = '(' + str(args) + ' ' + str(kwargs) + ')'
+        return value
+    
     def __init__(self, repeats=1, warmup=0):
         self.repeats = self._wrap_int(repeats)
         self.warmup = self._wrap_int(warmup)
         def wrapper(*args, **kwargs):
             func_call = partial(func, *args, **kwargs);
             
-            func_call.value = self._args_to_str(args, kwargs)   
+            func_call.value = FunctionProfiler._args_to_str(args, kwargs)   
             func_call.__name__ = func.__name__
             func_call.func_name = func.func_name
             
         results = sorted(self.results, key = lambda x : len(self.results[x]))
         reporter.write_results(results)
     
-    def _args_to_str(self, *args, **kwargs):
-        value = ''
-        if len(args) + len(kwargs) == 0:
-            value = 'None'
-        elif len(kwargs) == 0:
-            value = '(' + str(args) + ')'
-        elif len(args) == 0:
-            value = '(' + str(kwargs) + ')'
-        else:
-            value = '(' + str(args) + ' ' + str(kwargs) + ')'
-        return value
-    
     def _wrap_int(self, x):
         def wrapper():
             return x