コード例 #1
0
ファイル: functions.py プロジェクト: lodagro/nose2
    def _createTests(self, obj):
        if not hasattr(obj, 'setUp'):
            if hasattr(obj, 'setup'):
                obj.setUp = obj.setup
            elif hasattr(obj, 'setUpFunc'):
                obj.setUp = obj.setUpFunc
        if not hasattr(obj, 'tearDown'):
            if hasattr(obj, 'teardown'):
                obj.tearDown = obj.teardowns
            elif hasattr(obj, 'tearDownFunc'):
                obj.tearDown = obj.tearDownFunc

        tests = []
        args = {}
        setUp = getattr(obj, 'setUp', None)
        tearDown = getattr(obj, 'tearDown', None)
        if setUp is not None:
            args['setUp'] = setUp
        if tearDown is not None:
            args['tearDown'] = tearDown

        paramList = getattr(obj, 'paramList', None)
        isGenerator = util.isgenerator(obj)
        if paramList is not None or isGenerator:
            return tests
        else:
            case = unittest.FunctionTestCase(obj, **args)
            tests.append(case)
        return tests
コード例 #2
0
ファイル: functions.py プロジェクト: Gustry/QGIS
    def _createTests(self, obj):
        if not hasattr(obj, "setUp"):
            if hasattr(obj, "setup"):
                obj.setUp = obj.setup
            elif hasattr(obj, "setUpFunc"):
                obj.setUp = obj.setUpFunc
        if not hasattr(obj, "tearDown"):
            if hasattr(obj, "teardown"):
                obj.tearDown = obj.teardown
            elif hasattr(obj, "tearDownFunc"):
                obj.tearDown = obj.tearDownFunc

        tests = []
        args = {}
        setUp = getattr(obj, "setUp", None)
        tearDown = getattr(obj, "tearDown", None)
        if setUp is not None:
            args["setUp"] = setUp
        if tearDown is not None:
            args["tearDown"] = tearDown

        paramList = getattr(obj, "paramList", None)
        isGenerator = util.isgenerator(obj)
        if paramList is not None or isGenerator:
            return tests
        else:
            case = util.transplant_class(unittest.FunctionTestCase, obj.__module__)(obj, **args)
            tests.append(case)
        return tests
コード例 #3
0
ファイル: testclasses.py プロジェクト: nose-devs/nose2
 def loadTestsFromName(self, event):
     """Load tests from event.name if it names a test class/method"""
     name = event.name
     module = event.module
     try:
         result = util.test_from_name(name, module)
     except (AttributeError, ImportError):
         event.handled = True
         return event.loader.failedLoadTests(name, sys.exc_info())
     if result is None:
         return
     parent, obj, name, index = result
     if isinstance(obj, type) and not issubclass(obj, unittest.TestCase):
         # name is a test case class
         event.extraTests.append(self._loadTestsFromTestClass(event, obj))
     elif (
         isinstance(parent, type)
         and not issubclass(parent, unittest.TestCase)
         and not util.isgenerator(obj)
         and not hasattr(obj, "paramList")
     ):
         # name is a single test method
         event.extraTests.append(
             util.transplant_class(MethodTestCase(parent), parent.__module__)(
                 obj.__name__
             )
         )
コード例 #4
0
    def _createTests(self, obj):
        if not hasattr(obj, 'setUp'):
            if hasattr(obj, 'setup'):
                obj.setUp = obj.setup
            elif hasattr(obj, 'setUpFunc'):
                obj.setUp = obj.setUpFunc
        if not hasattr(obj, 'tearDown'):
            if hasattr(obj, 'teardown'):
                obj.tearDown = obj.teardown
            elif hasattr(obj, 'tearDownFunc'):
                obj.tearDown = obj.tearDownFunc

        tests = []
        args = {}
        setUp = getattr(obj, 'setUp', None)
        tearDown = getattr(obj, 'tearDown', None)
        if setUp is not None:
            args['setUp'] = setUp
        if tearDown is not None:
            args['tearDown'] = tearDown

        paramList = getattr(obj, 'paramList', None)
        isGenerator = util.isgenerator(obj)
        if paramList is not None or isGenerator:
            return tests
        else:
            case = util.transplant_class(FunctionTestCase,
                                         obj.__module__)(obj, **args)
            tests.append(case)
コード例 #5
0
ファイル: generators.py プロジェクト: nikolas/nose2
 def getTestCaseNames(self, event):
     """Get generator test case names from test case class"""
     log.debug('getTestCaseNames %s', event.testCase)
     names = filter(event.isTestMethod, dir(event.testCase))
     klass = event.testCase
     for name in names:
         method = getattr(klass, name)
         if util.isgenerator(method):
             event.excludedNames.append(name)
