Example #1
0
 def makeTest(self, obj, parent=None):
     """Given a test object and its parent, return a test case
     or test suite.
     """
     ldr = loader.TestLoader()
     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):
             # Randomize the order of the tests in the TestCase
             return self.randomized_loadTestsFromTestCase(obj)
         else:
             return self.randomized_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 ldr.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 ldr.loadTestsFromGenerator(obj, parent)
         else:
             return [FunctionTestCase(obj)]
     else:
         return Failure(TypeError,
                        "Can't make a test from %s" % obj)
Example #2
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)
Example #3
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)
Example #4
0
    def makeTest(self, obj, parent=None):
        """Given a test object and its parent, return a test case
        or test suite.
        """
        ldr = loader.TestLoader()
        if isinstance(obj, unittest.TestCase):
            return obj
        elif isclass(obj):
            if not self.class_specific:
                if parent and obj.__module__ != parent.__name__:
                    obj = transplant_class(obj, parent.__name__)
                if issubclass(obj, unittest.TestCase):
                    # Randomize the order of the tests in the TestCase
                    return self.randomized_loadTestsFromTestCase(obj)
                else:
                    return self.randomized_loadTestsFromTestClass(obj)
            else:
                class_specific_seed = getattr(
                    obj, CLASS_SPECIFIC_RANDOMIZE_TESTS_FIELD_NAME, None)
                if issubclass(
                        obj,
                        unittest.TestCase) and class_specific_seed is not None:
                    random.seed(class_specific_seed)
                    print("Using %d as seed to randomize tests in %s" %
                          (class_specific_seed, '.'.join(
                              [obj.__module__, obj.__name__])))
                    return self.randomized_loadTestsFromTestCase(obj)
                else:
                    return ldr.loadTestsFromTestCase(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 ldr.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 ldr.loadTestsFromGenerator(obj, parent)
            else:
                return [FunctionTestCase(obj)]
        else:
            return Failure(TypeError, "Can't make a test from %s" % obj)
Example #5
0
    def makeTest(self, obj, parent=None):
        """Given a test object and its parent, return a test case
        or test suite.
        """
        ldr = loader.TestLoader()
        if isinstance(obj, unittest.TestCase):
            return obj
        elif isclass(obj):
            if not self.class_specific:
                if parent and obj.__module__ != parent.__name__:
                    obj = transplant_class(obj, parent.__name__)
                if issubclass(obj, unittest.TestCase):
                    # Randomize the order of the tests in the TestCase
                    return self.randomized_loadTestsFromTestCase(obj)
                else:
                    return self.randomized_loadTestsFromTestClass(obj)
            else:
                class_specific_seed = getattr(obj, CLASS_SPECIFIC_RANDOMIZE_TESTS_FIELD_NAME, None)
                if issubclass(obj, unittest.TestCase) and class_specific_seed is not None:
                    random.seed(class_specific_seed)
                    print("Using %d as seed to randomize tests in %s" % (class_specific_seed, '.'.join(
                        [obj.__module__, obj.__name__])))
                    return self.randomized_loadTestsFromTestCase(obj)
                else:
                    return ldr.loadTestsFromTestCase(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 ldr.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 ldr.loadTestsFromGenerator(obj, parent)
            else:
                return [FunctionTestCase(obj)]
        else:
            return Failure(TypeError,
                           "Can't make a test from %s" % obj)
Example #6
0
 def makeTest(self, obj, parent=None):
     """Given a test object and its parent, return a test case
     or test suite.
     """
     plug_tests = []
     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:
         return Failure(*sys.exc_info())
     
     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)
Example #7
0
 def makeTest(self, obj, parent=None):
     """Given a test object and its parent, return a test case
     or test suite.
     """
     # Catch TypeError and AttributeError exceptions here and discard
     # them: the default plugin manager, NoPlugins, will raise TypeError
     # on generative calls.
     plug_tests = []
     try:
         for test in self.config.plugins.makeTest(obj, parent):
             plug_tests.append(test)
         if plug_tests:
             return self.suiteClass(plug_tests)
     except (TypeError, AttributeError):
         pass
     except (KeyboardInterrupt, SystemExit):
         raise
     except:
         return Failure(*sys.exc_info())
     
     if isinstance(obj, unittest.TestCase):
         return obj
     elif isclass(obj):            
         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 isgenerator(obj):
             return self.loadTestsFromGenerator(obj, parent)
         else:
             return FunctionTestCase(obj)
     else:
         return Failure(TypeError,
                        "Can't make a test from %s" % obj)
Example #8
0
    def makeTest(self, obj, parent=None):
        """Given a test object and its parent, return a test case
        or test suite.
        """
        plug_tests = []
        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:
            return Failure(*sys.exc_info())

        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)
Example #9
0
    def makeTest(self, obj, parent=None):

        """Given a test object and its parent, return a test case
        or test suite.
        """
        ldr = loader.TestLoader()
        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):
                # Randomize the order of the tests in the TestCase
                return self.Randomized_loadTestsFromTestCase(obj)
            else:
                return ldr.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 ldr.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 ldr.loadTestsFromGenerator(obj, parent)
            else:
                return FunctionTestCase(obj)
        else:
            return Failure(TypeError,
                           "Can't make a test from %s" % obj)