Ejemplo n.º 1
0
 def _load_filter(self, filter):
     """loads the filter"""
     module, attr = filter.rsplit('.', 1)
     try:
         mod = import_module(module)
     except ImportError, e:
         raise ImproperlyConfigured('Error importing filter module %s: "%s"' % (module, e))
Ejemplo n.º 2
0
 def _load_default_handler(self):
     """loads the default handler"""
     module, attr = settings.DEFAULT_HANDLER.rsplit('.', 1)
     try:
         mod = import_module(module)
     except ImportError, e:
         raise ImproperlyConfigured('Error importing default handler module %s: "%s"' % (module, e))
Ejemplo n.º 3
0
 def _load_py_files(env, search_path, auto_enable=None):
     import sys
     for path in search_path:
         sys.path.append(os.path.join(path, "lib"))
         plugin_files = locate("*.py", path)
         for plugin_file in plugin_files:
             p = "%s%s" % (os.path.join(path, "lib"), os.sep)
             if plugin_file.startswith(p):
                 continue
             try:
                 plugin_name = os.path.basename(plugin_file[:-3])
                 module_name = _get_module_name(plugin_file)
                 import_module(module_name)
                 _enable_plugin(env, plugin_name)
             except NotImplementedError, e:
                 #print "Cant Implement This"
                 pass
Ejemplo n.º 4
0
 def _get_shared_commands_for_file(self, file):
     commands = []
     module_name = loader._get_module_name(file)
     module = importlib.import_module(module_name)
     for name in dir(module):
         obj = getattr(module, name)
         if isinstance(obj, (type, types.ClassType)) and issubclass(obj, cdp.Command):
             commands.append(obj)
     return commands
Ejemplo n.º 5
0
    def _load_command_class(self, class_name):
        """Documentation"""
        module, attr = class_name.rsplit('.', 1)
        mod = import_module(module)
        cls = getattr(mod, attr)
        logging.debug(cls)
        if Command not in cls.mro():
            raise Exception("%s.%s does not inherit from %s.%s" %
                            (cls.__class__.__module__, cls.__class__.__name__,
                            Command.__class__.__module__, Command.__class__.__name__))

        return cls
Ejemplo n.º 6
0
    def __init__(self, settings_module):
        # update this dict from global settings (but only for ALL_CAPS settings)
        for setting in dir(global_settings):
            if setting == setting.upper():
                setattr(self, setting, getattr(global_settings, setting))

        # store the settings module in case someone later cares
        self.SETTINGS_MODULE = settings_module

        try:
            mod = importlib.import_module(self.SETTINGS_MODULE)
        except ImportError, e:
            return # since privding a settings file is optional
Ejemplo n.º 7
0
    def __init__(self, settings_module):
        # update this dict from global settings (but only for ALL_CAPS settings)
        for setting in dir(global_settings):
            if setting == setting.upper():
                setattr(self, setting, getattr(global_settings, setting))

        # store the settings module in case someone later cares
        self.SETTINGS_MODULE = settings_module

        try:
            mod = importlib.import_module(self.SETTINGS_MODULE)
        except ImportError, e:
            raise ImportError("Could not import settings '%s' (Is it on sys.path? Does it have syntax errors?): %s" % (self.SETTINGS_MODULE, e))
Ejemplo n.º 8
0
    def _get_class(self, class_name):
        """loads and returns the Command class object.
        Note: this does not return an instance, it only returns the class
        """
        module, attr = class_name.rsplit('.', 1)
        mod = import_module(module)
        cls = getattr(mod, attr)

        if Command not in cls.mro():
            raise Exception("%s.%s does not inherit from %s.%s" %
                            (cls.__class__.__module__, cls.__class__.__name__,
                            Command.__class__.__module__, Command.__class__.__name__))

        return cls
Ejemplo n.º 9
0
def get_unit_tests(args=None):
    
    if not args:
        files = tic.loader.locate("*.py")
        
    elif _is_args_dir(args):
        files = tic.loader.locate("*.py", 
            root=os.path.join(os.curdir, _convert_module_to_path(args)))
    elif _is_args_module(args):
        module = _is_args_module(args)
        module_suites = unittest.defaultTestLoader.loadTestsFromModule(module)
        if module_suites.countTestCases():
            return [module_suites]
    elif _is_args_TestCase(args):
        return [unittest.defaultTestLoader.loadTestsFromTestCase(_is_args_TestCase(args))]
    else:
        #maybe its a method?
        testcase = unittest.defaultTestLoader.loadTestsFromName(args)
        return [testcase]
#        raise Exception('Cant find test: %s' % args)
        
    suites = []
    for file in files:
        p = "%s%s" % (os.path.join(os.path.abspath(os.curdir), "lib"), os.sep)
        if file.startswith(p):
            continue
        module_name = tic.loader._get_module_name(file)
        module = importlib.import_module(module_name)
        module_suites = unittest.defaultTestLoader.loadTestsFromModule(module)
        try:
            module_suites.addTests(doctest.DocTestSuite(module))
        except:
            pass
        if not module_suites.countTestCases():
            continue
        suites.append(module_suites)
    
    return suites
Ejemplo n.º 10
0
def _is_args_module(args):
    try:
        module = importlib.import_module(args)
        return module
    except:
        return None