Exemplo n.º 1
0
 def wanted(attr, cls=cls, sel=self.selector):
     item = getattr(cls, attr, None)
     if isfunction(item):
         item = unbound_method(cls, item)
     if not ismethod(item):
         return False
     return sel.wantMethod(item)
Exemplo n.º 2
0
 def wanted(attr, cls=cls, sel=self.selector):
     item = getattr(cls, attr, None)
     if isfunction(item):
         item = unbound_method(cls, item)
     if not ismethod(item):
         return False
     return sel.wantMethod(item)
Exemplo n.º 3
0
    def _makeTest(self, obj, parent=None):
        """Given a test object and its parent, return a test case
        or test suite.
        """
        import inspect
        try:
            lineno = inspect.getsourcelines(obj)
        except:
            lineno = ("", 1)
        if isfunction(obj) and parent and not isinstance(
                parent, types.ModuleType):
            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) or isunboundmethod(obj):
            if parent is None:
                parent = obj.__class__
            if issubclass(parent, unittest.TestCase):
                return parent(obj.__name__)
            else:
                if PYTHON_VERSION_MAJOR > 2:
                    setattr(obj, "im_class", parent)
                    setattr(obj, "im_self", parent)
                test_case = MethodTestCase(obj)
                test_case.lineno = lineno[1]
                return test_case
        elif isfunction(obj):
            setattr(obj, "lineno", lineno[1])
            if hasattr(obj, "__module__"):
                if parent and obj.__module__ != parent.__name__:
                    obj = transplant_func(obj, parent.__name__)
            else:
                if parent:
                    obj = transplant_func(obj, parent.__name__)
                else:
                    obj = transplant_func(obj)

            if isgenerator(obj):
                return self.loadTestsFromGenerator(obj, parent, lineno[1])
            else:
                return FunctionTestCase(obj)
        else:
            return Failure(TypeError, "Can't make a test from %s" % obj)
Exemplo n.º 4
0
    def _makeTest(self, obj, parent=None):
        """Given a test object and its parent, return a test case
        or test suite.
        """
        import inspect
        try:
          lineno = inspect.getsourcelines(obj)
        except:
          lineno = ("", 1)
        if isfunction(obj) and parent and not isinstance(parent, types.ModuleType):
          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) or isunboundmethod(obj):
            if parent is None:
                parent = obj.__class__
            if issubclass(parent, unittest.TestCase):
                return parent(obj.__name__)
            else:
              if PYTHON_VERSION_MAJOR > 2:
                setattr(obj, "im_class", parent)
                setattr(obj, "im_self", parent)
              test_case = MethodTestCase(obj)
              test_case.lineno = lineno[1]
              return test_case
        elif isfunction(obj):
            setattr(obj, "lineno", lineno[1])
            if hasattr(obj, "__module__"):
                if parent and obj.__module__ != parent.__name__:
                    obj = transplant_func(obj, parent.__name__)
            else:
                if parent:
                    obj = transplant_func(obj, parent.__name__)
                else:
                    obj = transplant_func(obj)

            if isgenerator(obj):
                return self.loadTestsFromGenerator(obj, parent, lineno[1])
            else:
                return FunctionTestCase(obj)
        else:
            return Failure(TypeError,
                           "Can't make a test from %s" % obj)