diff options
author | Eric Jones <eric@enthought.com> | 2002-01-03 19:50:46 +0000 |
---|---|---|
committer | Eric Jones <eric@enthought.com> | 2002-01-03 19:50:46 +0000 |
commit | 6e13c0408681ef82fc5f70d002d34993f19cc659 (patch) | |
tree | fbaba261253d70c119dcdbf343dbfccb84fbcad1 /weave/tests/compiler_test_utils.py | |
parent | 7161eb8ef2587dea3e8066bf209d0fe715057d0c (diff) | |
download | numpy-6e13c0408681ef82fc5f70d002d34993f19cc659.tar.gz |
renaming compiler to weave
Diffstat (limited to 'weave/tests/compiler_test_utils.py')
-rwxr-xr-x | weave/tests/compiler_test_utils.py | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/weave/tests/compiler_test_utils.py b/weave/tests/compiler_test_utils.py new file mode 100755 index 000000000..110e7f240 --- /dev/null +++ b/weave/tests/compiler_test_utils.py @@ -0,0 +1,99 @@ +import os,sys,string +import pprint + +def remove_whitespace(in_str): + import string + out = string.replace(in_str," ","") + out = string.replace(out,"\t","") + out = string.replace(out,"\n","") + return out + +def print_assert_equal(test_string,actual,desired): + """this should probably be in scipy_test + """ + try: + assert(actual == desired) + except AssertionError: + import cStringIO + msg = cStringIO.StringIO() + msg.write(test_string) + msg.write(' failed\nACTUAL: \n') + pprint.pprint(actual,msg) + msg.write('DESIRED: \n') + pprint.pprint(desired,msg) + raise AssertionError, msg.getvalue() + +################################################### +# mainly used by catalog tests +################################################### +from scipy_distutils.misc_util import add_grandparent_to_path,restore_path + +add_grandparent_to_path(__name__) +import catalog +restore_path() + +def temp_catalog_files(): + d = catalog.default_dir() + f = catalog.os_dependent_catalog_name() + suffixes = ['.dat','.dir',''] + cat_files = [os.path.join(d,f+suffix) for suffix in suffixes] + return cat_files + +def clear_temp_catalog(): + """ Remove any catalog from the temp dir + """ + cat_files = temp_catalog_files() + for catalog_file in cat_files: + if os.path.exists(catalog_file): + if os.path.exists(catalog_file+'.bak'): + os.remove(catalog_file+'.bak') + os.rename(catalog_file,catalog_file+'.bak') + +def restore_temp_catalog(): + """ Remove any catalog from the temp dir + """ + cat_files = temp_catalog_files() + for catalog_file in cat_files: + if os.path.exists(catalog_file+'.bak'): + if os.path.exists(catalog_file): + os.remove(catalog_file) + os.rename(catalog_file+'.bak',catalog_file) + +def empty_temp_dir(): + """ Create a sub directory in the temp directory for use in tests + """ + import tempfile + d = catalog.default_dir() + for i in range(10000): + new_d = os.path.join(d,tempfile.gettempprefix()[1:-1]+`i`) + if not os.path.exists(new_d): + os.mkdir(new_d) + break + return new_d + +def cleanup_temp_dir(d): + """ Remove a directory created by empty_temp_dir + should probably catch errors + """ + files = map(lambda x,d=d: os.path.join(d,x),os.listdir(d)) + for i in files: + if os.path.isdir(i): + cleanup_temp_dir(i) + else: + os.remove(i) + os.rmdir(d) + +def simple_module(directory,name,function_prefix,count=2): + module_name = os.path.join(directory,name+'.py') + func = "def %(function_prefix)s%(fid)d():\n pass\n" + code = '' + for fid in range(count): + code+= func % locals() + open(module_name,'w').write(code) + sys.path.append(directory) + exec "import " + name + funcs = [] + for i in range(count): + funcs.append(eval(name+'.'+function_prefix+`i`)) + sys.path = sys.path[:-1] + return module_name, funcs |