summaryrefslogtreecommitdiff
path: root/numpy/testing/utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'numpy/testing/utils.py')
-rw-r--r--numpy/testing/utils.py47
1 files changed, 45 insertions, 2 deletions
diff --git a/numpy/testing/utils.py b/numpy/testing/utils.py
index 19acd2654..4ea19c270 100644
--- a/numpy/testing/utils.py
+++ b/numpy/testing/utils.py
@@ -56,15 +56,58 @@ else:
""" Return number of jiffies (1/100ths of a second) that this
process has been scheduled in user mode. [Emulation with time.time]. """
return int(100*(time.time()-_load_time))
-
def memusage():
""" Return memory usage of running python. [Not implemented]"""
return
+if os.name=='nt':
+ # Code stolen from enthought/debug/memusage.py
+ import win32pdh
+ # from win32pdhutil, part of the win32all package
+ def GetPerformanceAttributes(object, counter, instance = None,
+ inum=-1, format = win32pdh.PDH_FMT_LONG, machine=None):
+ # NOTE: Many counters require 2 samples to give accurate results,
+ # including "% Processor Time" (as by definition, at any instant, a
+ # thread's CPU usage is either 0 or 100). To read counters like this,
+ # you should copy this function, but keep the counter open, and call
+ # CollectQueryData() each time you need to know.
+ # See http://msdn.microsoft.com/library/en-us/dnperfmo/html/perfmonpt2.asp
+ # My older explanation for this was that the "AddCounter" process forced
+ # the CPU to 100%, but the above makes more sense :)
+ path = win32pdh.MakeCounterPath( (machine,object,instance, None, inum,counter) )
+ hq = win32pdh.OpenQuery()
+ try:
+ hc = win32pdh.AddCounter(hq, path)
+ try:
+ win32pdh.CollectQueryData(hq)
+ type, val = win32pdh.GetFormattedCounterValue(hc, format)
+ return val
+ finally:
+ win32pdh.RemoveCounter(hc)
+ finally:
+ win32pdh.CloseQuery(hq)
+
+ def memusage(processName="python", instance=0):
+ return GetPerformanceAttributes("Process", "Virtual Bytes",
+ processName, instance,
+ win32pdh.PDH_FMT_LONG, None)
+
def assert_equal(actual,desired,err_msg='',verbose=1):
""" Raise an assertion if two items are not
equal. I think this should be part of unittest.py
"""
+ if isinstance(desired, dict):
+ assert isinstance(actual, dict),`type(actual)`
+ assert_equal(len(actual),len(desired),err_msg,verbose)
+ for k,i in desired.items():
+ assert actual.has_key(k),`k`
+ assert_equal(actual[k], desired[k], 'key=%r\n%s' % (k,err_msg), verbose)
+ return
+ if isinstance(desired, list) and isinstance(actual, list):
+ assert_equal(len(actual),len(desired),err_msg,verbose)
+ for k in range(len(desired)):
+ assert_equal(actual[k], desired[k], 'item=%r\n%s' % (k,err_msg), verbose)
+ return
from numpy.core import ArrayType
if isinstance(actual, ArrayType) or isinstance(desired, ArrayType):
return assert_array_equal(actual, desired, err_msg)
@@ -79,7 +122,7 @@ def assert_equal(actual,desired,err_msg='',verbose=1):
+ 'DESIRED: ' + repr(desired) \
+ '\nACTUAL: ' + repr(actual)
assert desired == actual, msg
-
+ return
def assert_almost_equal(actual,desired,decimal=7,err_msg='',verbose=1):
""" Raise an assertion if two items are not