def test_build_search_order1(self): """ MODULE in search path should be replaced by module_dir. """ q = catalog.catalog(['first','MODULE','third']) q.set_module_directory('second') order = q.build_search_order() assert_(order == ['first','second','third',catalog.default_dir()])
def test_build_search_order3(self): """ If MODULE is absent, module_dir shouldn't be in search path. """ q = catalog.catalog(['first','second']) q.set_module_directory('third') order = q.build_search_order() assert_(order == ['first','second',catalog.default_dir()])
def empty_temp_dir(): """Create a sub directory in the temp directory for use in tests""" d = catalog.default_dir() for i in range(10000): new_d = os.path.join(d,tempfile.gettempprefix()[1:-1]+repr(i)) if not os.path.exists(new_d): os.mkdir(new_d) break return new_d
def test_is_writable(self): path = catalog.default_dir() name = os.path.join(path,'dummy_catalog') test_file = open(name,'w') try: test_file.write('making sure default location is writable\n') finally: test_file.close() os.remove(name)
def test_build_search_order4(self): """ Make sure environment variable is getting used. """ q = catalog.catalog(['first','second']) if sys.platform == 'win32': sep = ';' else: sep = ':' os.environ['PYTHONCOMPILED'] = sep.join(('MODULE','fourth','fifth')) q.set_module_directory('third') order = q.build_search_order() assert(order == ['first','second','third','fourth','fifth',catalog.default_dir()])
def test_is_writable(self): # default_dir has to be writable path = catalog.default_dir() name = os.path.join(path, 'dummy_catalog') test_file = open(name, 'w') try: test_file.write('making sure default location is writable\n') finally: test_file.close() os.remove(name)
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]+repr(i)) if not os.path.exists(new_d): os.mkdir(new_d) break return new_d
def restore_temp_catalog(backup_dir): """Remove any catalog from the temp dir""" cat_dir = catalog.default_dir() for file in os.listdir(backup_dir): file = os.path.join(backup_dir,file) d,f = os.path.split(file) dst_file = os.path.join(cat_dir, f) if os.path.exists(dst_file): os.remove(dst_file) move_file(file,dst_file) os.rmdir(backup_dir)
def restore_temp_catalog(backup_dir): """Remove any catalog from the temp dir""" cat_dir = catalog.default_dir() for file in os.listdir(backup_dir): file = os.path.join(backup_dir, file) d, f = os.path.split(file) dst_file = os.path.join(cat_dir, f) if os.path.exists(dst_file): os.remove(dst_file) move_file(file, dst_file) os.rmdir(backup_dir)
def test_build_search_order2(self): """ MODULE in search path should be removed if module_dir==None. """ q = catalog.catalog(['first','MODULE','third']) order = q.build_search_order() assert_(order == ['first','third',catalog.default_dir()])
def test_build_search_order3(self): # If MODULE is absent, module_dir shouldn't be in search path. q = catalog.catalog(['first','second']) q.set_module_directory('third') order = q.build_search_order() assert_(order == ['first','second',catalog.default_dir()])
def test_build_search_order1(self): # MODULE in search path should be replaced by module_dir. q = catalog.catalog(['first','MODULE','third']) q.set_module_directory('second') order = q.build_search_order() assert_(order == ['first','second','third',catalog.default_dir()])
def test_default(self): in_path = catalog.default_dir() path = catalog.catalog_path(in_path) d, f = os.path.split(path) assert_(d == in_path) assert_(f == catalog.os_dependent_catalog_name())
def test_build_search_order2(self): """ MODULE in search path should be removed if module_dir==None. """ q = catalog.catalog(['first', 'MODULE', 'third']) order = q.build_search_order() assert_(order == ['first', 'third', catalog.default_dir()])
def get_weave_cache_dir(): if weave is not None: return default_dir() else: return None
def temp_catalog_files(prefix=''): # might need to add some more platform specific catalog file # suffixes to remove. The .pag was recently added for SunOS d = catalog.default_dir() f = catalog.os_dependent_catalog_name() return glob.glob(os.path.join(d,prefix+f+'*'))
def test_default(self): in_path = catalog.default_dir() path = catalog.catalog_path(in_path) d,f = os.path.split(path) assert_(d == in_path) assert_(f == catalog.os_dependent_catalog_name())
from error_eval import ErrorEval from itertools import combinations, chain from matplotlib import rc from socket import gethostname from spirrid import SPIRRID from scipy import stats, polyval import numpy as np import os.path import pylab as p # import matplotlib with matlab interface import types import shutil from os.path import expanduser from scipy.weave.catalog import default_dir HOME_DIR = expanduser("~") PYTHON_COMPILED_DIR = default_dir() #=============================================================================== # Helper functions #=============================================================================== def Heaviside(x): ''' Heaviside function ''' return x >= 0 def powerset(iterable): ''' Return object of all combination of iterable. powerset([1,2,3]) --> () (1,) (2,) (3,) (1,2) (1,3) (2,3) (1,2,3) ''' s = list(iterable) return chain.from_iterable(combinations(s, r) for r in range(len(s) + 1))