Ejemplo n.º 1
0
    def test_add_function_ordered(self):
        clear_temp_catalog()
        q = catalog.catalog()
        import string

        q.add_function('f', string.upper)
        q.add_function('f', string.lower)
        q.add_function('ff', string.find)
        q.add_function('ff', string.replace)
        q.add_function('fff', string.atof)
        q.add_function('fff', string.atoi)
        del q

        # now we're gonna make a new catalog with same code
        # but different functions in a specified module directory
        env_dir = empty_temp_dir()
        r = catalog.catalog(env_dir)
        r.add_function('ff', os.abort)
        r.add_function('ff', os.chdir)
        r.add_function('fff', os.access)
        r.add_function('fff', os.open)
        del r
        # now we're gonna make a new catalog with same code
        # but different functions in a user specified directory
        user_dir = empty_temp_dir()
        s = catalog.catalog(user_dir)
        import re
        s.add_function('fff', re.match)
        s.add_function('fff', re.purge)
        del s

        # open new catalog and make sure it retreives the functions
        # from d catalog instead of the temp catalog (made by q)
        os.environ['PYTHONCOMPILED'] = env_dir
        t = catalog.catalog(user_dir)
        funcs1 = t.get_functions('f')
        funcs2 = t.get_functions('ff')
        funcs3 = t.get_functions('fff')
        restore_temp_catalog()
        # make sure everything is read back in the correct order
        # a little cheating... I'm ignoring any functions that might have
        # been read in from a prior catalog file (such as the defualt one).
        # the test should really be made so that these aren't read in, but
        # until I get this figured out...
        #assert_(funcs1 == [string.lower,string.upper])
        #assert_(funcs2 == [os.chdir,os.abort,string.replace,string.find])
        #assert_(funcs3 == [re.purge,re.match,os.open,
        #                  os.access,string.atoi,string.atof])
        assert_(funcs1[:2] == [string.lower, string.upper]), ` funcs1 `
        assert_(
            funcs2[:4] == [os.chdir, os.abort, string.replace, string.find])
        assert_(
            funcs3[:6] ==
            [re.purge, re.match, os.open, os.access, string.atoi, string.atof])
        cleanup_temp_dir(user_dir)
        cleanup_temp_dir(env_dir)
Ejemplo n.º 2
0
 def test_get_existing_files2(self):
     # Shouldn't get a single file from the temp dir.
     backup_dir = clear_temp_catalog()
     q = catalog.catalog()
     # create a dummy file
     q.add_function('code', os.getpid)
     del q
     q = catalog.catalog()
     files = q.get_existing_files()
     restore_temp_catalog(backup_dir)
     assert_(len(files) == 1)
Ejemplo n.º 3
0
 def test_get_existing_files2(self):
     # Shouldn't get a single file from the temp dir.
     backup_dir = clear_temp_catalog()
     q = catalog.catalog()
     # create a dummy file
     q.add_function('code', os.getpid)
     del q
     q = catalog.catalog()
     files = q.get_existing_files()
     restore_temp_catalog(backup_dir)
     assert_(len(files) == 1)
