Пример #1
0
 def address(self):
     """Return a round-trip name for this test, a name that can be
     fed back as input to loadTestByName and (assuming the same
     plugin configuration) result in the loading of this test.
     """
     if self.descriptor is not None:
         return test_address(self.descriptor)
     else:
         return test_address(self.method)
Пример #2
0
 def address(self):
     """Return a round-trip name for this test, a name that can be
     fed back as input to loadTestByName and (assuming the same
     plugin configuration) result in the loading of this test.
     """
     if self.descriptor is not None:
         return test_address(self.descriptor)
     else:
         return test_address(self.method)
Пример #3
0
 def get_nose_name(its_self):
     if isinstance(its_self, (FunctionTestCase, MethodTestCase)):
         file_, module, class_ = test_address(its_self)
         name = '%s:%s' % (module, class_)
         return name
     elif isinstance(its_self, TestModule):
         return its_self.moduleName
Пример #4
0
 def get_nose_name(its_self):
     if isinstance(its_self, (FunctionTestCase, MethodTestCase)):
         file_, module, class_ = test_address(its_self)
         name = '%s:%s' % (module, class_)
         return name
     elif isinstance(its_self, TestModule):
         return its_self.moduleName
Пример #5
0
 def generate(g=generator, c=cls):
     try:
         for test in g():
             test_func, arg = self.parseGeneratedTest(test)
             if not callable(test_func):
                 test_func = unbound_method(c, getattr(c, test_func))
             if ismethod(test_func):
                 yield MethodTestCase(test_func, arg=arg, descriptor=g)
             elif callable(test_func):
                 # In this case we're forcing the 'MethodTestCase'
                 # to run the inline function as its test call,
                 # but using the generator method as the 'method of
                 # record' (so no need to pass it as the descriptor)
                 yield MethodTestCase(g, test=test_func, arg=arg)
             else:
                 yield Failure(
                     TypeError,
                     "%s is not a callable or method" % test_func)
     except KeyboardInterrupt:
         raise
     except:
         exc = sys.exc_info()
         yield Failure(exc[0],
                       exc[1],
                       exc[2],
                       address=test_address(generator))
Пример #6
0
    def address(self):
        if self._nose_obj is not None:
            return test_address(self._nose_obj)
        obj = resolve_name(self._dt_test.name)

        if isproperty(obj):
            # properties have no connection to the class they are in
            # so we can't just look 'em up, we have to first look up
            # the class, then stick the prop on the end
            parts = self._dt_test.name.split(".")
            class_name = ".".join(parts[:-1])
            cls = resolve_name(class_name)
            base_addr = test_address(cls)
            return (base_addr[0], base_addr[1], ".".join([base_addr[2], parts[-1]]))
        else:
            return test_address(obj)
Пример #7
0
    def _makeTest(self, obj, parent=None):
        """Given a test object and its parent, return a test case
        or test suite.
        """
        plug_tests = []
        try:
            addr = test_address(obj)
        except KeyboardInterrupt:
            raise
        except:
            addr = None
        for test in self.config.plugins.makeTest(obj, parent):
            plug_tests.append(test)
        # TODO: is this try/except needed?
        try:
            if plug_tests:
                return self.suiteClass(plug_tests)
        except (KeyboardInterrupt, SystemExit):
            raise
        except:
            exc = sys.exc_info()
            return Failure(exc[0], exc[1], exc[2], address=addr)
        
        if isfunction(obj) and parent and not isinstance(parent, types.ModuleType):
	    # This is a Python 3.x 'unbound method'.  Wrap it with its
	    # associated class..
            obj = unbound_method(parent, obj)

        if isinstance(obj, unittest.TestCase):
            return obj
        elif isclass(obj):
            if parent and obj.__module__ != parent.__name__:
                obj = transplant_class(obj, parent.__name__)
            if issubclass(obj, unittest.TestCase):
                return self.loadTestsFromTestCase(obj)
            else:
                return self.loadTestsFromTestClass(obj)
        elif ismethod(obj):
            if parent is None:
                parent = obj.__class__
            if issubclass(parent, unittest.TestCase):
                return parent(obj.__name__)
            else:
                if isgenerator(obj):
                    return self.loadTestsFromGeneratorMethod(obj, parent)
                else:
                    return MethodTestCase(obj)
        elif isfunction(obj):
            isgen = isgenerator(obj)
            if parent and obj.__module__ != parent.__name__:
                obj = transplant_func(obj, parent.__name__)
            if isgen:
                return self.loadTestsFromGenerator(obj, parent)
            else:
                return FunctionTestCase(obj)
        else:
            return Failure(TypeError,
                           "Can't make a test from %s" % obj,
                           address=addr)
