Commits

Joe LaFata committed 376d640

fixed python 3 support

Comments (0)

Files changed (2)

src/tests/test_unitbench.py

     from StringIO import StringIO
 else:
     from io import StringIO
+    xrange = range
 
 class NullReporter(Reporter):
     pass
         
         lines = output.strip().split("\n")
         
-        print output
+        print(output)
         eq_(lines[0].find("100"), 7)
         eq_(lines[2].find("Sample1"), 0)
         eq_(lines[3].find("Sample2"), 0)
         
         lines = output.strip().split("\n")
         
-        print output
+        print(output)
         eq_(lines[0].find("Sample1"), 6)
         eq_(lines[1], "======================================================================")
         eq_(lines[2].find("100"), 0)
         stream.close()
         
         lines = output.split("\n")
-        print lines
+        print(output)
         eq_("Name,Value,Call Count,Wall Minimum,Wall Maximum,Wall Average,Wall Standard Deviation,Wall Variance", lines[0])
         eq_("Sample1", lines[1].split(',')[0])
         eq_("10", lines[1].split(',')[1])
     from StringIO import StringIO
     maxint = sys.maxint
     fname = "func_name"
+    dict_iteritems = lambda x: x.iteritems()
+    dict_itervalues = lambda x: x.itervalues()
 else:
     from io import StringIO
     xrange = range
     maxint = sys.maxsize
     fname = "__name__"
+    dict_iteritems = lambda x: x.items()
+    dict_itervalues = lambda x: x.values()
 
 if sys.platform == "win32":
     get_time = time.clock
         if len(kwargs) > 0:
             if len(value) > 0:
                 value += ' '
-            sorted_kwargs = sorted(kwargs.iteritems(), key=itemgetter(0))
+            sorted_kwargs = sorted(dict_iteritems(kwargs), key=itemgetter(0))
             value += '{' + ', '.join(
                  map(lambda x: x[0] + ':' + to_str(x[1]), sorted_kwargs)) + '}'
         return value
             
             func_call.value = FunctionProfiler._args_to_str(*args, **kwargs)   
             func_call.__name__ = func.__name__
-            func_call.func_name = func.func_name
+            func_call.func_name = getattr(func, fname)
             
             r = self._run_benchmark(func_call)
             
             reporter = ConsoleReporter(group_by=ConsoleReporter.GroupType.FUNCTION)
         
         if not self.track_parameters:
-            for val in self.results.itervalues():
+            for val in dict_itervalues(self.results):
                 val.value = "### call count: " + str(len(val.times))
         
         reporter.write_results(self.results.values())
                     func_call = partial(method)
                 func_call.value = value   
                 func_call.__name__ = method.__name__
-                func_call.func_name = method.func_name
+                func_call.func_name = getattr(method, fname)
                 func_call.setup = self.setup
                 func_call.teardown = self.teardown
                 
         results = map(lambda x: x.calculate_stats(), results)
         getter = attrgetter(self.group_by)
         other = attrgetter(ConsoleReporter.GroupType.other(self.group_by))
-        results.sort(key=getter)
-        
+        results = sorted(results, key=getter)
         results = deque(results)
         
         first_title = self.group_by.title() + ": "
             title_set = []
             while len(results) > 0 and getter(results[0]) == title_name:
                 title_set.append(results.popleft())
-            
-            title_set.sort(key=attrgetter("user_mean"), reverse=True)
+            title_set = sorted(title_set, key=attrgetter("user_mean"), reverse=True)
             
             for r in title_set:
                 if (hasattr(r, "user_mean") and
     
     def write_results(self, results):
         results = map(lambda x: x.calculate_stats(), results)
-        results.sort(key=attrgetter("name"))
+        results = sorted(results, key=attrgetter("name"))
         out = self.stream
         
         out.write("Name,Value,Call Count")