def test_import_by_path(self): with self.assertRaises(ImportError): import_by_path('len') with self.assertRaises(ImportError): import_by_path('uwsgi_tasks.tests.unknown_function') main = __import__('__main__') main.local_function = local_function self.assertTrue(local_function is import_by_path('local_function')) self.assertTrue(local_function is import_by_path( 'uwsgi_tasks.tests.local_function')) self.assertTrue( len is import_by_path('{}.len'.format(self.builtin_module)))
def test_import_by_path(self): with self.assertRaises(ImportError): import_by_path('len') with self.assertRaises(ImportError): import_by_path('uwsgi_tasks.tests.unknown_function') main = __import__('__main__') main.local_function = local_function self.assertTrue(local_function is import_by_path('local_function')) self.assertTrue( local_function is import_by_path('uwsgi_tasks.tests.local_function') ) self.assertTrue(len is import_by_path('__builtin__.len'))
def load_function(func_name): func = getattr(saved_tasks, func_name, None) if func: return func return import_by_path(func_name)