Ejemplo n.º 4
0
    def test_add_function_ordered(self):
        clear_temp_catalog()
        q = catalog.catalog()
        import string

        q.add_function('f',string.upper)
        q.add_function('f',string.lower)
        q.add_function('ff',string.find)
        q.add_function('ff',string.replace)
        q.add_function('fff',string.atof)
        q.add_function('fff',string.atoi)
        del q

        # now we're gonna make a new catalog with same code
        # but different functions in a specified module directory
        env_dir = empty_temp_dir()
        r = catalog.catalog(env_dir)
        r.add_function('ff',os.abort)
        r.add_function('ff',os.chdir)
        r.add_function('fff',os.access)
        r.add_function('fff',os.open)
        del r
        # now we're gonna make a new catalog with same code
        # but different functions in a user specified directory
        user_dir = empty_temp_dir()
        s = catalog.catalog(user_dir)
        import re
        s.add_function('fff',re.match)
        s.add_function('fff',re.purge)
        del s

        # open new catalog and make sure it retreives the functions
        # from d catalog instead of the temp catalog (made by q)
        os.environ['PYTHONCOMPILED'] = env_dir
        t = catalog.catalog(user_dir)
        funcs1 = t.get_functions('f')
        funcs2 = t.get_functions('ff')
        funcs3 = t.get_functions('fff')
        restore_temp_catalog()
        # make sure everything is read back in the correct order
        # a little cheating... I'm ignoring any functions that might have
        # been read in from a prior catalog file (such as the defualt one).
        # the test should really be made so that these aren't read in, but
        # until I get this figured out...
        #assert_(funcs1 == [string.lower,string.upper])
        #assert_(funcs2 == [os.chdir,os.abort,string.replace,string.find])
        #assert_(funcs3 == [re.purge,re.match,os.open,
        #                  os.access,string.atoi,string.atof])
        assert_(funcs1[:2] == [string.lower,string.upper]),repr(funcs1)
        assert_(funcs2[:4] == [os.chdir,os.abort,string.replace,string.find])
        assert_(funcs3[:6] == [re.purge,re.match,os.open,
                          os.access,string.atoi,string.atof])
        cleanup_temp_dir(user_dir)
        cleanup_temp_dir(env_dir)
Ejemplo n.º 5
0
 def test_get_existing_files2(self):
     """ Shouldn't get a single file from the temp dir.
     """
     clear_temp_catalog()
     q = catalog.catalog()
     # create a dummy file
     import os
     q.add_function('code', os.getpid)
     del q
     q = catalog.catalog()
     files = q.get_existing_files()
     restore_temp_catalog()
     assert(len(files) == 1)
Ejemplo n.º 6
0
 def test_get_existing_files1(self):
     # Shouldn't get any files when temp doesn't exist and no path set.
     backup_dir = clear_temp_catalog()
     q = catalog.catalog()
     files = q.get_existing_files()
     restore_temp_catalog(backup_dir)
     assert_(len(files) == 0)
Ejemplo n.º 7
0
 def test_catalog_files2(self):
     """ Ignore bad paths in the path.
     """
     q = catalog.catalog()
     os.environ['PYTHONCOMPILED'] = '_some_bad_path_'
     files = q.get_catalog_files()
     assert_(len(files) == 1)
Ejemplo n.º 8
0
 def test_get_environ_path(self):
     if sys.platform == 'win32': sep = ';'
     else: sep = ':'
     os.environ['PYTHONCOMPILED'] = sep.join(('path1', 'path2', 'path3'))
     q = catalog.catalog()
     path = q.get_environ_path()
     assert_(path == ['path1', 'path2', 'path3'])
Ejemplo n.º 9
0
 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()])
Ejemplo n.º 10
0
 def test_get_existing_files1(self):
     # Shouldn't get any files when temp doesn't exist and no path set.
     backup_dir = clear_temp_catalog()
     q = catalog.catalog()
     files = q.get_existing_files()
     restore_temp_catalog(backup_dir)
     assert_(len(files) == 0)
Ejemplo n.º 11
0
 def test_clear_module_directory(self):
     q = catalog.catalog()
     r = q.get_module_directory()
     assert_(r is None)
     q.set_module_directory('bob')
     r = q.clear_module_directory()
     assert_(r is None)
Ejemplo n.º 12
0
 def test_get_environ_path(self):
     if sys.platform == 'win32': sep = ';'
     else: sep = ':'
     os.environ['PYTHONCOMPILED'] = sep.join(('path1','path2','path3'))
     q = catalog.catalog()
     path = q.get_environ_path()
     assert_(path == ['path1','path2','path3'])
Ejemplo n.º 13
0
 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()])
Ejemplo n.º 14
0
 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()])
Ejemplo n.º 15
0
 def test_catalog_files2(self):
     """ Ignore bad paths in the path.
     """
     q = catalog.catalog()
     os.environ['PYTHONCOMPILED'] = '_some_bad_path_'
     files = q.get_catalog_files()
     assert_(len(files) == 1)