Пример #8
0
    def _makeTest(self, obj, parent=None):
        """Given a test object and its parent, return a test case
        or test suite.
        """
        plug_tests = []
        try:
            addr = test_address(obj)
        except KeyboardInterrupt:
            raise
        except:
            addr = None
        for test in self.config.plugins.makeTest(obj, parent):
            plug_tests.append(test)
        # TODO: is this try/except needed?
        try:
            if plug_tests:
                return self.suiteClass(plug_tests)
        except (KeyboardInterrupt, SystemExit):
            raise
        except:
            exc = sys.exc_info()
            return Failure(exc[0], exc[1], exc[2], address=addr)

        if isfunction(obj) and parent and not isinstance(
                parent, types.ModuleType):
            # This is a Python 3.x 'unbound method'.  Wrap it with its
            # associated class..
            obj = unbound_method(parent, obj)

        if isinstance(obj, unittest.TestCase):
            return obj
        elif isclass(obj):
            if parent and obj.__module__ != parent.__name__:
                obj = transplant_class(obj, parent.__name__)
            if issubclass(obj, unittest.TestCase):
                return self.loadTestsFromTestCase(obj)
            else:
                return self.loadTestsFromTestClass(obj)
        elif ismethod(obj):
            if parent is None:
                parent = obj.__class__
            if issubclass(parent, unittest.TestCase):
                return parent(obj.__name__)
            else:
                if isgenerator(obj):
                    return self.loadTestsFromGeneratorMethod(obj, parent)
                else:
                    return MethodTestCase(obj)
        elif isfunction(obj):
            if parent and obj.__module__ != parent.__name__:
                obj = transplant_func(obj, parent.__name__)
            if isgenerator(obj):
                return self.loadTestsFromGenerator(obj, parent)
            else:
                return FunctionTestCase(obj)
        else:
            return Failure(TypeError,
                           "Can't make a test from %s" % obj,
                           address=addr)
Пример #9
0
    def validateName(self, testObject):
        filepath, module, call = test_address(testObject)

        node = self.hash_ring.get_node('%s.%s' % (module, call))
        if node != self.node_id:
            return False

        return None
Пример #10
0
    def validateName(self, testObject):
        filepath, module, call = test_address(testObject)

        node = self.hash_ring.get_node('%s.%s' % (module, call))
        if node != self.node_id:
            return False

        return None
Пример #11
0
    def address(self):
        if self._nose_obj is not None:
            return test_address(self._nose_obj)
        obj = resolve_name(self._dt_test.name)

        if isproperty(obj):
            # properties have no connection to the class they are in
            # so we can't just look 'em up, we have to first look up
            # the class, then stick the prop on the end
            parts = self._dt_test.name.split('.')
            class_name = '.'.join(parts[:-1])
            cls = resolve_name(class_name)
            base_addr = test_address(cls)
            return (base_addr[0], base_addr[1],
                    '.'.join([base_addr[2], parts[-1]]))
        else:
            return test_address(obj)
Пример #12
0
 def address(self):
     """Return a round-trip name for this test, a name that can be
     fed back as input to loadTestByName and (assuming the same
     plugin configuration) result in the loading of this test.
     """
     try:
         return self.test.address()
     except AttributeError:
         # not a nose case
         return test_address(self.test)
Пример #13
0
 def address(self):
     """Return a round-trip name for this test, a name that can be
     fed back as input to loadTestByName and (assuming the same
     plugin configuration) result in the loading of this test.
     """
     try:
         return self.test.address()
     except AttributeError:
         # not a nose case
         return test_address(self.test)
Пример #14
0
 def address(self):
     """Return a round-trip name for this test, a name that can be
     fed back as input to loadTestByName and (assuming the same
     plugin configuration) result in the loading of this test.
     """
     if hasattr(self.test, 'address'):
         return self.test.address()
     else:
         # not a nose case
         return test_address(self.test)