コード例 #6
0
ファイル: generators.py プロジェクト: aloysbaillet/nose2
 def getTestCaseNames(self, event):
     """Get generator test case names from test case class"""
     log.debug('getTestCaseNames %s', event.testCase)
     names = filter(event.isTestMethod, dir(event.testCase))
     klass = event.testCase
     for name in names:
         method = getattr(klass, name)
         if util.isgenerator(method):
             event.excludedNames.append(name)
コード例 #7
0
ファイル: generators.py プロジェクト: Gustry/QGIS
 def loadTestsFromTestClass(self, event):
     testCaseClass = event.testCase
     for name in dir(testCaseClass):
         method = getattr(testCaseClass, name)
         if (
             name.startswith(self.session.testMethodPrefix)
             and hasattr(getattr(testCaseClass, name), "__call__")
             and util.isgenerator(method)
         ):
             instance = testCaseClass()
             event.extraTests.extend(self._testsFromGeneratorMethod(event, name, method, instance))
コード例 #8
0
    def loadTestsFromName(self, event):
        """Load tests from generator named on command line"""
        original_name = name = event.name
        module = event.module
        try:
            result = util.test_from_name(name, module)
        except (AttributeError, ImportError):
            event.handled = True
            return event.loader.failedLoadTests(name, sys.exc_info())
        if result is None:
            # we can't find it - let the default case handle it
            return

        parent, obj, name, index = result
        if not util.isgenerator(obj):
            return

        if (index is None and not
            isinstance(parent, type) and not
            isinstance(obj, types.FunctionType)):
            log.debug("Don't know how to load generator tests from %s", obj)
            return

        if (parent and
            isinstance(parent, type) and
            issubclass(parent, unittest.TestCase)):
            # generator method in test case
            instance = parent(obj.__name__)
            tests = list(
                self._testsFromGenerator(
                    event, obj.__name__, obj(instance), parent)
            )
        elif (parent and
              isinstance(parent, type)):
            # generator method in test class
            method = obj
            instance = parent()
            tests = list(
                self._testsFromGeneratorMethod(event, name, method, instance)
            )
        else:
            # generator func
            tests = list(self._testsFromGeneratorFunc(event, obj))

        if index is not None:
            try:
                tests = [tests[index - 1]]
            except IndexError:
                raise exceptions.TestNotFoundError(original_name)

        suite = event.loader.suiteClass()
        suite.addTests(tests)
        event.handled = True
        return suite
コード例 #9
0
ファイル: generators.py プロジェクト: aloysbaillet/nose2
    def loadTestsFromName(self, event):
        """Load tests from generator named on command line"""
        original_name = name = event.name
        module = event.module
        try:
            result = util.test_from_name(name, module)
        except (AttributeError, ImportError) as e:
            event.handled = True
            return event.loader.failedLoadTests(name, e)
        if result is None:
            # we can't find it - let the default case handle it
            return

        parent, obj, name, index = result
        if not util.isgenerator(obj):
            return

        if (index is None and not
            isinstance(parent, type) and not
            isinstance(obj, types.FunctionType)):
            log.debug("Don't know how to load generator tests from %s", obj)
            return

        if (parent and
            isinstance(parent, type) and
            issubclass(parent, unittest.TestCase)):
            # generator method in test case
            instance = parent(obj.__name__)
            tests = list(
                self._testsFromGenerator(
                    event, obj.__name__, obj(instance), parent)
            )
        elif (parent and
              isinstance(parent, type)):
              # generator method in test class
            method = obj
            instance = parent()
            tests = list(
                self._testsFromGeneratorMethod(event, name, method, instance)
            )
        else:
            # generator func
            tests = list(self._testsFromGeneratorFunc(event, obj))

        if index is not None:
            try:
                tests = [tests[index - 1]]
            except IndexError:
                raise exceptions.TestNotFoundError(original_name)

        suite = event.loader.suiteClass()
        suite.addTests(tests)
        event.handled = True
        return suite
コード例 #10
0
ファイル: generators.py プロジェクト: nikolas/nose2
 def loadTestsFromTestClass(self, event):
     testCaseClass = event.testCase
     for name in dir(testCaseClass):
         method = getattr(testCaseClass, name)
         if (name.startswith(self.session.testMethodPrefix)
                 and hasattr(getattr(testCaseClass, name), '__call__')
                 and util.isgenerator(method)):
             instance = testCaseClass()
             event.extraTests.extend(
                 self._testsFromGeneratorMethod(event, name, method,
                                                instance))
