def set_package_path(level=1): """ Prepend package directory to sys.path. set_package_path should be called from a test_file.py that satisfies the following tree structure: <somepath>/<somedir>/test_file.py Then the first existing path name from the following list <somepath>/build/lib.<platform>-<version> <somepath>/.. is prepended to sys.path. The caller is responsible for removing this path by using restore_path() """ from distutils.util import get_platform f = get_frame(level) if f.f_locals['__name__']=='__main__': testfile = sys.argv[0] else: testfile = f.f_locals['__file__'] d = os.path.dirname(os.path.dirname(os.path.abspath(testfile))) d1 = os.path.join(d,'build','lib.%s-%s'%(get_platform(),sys.version[:3])) if not os.path.isdir(d1): d1 = os.path.dirname(d) if DEBUG: print 'Inserting %r to sys.path for test_file %r' % (d1, testfile) sys.path.insert(0,d1) return
def __init__(self, package=None): if package is None: from numpy.distutils.misc_util import get_frame f = get_frame(1) package = f.f_locals.get('__name__',f.f_globals.get('__name__',None)) assert package is not None self.package = package self._rename_map = {}
def __init__(self, package=None): warnings.warn("NumpyTest will be removed in the next release; please update your code to use nose or unittest", DeprecationWarning, stacklevel=2) if package is None: from numpy.distutils.misc_util import get_frame f = get_frame(1) package = f.f_locals.get('__name__',f.f_globals.get('__name__',None)) assert package is not None self.package = package self._rename_map = {}
def __init__(self, package=None): #warnings.warn("NumpyTest will be removed in the next release; please update your code to use nose or unittest", # DeprecationWarning, stacklevel=2) if package is None: from numpy.distutils.misc_util import get_frame f = get_frame(1) package = f.f_locals.get('__name__',f.f_globals.get('__name__',None)) assert package is not None self.package = package self._rename_map = {}
def measure(self,code_str,times=1): """ Return elapsed time for executing code_str in the namespace of the caller for given times. """ frame = get_frame(1) locs,globs = frame.f_locals,frame.f_globals code = compile(code_str, 'NumpyTestCase runner for '+self.__class__.__name__, 'exec') i = 0 elapsed = jiffies() while i<times: i += 1 exec code in globs,locs elapsed = jiffies() - elapsed return 0.01*elapsed
def set_local_path(reldir='', level=1): """ Prepend local directory to sys.path. The caller is responsible for removing this path by using restore_path() """ f = get_frame(level) if f.f_locals['__name__']=='__main__': testfile = sys.argv[0] else: testfile = f.f_locals['__file__'] local_path = os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(testfile)),reldir)) if DEBUG: print 'Inserting %r to sys.path' % (local_path) sys.path.insert(0,local_path) return
def set_local_path(reldir='', level=1): """ Prepend local directory to sys.path. The caller is responsible for removing this path by using restore_path() """ warnings.warn("set_local_path will be removed in NumPy 1.3; please " "update your code", DeprecationWarning, stacklevel=2) f = get_frame(level) if f.f_locals['__name__']=='__main__': testfile = sys.argv[0] else: testfile = f.f_locals['__file__'] local_path = os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(testfile)),reldir)) if DEBUG: print 'Inserting %r to sys.path' % (local_path) sys.path.insert(0,local_path) return
def set_local_path(reldir='', level=1): """ Prepend local directory to sys.path. The caller is responsible for removing this path by using restore_path() """ #warnings.warn("set_local_path will be removed in NumPy 1.3; please " # "update your code", DeprecationWarning, stacklevel=2) f = get_frame(level) if f.f_locals['__name__']=='__main__': testfile = sys.argv[0] else: testfile = f.f_locals['__file__'] local_path = os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(testfile)),reldir)) if DEBUG: print 'Inserting %r to sys.path' % (local_path) sys.path.insert(0,local_path) return
def rundocs(self, filename=None): """ Run doc string tests found in filename. """ import doctest if filename is None: f = get_frame(1) filename = f.f_globals['__file__'] name = os.path.splitext(os.path.basename(filename))[0] path = [os.path.dirname(filename)] file, pathname, description = imp.find_module(name, path) try: m = imp.load_module(name, file, pathname, description) finally: file.close() if sys.version[:3]<'2.4': doctest.testmod(m, verbose=False) else: tests = doctest.DocTestFinder().find(m) runner = doctest.DocTestRunner(verbose=False) for test in tests: runner.run(test) return