Пример #15
0
 def address(self):
     """Return a round-trip name for this test, a name that can be
     fed back as input to loadTestByName and (assuming the same
     plugin configuration) result in the loading of this test.
     """
     if hasattr(self.test, 'address'):
         return self.test()
     else:
         # not a nose case
         return test_address(self.test)
Пример #16
0
def nice_test_address(test):
    if isinstance(test, nose.suite.ContextSuite):
        addr = test_address(test.context)
        if hasattr(test, 'error_context') and test.error_context:
            addr = list(addr)
            if addr[2]:
                # class
                addr[2] = '%s.%s' % (addr[2], test.error_context)
            else:
                # module
                addr[2] = test.error_context
    else:
        addr = test_address(test)
    if addr is None:
        return '??'
    path, module, test_path = addr
    path = nice_path(path)
    if test_path is None:
        return path
    return "%s:%s" % (path, test_path)
Пример #17
0
 def generate(g=generator, c=testCaseClass):
     try:
         for test in g():
             test_func, arg = (test[0], test[1:])
             yield QUnitMethodTestCase(test_func, arg=arg, descriptor=g)
     except KeyboardInterrupt:
         raise
     except:
         exc = sys.exc_info()
         yield Failure(exc[0], exc[1], exc[2],
                       address=test_address(generator))
Пример #18
0
    def validateName(self, testObject):
        try:
            _, module, call = test_address(testObject)
        except TypeError:
            module = 'unknown'
            call = str(testObject)

        node = self.hash_ring.get_node('%s.%s' % (module, call))
        if node != self.node_id:
            return False

        return None
Пример #19
0
 def generate(g=generator, m=module):
     try:
         for test in g():
             test_func, arg = self.parseGeneratedTest(test)
             if not callable(test_func):
                 test_func = getattr(m, test_func)
             yield FunctionTestCase(test_func, arg=arg, descriptor=g)
     except KeyboardInterrupt:
         raise
     except:
         exc = sys.exc_info()
         yield Failure(exc[0], exc[1], exc[2], address=test_address(generator))
Пример #20
0
    def validateName(self, testObject):
        try:
            _, module, call = test_address(testObject)
        except TypeError:
            module = 'unknown'
            call = str(testObject)

        node = self.hash_ring.get_node('%s.%s' % (module, call))
        if node != self.node_id:
            return False

        return None
Пример #21
0
 def generate(g=generator, c=testCaseClass):
     try:
         for test in g():
             test_func, arg = (test[0], test[1:])
             yield QUnitMethodTestCase(test_func, arg=arg, descriptor=g)
     except KeyboardInterrupt:
         raise
     except:
         exc = sys.exc_info()
         yield Failure(exc[0],
                       exc[1],
                       exc[2],
                       address=test_address(generator))
Пример #22
0
 def generate(g=generator, m=module):
     try:
         for test in g():
             test_func, arg = self.parseGeneratedTest(test)
             if not isinstance(test_func, collections.Callable):
                 test_func = getattr(m, test_func)
             yield FunctionTestCase(test_func, arg=arg, descriptor=g)
     except KeyboardInterrupt:
         raise
     except:
         exc = sys.exc_info()
         yield Failure(exc[0], exc[1], exc[2],
                       address=test_address(generator))
Пример #23
0
 def makeTest(self, obj, parent=None):
     try:
         return self._makeTest(obj, parent)
     except (KeyboardInterrupt, SystemExit):
         raise
     except:
         exc = sys.exc_info()
         try:
             addr = test_address(obj)
         except KeyboardInterrupt:
             raise
         except:
             addr = None
         return Failure(exc[0], exc[1], exc[2], address=addr)
Пример #24
0
 def makeTest(self, obj, parent=None):
     try:
         return self._makeTest(obj, parent)
     except (KeyboardInterrupt, SystemExit):
         raise
     except:
         exc = sys.exc_info()
         try:
             addr = test_address(obj)
         except KeyboardInterrupt:
             raise
         except:
             addr = None
         return Failure(exc[0], exc[1], exc[2], address=addr)