コード例 #11
0
ファイル: generators.py プロジェクト: nikolas/nose2
 def loadTestsFromTestCase(self, event):
     """Load generator tests from test case"""
     log.debug('loadTestsFromTestCase %s', event.testCase)
     testCaseClass = event.testCase
     for name in dir(testCaseClass):
         method = getattr(testCaseClass, name)
         if (name.startswith(self.session.testMethodPrefix)
                 and hasattr(getattr(testCaseClass, name), '__call__')
                 and util.isgenerator(method)):
             instance = testCaseClass(name)
             event.extraTests.extend(
                 self._testsFromGenerator(event, name, method(instance),
                                          testCaseClass))
コード例 #12
0
ファイル: generators.py プロジェクト: Gustry/QGIS
 def loadTestsFromTestCase(self, event):
     """Load generator tests from test case"""
     log.debug("loadTestsFromTestCase %s", event.testCase)
     testCaseClass = event.testCase
     for name in dir(testCaseClass):
         method = getattr(testCaseClass, name)
         if (
             name.startswith(self.session.testMethodPrefix)
             and hasattr(getattr(testCaseClass, name), "__call__")
             and util.isgenerator(method)
         ):
             instance = testCaseClass(name)
             event.extraTests.extend(self._testsFromGenerator(event, name, method(instance), testCaseClass))
コード例 #13
0
ファイル: functions.py プロジェクト: flutesys/nose2
    def loadTestsFromName(self, event):
        """Load test if event.name is the name of a test function"""
        name = event.name
        module = event.module
        try:
            result = util.test_from_name(name, module)
        except (AttributeError, ImportError):
            event.handled = True
            return event.loader.failedLoadTests(name, sys.exc_info())
        if result is None:
            return

        parent, obj, name, index = result
        if (isinstance(obj, types.FunctionType) and not util.isgenerator(obj)
                and not hasattr(obj, 'paramList')
                and util.num_expected_args(obj) == 0):
            suite = event.loader.suiteClass()
            suite.addTests(self._createTests(obj))
            event.handled = True
            return suite
コード例 #14
0
ファイル: functions.py プロジェクト: lodagro/nose2
    def loadTestsFromName(self, event):
        """Load test if event.name is the name of a test function"""
        name = event.name
        module = event.module
        try:
            result = util.test_from_name(name, module)
        except (AttributeError, ImportError) as e:
            event.handled = True
            return event.loader.failedLoadTests(name, e)
        if result is None:
            return

        parent, obj, name, index = result
        if (isinstance(obj, types.FunctionType) and not
            util.isgenerator(obj) and not
            hasattr(obj, 'paramList') and not
            inspect.getargspec(obj).args):
            suite = event.loader.suiteClass()
            suite.addTests(self._createTests(obj))
            event.handled = True
            return suite
コード例 #15
0
ファイル: testcases.py プロジェクト: atdt/nose2
 def loadTestsFromName(self, event):
     """Load tests from event.name if it names a test case/method"""
     name = event.name
     module = event.module
     try:
         result = util.test_from_name(name, module)
     except (AttributeError, ImportError) as e:
         event.handled = True
         return event.loader.failedLoadTests(name, e)
     if result is None:
         return
     parent, obj, name, index = result
     if isinstance(obj, type) and issubclass(obj, unittest.TestCase):
         # name is a test case class
         event.extraTests.append(self._loadTestsFromTestCase(event, obj))
     elif (isinstance(parent, type) and
           issubclass(parent, unittest.TestCase) and not
           util.isgenerator(obj) and not
           hasattr(obj, 'paramList')):
         # name is a single test method
         event.extraTests.append(parent(obj.__name__))
コード例 #16
0
 def loadTestsFromName(self, event):
     """Load tests from event.name if it names a test case/method"""
     name = event.name
     module = event.module
     log.debug("load %s from %s", name, module)
     try:
         result = util.test_from_name(name, module)
     except (AttributeError, ImportError) as e:
         event.handled = True
         return event.loader.failedLoadTests(name, e)
     if result is None:
         return
     parent, obj, name, index = result
     if isinstance(obj, type) and issubclass(obj, unittest.TestCase):
         # name is a test case class
         event.extraTests.append(self._loadTestsFromTestCase(event, obj))
     elif (isinstance(parent, type)
           and issubclass(parent, unittest.TestCase)
           and not util.isgenerator(obj) and not hasattr(obj, 'paramList')):
         # name is a single test method
         event.extraTests.append(parent(obj.__name__))
コード例 #17
0
ファイル: generators.py プロジェクト: aloysbaillet/nose2
 def is_test(obj):
     return (obj.__name__.startswith(self.session.testMethodPrefix)
             and util.isgenerator(obj))
コード例 #18
0
ファイル: generators.py プロジェクト: nikolas/nose2
 def is_test(obj):
     return (obj.__name__.startswith(self.session.testMethodPrefix)
             and util.isgenerator(obj))