Beispiel #1
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)
Beispiel #2
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)
Beispiel #3
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)
Beispiel #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)
Beispiel #5
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)
Beispiel #6
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)
Beispiel #7
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)
Beispiel #8
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 = [str.upper, str.lower, str.find, str.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)
Beispiel #9
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)
Beispiel #10
0
 def test_add_function_persistent1(self):
     """ Test persisting a function in the default catalog
     """
     clear_temp_catalog()
     q = catalog.catalog()
     # just use some already available functions
     import string
     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()
     for i in funcs:
         assert_(i in pfuncs)