Ejemplo n.º 16
0
 def test_clear_module_directory(self):
     q = catalog.catalog()
     r = q.get_module_directory()
     assert_(r is None)
     q.set_module_directory('bob')
     r = q.clear_module_directory()
     assert_(r is None)
Ejemplo n.º 17
0
 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()])
Ejemplo n.º 18
0
 def test_get_existing_files1(self):
     """ Shouldn't get any files when temp doesn't exist and no path set.
     """
     clear_temp_catalog()
     q = catalog.catalog()
     files = q.get_existing_files()
     restore_temp_catalog()
     assert(len(files) == 0)
Ejemplo n.º 19
0
 def test_access_writable_file(self):
     # There should always be a writable file -- even if it is in temp
     q = catalog.catalog()
     file = q.get_writable_file()
     try:
         f = open(file,'w')
         f.write('bob')
     finally:
         f.close()
         os.remove(file)
Ejemplo n.º 20
0
 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()])
Ejemplo n.º 21
0
 def test_access_writable_file(self):
     # There should always be a writable file -- even if it is in temp
     q = catalog.catalog()
     file = q.get_writable_file()
     try:
         f = open(file,'w')
         f.write('bob')
     finally:
         f.close()
         os.remove(file)
Ejemplo n.º 22
0
 def test_writable_dir(self):
     # Check that we can create a file in the writable directory
     q = catalog.catalog()
     d = q.get_writable_dir()
     file = os.path.join(d,'some_silly_file')
     try:
         f = open(file,'w')
         f.write('bob')
     finally:
         f.close()
         os.remove(file)
Ejemplo n.º 23
0
 def test_writable_dir(self):
     # Check that we can create a file in the writable directory
     q = catalog.catalog()
     d = q.get_writable_dir()
     file = os.path.join(d,'some_silly_file')
     try:
         f = open(file,'w')
         f.write('bob')
     finally:
         f.close()
         os.remove(file)
Ejemplo n.º 24
0
 def test_add_function_persistent1(self):
     # Test persisting a function in the default catalog
     backup_dir = clear_temp_catalog()
     q = catalog.catalog()
     # just use some already available functions
     funcs = [string.upper, string.lower, string.find,string.replace]
     for i in funcs:
         q.add_function_persistent('code',i)
     pfuncs = q.get_cataloged_functions('code')
     # any way to clean modules???
     restore_temp_catalog(backup_dir)
     for i in funcs:
         assert_(i in pfuncs)
Ejemplo n.º 25
0
 def test_add_function_persistent1(self):
     # Test persisting a function in the default catalog
     backup_dir = clear_temp_catalog()
     q = catalog.catalog()
     # just use some already available functions
     funcs = [string.upper, string.lower, string.find,string.replace]
     for i in funcs:
         q.add_function_persistent('code',i)
     pfuncs = q.get_cataloged_functions('code')
     # any way to clean modules???
     restore_temp_catalog(backup_dir)
     for i in funcs:
         assert_(i in pfuncs)
Ejemplo n.º 26
0
 def test_writable_with_bad_path(self):
     """ There should always be a writable file -- even if search paths contain
         bad values.
     """
     if sys.platform == 'win32': sep = ';'
     else: sep = ':'
     os.environ['PYTHONCOMPILED'] = sep.join(('_bad_path_name_'))
     q = catalog.catalog()
     file = q.get_writable_file()
     try:
         f = open(file,'w')
         f.write('bob')
     finally:
         f.close()
     os.remove(file)
Ejemplo n.º 27
0
 def test_unique_module_name(self):
     # Check that we can create a file in the writable directory
     q = catalog.catalog()
     file = q.unique_module_name('bob')
     cfile1 = file+'.cpp'
     assert_(not os.path.exists(cfile1))
     # Make sure it is writable
     try:
         f = open(cfile1,'w')
         f.write('bob')
     finally:
         f.close()
     # try again with same code fragment -- should get unique name
     file = q.unique_module_name('bob')
     cfile2 = file+'.cpp'
     assert_(not os.path.exists(cfile2+'.cpp'))
     os.remove(cfile1)