Пример #25
0
 def address(self, case):
     if hasattr(case, 'address'):
         file, mod, call = case.address()
     elif hasattr(case, 'context'):
         file, mod, call = test_address(case.context)
     else:
         raise Exception("Unable to convert %s to address" % case)
     parts = []
     if file is None:
         if mod is None:
             raise Exception("Unaddressable case %s" % case)
         else:
             parts.append(mod)
     else:
         parts.append(file)
     if call is not None:
         parts.append(call)
     return ':'.join(map(str, parts))
Пример #26
0
 def _add_test_result(self, test, status, output, err=None):
     filename, module, _ = test_address(test)
     if filename and (filename.endswith('.pyc') or
                      filename.endswith('.pyo')):
         filename = filename[:-1]
     name = str(test)
     fixture = module or test.id()
     description = test.shortDescription() or ''
     case = xmlio.Element('test', file=filename, name=name, fixture=fixture,
                          status=status)
     if description:
         case.append(xmlio.Element('description')[description])
     if output:
         case.append(xmlio.Element('stdout')[output])
     if err is not None:
         tb = traceback.format_exception(*err)
         case.append(xmlio.Element('traceback')[tb])
     self.dom.append(case)
Пример #27
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
Пример #28
0
 def generate(g=generator, c=cls):
     try:
         for test in g():
             test_func, arg = self.parseGeneratedTest(test)
             if not callable(test_func):
                 test_func = unbound_method(c, getattr(c, test_func))
             if ismethod(test_func):
                 yield MethodTestCase(test_func, arg=arg, descriptor=g)
             elif isfunction(test_func):
                 # In this case we're forcing the 'MethodTestCase'
                 # to run the inline function as its test call,
                 # but using the generator method as the 'method of
                 # record' (so no need to pass it as the descriptor)
                 yield MethodTestCase(g, test=test_func, arg=arg)
             else:
                 yield Failure(TypeError, "%s is not a function or method" % test_func)
     except KeyboardInterrupt:
         raise
     except:
         exc = sys.exc_info()
         yield Failure(exc[0], exc[1], exc[2], address=test_address(generator))
Пример #29
0
 def address(case):
     if hasattr(case, "address"):
         file, mod, call = case.address()
     elif hasattr(case, "context"):
         file, mod, call = test_address(case.context)
     else:
         raise Exception("Unable to convert %s to address" % case)
     parts = []
     if file is None:
         if mod is None:
             raise Exception("Unaddressable case %s" % case)
         else:
             parts.append(mod)
     else:
         # strip __init__.py(c) from end of file part
         # if present, having it there confuses loader
         dirname, basename = os.path.split(file)
         if basename.startswith("__init__"):
             file = dirname
         parts.append(file)
     if call is not None:
         parts.append(call)
     return ":".join(map(str, parts))
Пример #30
0
 def address(self):
     if self._nose_obj is not None:
         return test_address(self._nose_obj)
     return test_address(resolve_name(self._dt_test.name))
Пример #31
0
 def address(self):
     return test_address(self.context)
Пример #32
0
 def addFailure(self, test, err):
     type_, value, traceback = err
     exc_string = "".join(format_exception(type_, value, traceback))
     self.data['result.string'] += 'F'
     self.data['result.failures'].append((test_address(test),
                                          (type_, value, exc_string)))
Пример #33
0
 def prepareTestCase(self, test):
     path, name, func = util.test_address(test)
     test_steps.log_new_func(func, path)
Пример #34
0
 def afterTest(self, test):
     self.data['result.tests'].append(test_address(test))
Пример #35
0
 def afterTest(self, test):
     self.data['result.tests'].append(test_address(test))
Пример #36
0
 def addFailure(self, test, err):
     type_, value, traceback = err
     exc_string = "".join(format_exception(type_, value, traceback))
     self.data['result.string'] += 'F'
     self.data['result.failures'].append(
         (test_address(test), (type_, value, exc_string)))
Пример #37
0
 def afterTest(self, test):
     # None means test never ran, False means failed/err
     if test.passed is False:
         filename = test_address(test)[0]
         self._failed_test_modules.add(filename)
Пример #38
0
 def id(self):
     base = '.'.join([x for x in test_address(self.context)[1:] if x])
     if self.error_context == 'teardown':
         return '%s:%s' % (base, self.error_context)
     return base
Пример #39
0
 def address(self):
     if self._nose_obj is not None:
         return test_address(self._nose_obj)
     return test_address(resolve_name(self._dt_test.name))