Exemplo n.º 1
0
def parse_test_name(test):
    test_file, _, class_and_name = split_test_name(test)
    try:
        test_class, test_name = class_and_name.split(".")
    except AttributeError:
        test_class, test_name = (None, None)
    except ValueError:
        test_class, test_name = class_and_name, None

    return test_file, test_class, test_name
Exemplo n.º 2
0
    def loadTestsFromName(self, name, module=None, importPath=None):
        """Load tests from test name. Name may be a file, directory or
        module. Specify module (or module) as name to load from a
        particular module. Specify importPath to load
        from that path.
        """
        # compatibility shim
        try:
            module = module.__name__
        except AttributeError:
            pass
        
        tests = None
        path, mod_name, fn = split_test_name(name)
        log.debug('test name %s resolves to path %s, module %s, callable %s'
                  % (name, path, mod_name, fn))

        if path:
            if os.path.isfile(path):
                log.debug("%s is a file", path)
                if self.selector.wantFile(name, module):
                    tests = self.loadTestsFromPath(path,
                                                   module=module,
                                                   importPath=importPath)
            elif os.path.isdir(path):
                log.debug("%s is a directory", path)
                if self.selector.wantDirectory(path):
                    init = os.path.join(path, '__init__.py')
                    if os.path.exists(init):
                        tests = self.loadTestsFromPath(path,
                                                       module=module,
                                                       importPath=importPath)
                    else:
                        # dirs inside of modules don't belong to the
                        # module, so module and importPath are not passed
                        tests = self.loadTestsFromDir(path)
            else:
                # ignore non-file, non-path item
                log.warning("%s is neither file nor path", path)
        elif mod_name:
            # handle module-like names
            tests = self.loadTestsFromModuleName(name,
                                                 package=module,
                                                 importPath=importPath)
        elif module:
            # handle func-like names in a module            
            raise ValueError("No module or file specified in test name")
        if tests:
            for test in tests:
                yield test                
        # give plugins a chance
        for plug in self.plugins:
            if hasattr(plug, 'loadTestsFromName'):
                for test in plug.loadTestsFromName(name, module, importPath):
                    yield test
Exemplo n.º 3
0
 def __init__(self, name, workingDir=None):
     if workingDir is None:
         workingDir = os.getcwd()
     self.name = name
     self.workingDir = workingDir
     self.filename, self.module, self.call = split_test_name(name)
     log.debug('Test name %s resolved to file %s, module %s, call %s', name,
               self.filename, self.module, self.call)
     if self.filename is None:
         if self.module is not None:
             self.filename = getfilename(self.module, self.workingDir)
     if self.filename:
         self.filename = src(self.filename)
         if not op_isabs(self.filename):
             self.filename = op_abspath(op_join(workingDir, self.filename))
         if self.module is None:
             self.module = getpackage(self.filename)
     log.debug(
         'Final resolution of test name %s: file %s module %s call %s',
         name, self.filename, self.module, self.call)
Exemplo n.º 4
0
 def match(self, test, test_name):
     adr_file, adr_mod, adr_tst = test_address(test)
     chk_file, chk_mod, chk_tst = split_test_name(test_name)
     
     if chk_file is not None and not adr_file.startswith(chk_file):
         return False
     if chk_mod is not None and not adr_mod.startswith(chk_mod):
         return False
     if chk_tst is not None and chk_tst != adr_tst:
         # could be a test like Class.test and a check like Class
         if not '.' in chk_tst:
             try:
                 cls, mth = adr_tst.split('.')
             except ValueError:
                 return False
             if cls != chk_tst:            
                 return False
         else:
             return False
     return True
Exemplo n.º 5
0
 def __init__(self, name, workingDir=None):
     if workingDir is None:
         workingDir = os.getcwd()
     self.name = name
     self.workingDir = workingDir
     self.filename, self.module, self.call = split_test_name(name)
     log.debug('Test name %s resolved to file %s, module %s, call %s',
               name, self.filename, self.module, self.call)
     if self.filename is None:
         if self.module is not None:
             self.filename = getfilename(self.module, self.workingDir)
     if self.filename:
         self.filename = src(self.filename)
         if not op_isabs(self.filename):
             self.filename = op_abspath(op_join(workingDir,
                                                self.filename))
         if self.module is None:
             self.module = getpackage(self.filename)
     log.debug(
         'Final resolution of test name %s: file %s module %s call %s',
         name, self.filename, self.module, self.call)