Ejemplo n.º 28
0
 def test_unique_module_name(self):
     # Check that we can create a file in the writable directory
     q = catalog.catalog()
     file = q.unique_module_name('bob')
     cfile1 = file+'.cpp'
     assert_(not os.path.exists(cfile1))
     # Make sure it is writable
     try:
         f = open(cfile1,'w')
         f.write('bob')
     finally:
         f.close()
     # try again with same code fragment -- should get unique name
     file = q.unique_module_name('bob')
     cfile2 = file+'.cpp'
     assert_(not os.path.exists(cfile2+'.cpp'))
     os.remove(cfile1)
Ejemplo n.º 29
0
 def test_set_module_directory(self):
     q = catalog.catalog()
     q.set_module_directory('bob')
     r = q.get_module_directory()
     assert_(r == 'bob')
Ejemplo n.º 30
0
 def test_catalog_files1(self):
     """ Be sure we get at least one file even without specifying the path.
     """
     q = catalog.catalog()
     files = q.get_catalog_files()
     assert_(len(files) == 1)
Ejemplo n.º 31
0
 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()])
Ejemplo n.º 32
0
# should re-write compiled functions to take a local and global dict
# as input.
from numpy.core.multiarray import _get_ndarray_c_version
import os
import platform
import scipy.weave.catalog as catalog
import scipy.weave.common_info as common_info
import scipy.weave.ext_tools as ext_tools
import sys

ndarray_api_version = '/* NDARRAY API VERSION %x */' % (_get_ndarray_c_version(),)

# not an easy way for the user_path_list to come in here.
# the PYTHONCOMPILED environment variable offers the most hope.

function_catalog = catalog.catalog()

class inline_ext_function(ext_tools.ext_function):
    # Some specialization is needed for inline extension functions
    def function_declaration_code(self):
        code = 'static PyObject* %s(PyObject*self, PyObject* args)\n{\n'
        return code % self.name

    def template_declaration_code(self):
        code = 'template<class T>\n' \
               'static PyObject* %s(PyObject*self, PyObject* args)\n{\n'
        return code % self.name

    def parse_tuple_code(self):
        """ Create code block for PyArg_ParseTuple.  Variable declarations
            for all PyObjects are done also.
Ejemplo n.º 33
0
 def test_set_module_directory(self):
     q = catalog.catalog()
     q.set_module_directory('bob')
     r = q.get_module_directory()
     assert_(r == 'bob')
Ejemplo n.º 34
0
 def test_catalog_files1(self):
     """ Be sure we get at least one file even without specifying the path.
     """
     q = catalog.catalog()
     files = q.get_catalog_files()
     assert_(len(files) == 1)
Ejemplo n.º 35
0
 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()])
Ejemplo n.º 36
0
# should re-write compiled functions to take a local and global dict
# as input.
from numpy.core.multiarray import _get_ndarray_c_version
import os
import platform
import scipy.weave.catalog as catalog
import scipy.weave.common_info as common_info
import scipy.weave.ext_tools as ext_tools
import sys

ndarray_api_version = "/* NDARRAY API VERSION %x */" % (_get_ndarray_c_version(),)

# not an easy way for the user_path_list to come in here.
# the PYTHONCOMPILED environment variable offers the most hope.

function_catalog = catalog.catalog()


class inline_ext_function(ext_tools.ext_function):
    # Some specialization is needed for inline extension functions
    def function_declaration_code(self):
        code = "static PyObject* %s(PyObject*self, PyObject* args)\n{\n"
        return code % self.name

    def template_declaration_code(self):
        code = "template<class T>\n" "static PyObject* %s(PyObject*self, PyObject* args)\n{\n"
        return code % self.name

    def parse_tuple_code(self):
        """ Create code block for PyArg_ParseTuple.  Variable declarations
            for all PyObjects are done also.