Beispiel #1
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)
Beispiel #2
0
    def makeSuiteFromFeature(self,
                             module,
                             feature_path,
                             scenarios_to_run=None):
        MyTestSuite = transplant_class(TestSuite, module.__name__)

        MyFeatureTestCase = transplant_class(FeatureTestCase, module.__name__)

        return MyTestSuite(tests=[
            MyFeatureTestCase(
                feature_path=feature_path,
                scenarios_to_run=scenarios_to_run,
                config=self.config,
            ),
        ], )
Beispiel #3
0
    def makeSuiteFromFeature(self, module, feature_path,
                             scenario_indexes=None):
        MyTestSuite = transplant_class(TestSuite, module.__name__)

        MyFeatureTestCase = transplant_class(FeatureTestCase, module.__name__)

        return MyTestSuite(
            tests=[
                MyFeatureTestCase(
                    feature_path=feature_path,
                    scenario_indexes=scenario_indexes,
                    config=self.config,
                ),
            ],
        )
Beispiel #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(
                unittest.FunctionTestCase, obj.__module__)(obj, **args)
            tests.append(case)
        return tests
Beispiel #5
0
 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__
             )
         )
    def test_combos_fail(self):
        feature_text = """Feature: I expect a step to fail.
           Scenario: Combo boxes fail
              Given I go to "basic_page"
              Then I should not see option "Mercedes" in selector "car_choice"
        """

        def captureFailure(*args):
            self.failure = args

        MyFeatureTestCase = transplant_class(FeatureTestCase, self.__module__)
        feature_test = MyFeatureTestCase(
            feature_path=__file__,
            feature_text=feature_text,
        )
        feature_test.run(result=Mock(
            addFailure=Mock(side_effect=captureFailure),
            addError=Mock(side_effect=Exception),
            addSuccess=Mock(side_effect=Exception),
        ))
        feature_exc_info = self.failure[1]
        failstep = ('Then I should not see option "Mercedes" '
                    'in selector "car_choice"')
        self.assertEqual(feature_exc_info.failed_step.strip(), failstep)
        failname = 'Scenario: Combo boxes fail'
        self.assertEqual(feature_exc_info.scenario_name.strip(), failname)
        expected_completed = [
            'Given I go to "basic_page"',
        ]
        completed_steps = [s.strip() for s in feature_exc_info.completed_steps]
        self.assertEqual(completed_steps, expected_completed)
    def test_labels_fail(self):
        feature_text = """Feature: I expect a step to fail.
            Scenario: Test labels fail
                When I go to "basic_page"
                And I click on label "Password:"******"pass" should not be focused"""

        def captureFailure(*args):
            self.failure = args

        MyFeatureTestCase = transplant_class(FeatureTestCase, self.__module__)
        feature_test = MyFeatureTestCase(
            feature_path=__file__,
            feature_text=feature_text,
        )
        feature_test.run(result=Mock(
            addFailure=Mock(side_effect=captureFailure),
            addError=Mock(side_effect=Exception),
            addSuccess=Mock(side_effect=Exception),
        ))
        feature_exc_info = self.failure[1]
        failstep = 'Then element with id "pass" should not be focused'
        self.assertEqual(feature_exc_info.failed_step.strip(), failstep)
        failname = 'Scenario: Test labels fail'
        self.assertEqual(feature_exc_info.scenario_name.strip(), failname)
        expected_completed = [
            'When I go to "basic_page"',
            'And I click on label "Password:"'
        ]
        completed_steps = [s.strip() for s in feature_exc_info.completed_steps]
        self.assertEqual(completed_steps, expected_completed)
Beispiel #8
0
 def _loadTestsFromTestClass(self, event, cls):
     # ... fire event for others to load from
     evt = LoadFromTestClassEvent(event.loader, cls)
     result = self.session.hooks.loadTestsFromTestClass(evt)
     if evt.handled:
         loaded_suite = result or event.loader.suiteClass()
     else:
         names = self._getTestMethodNames(event, cls)
         loaded_suite = event.loader.suiteClass(
             [util.transplant_class(MethodTestCase(cls), cls.__module__)(name) for name in names]
         )
     if evt.extraTests:
         loaded_suite.addTests(evt.extraTests)
     # ... add extra tests
     return loaded_suite
Beispiel #9
0
    def makeSuiteFromFeature(self, module, feature_path,
                             scenarios_to_run=None):
        MyTestSuite = transplant_class(TestSuite, module.__name__)

        MyFeatureTestCase = transplant_class(FeatureTestCase, module.__name__)

        if self.checkOnly:
            MyFeatureTestCase(
                feature_path=feature_path,
                scenarios_to_run=scenarios_to_run,
                config=self.config,
            )
            return MyTestSuite(tests=[])
        else:
            return MyTestSuite(
                tests=[
                    MyFeatureTestCase(
                        feature_path=feature_path,
                        scenarios_to_run=scenarios_to_run,
                        config=self.config,
                        tag_list=self.tag_list,
                    ),
                ],
            )
Beispiel #10
0
 def _loadTestsFromTestClass(self, event, cls):
     # ... fire event for others to load from
     evt = LoadFromTestClassEvent(event.loader, cls)
     result = self.session.hooks.loadTestsFromTestClass(evt)
     if evt.handled:
         loaded_suite = result or event.loader.suiteClass()
     else:
         names = self._getTestMethodNames(event, cls)
         loaded_suite = event.loader.suiteClass([
             util.transplant_class(MethodTestCase(cls),
                                   cls.__module__)(name) for name in names
         ])
     if evt.extraTests:
         loaded_suite.addTests(evt.extraTests)
     # ... add extra tests
     return loaded_suite
Beispiel #11
0
 def _generateFuncTests(self, obj):
     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
     for index, argSet in enumerate_params(obj.paramList):
         def func(argSet=argSet, obj=obj):
             return obj(*argSet)
         func = functools.update_wrapper(func, obj)
         delattr(func, 'paramList')
         name = '%s.%s' % (obj.__module__, obj.__name__)
         func_name = util.name_from_args(name, index, argSet)
         yield util.transplant_class(
             ParamsFunctionCase, obj.__module__)(func_name, func, **args)
Beispiel #12
0
 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) 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 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__))
Beispiel #13
0
 def createTest(name):
     return util.transplant_class(
         GeneratorMethodCase(instance.__class__),
         instance.__class__.__module__)(name, **args)
Beispiel #14
0
 def createTest(name):
     return util.transplant_class(GeneratorFunctionCase,
                                  obj.__module__)(name, **args)
Beispiel #15
0
 def createTest(name):
     return util.transplant_class(
         GeneratorMethodCase(instance.__class__),
         instance.__class__.__module__)(name, **args)
Beispiel #16
0
 def createTest(name):
     return util.transplant_class(
         GeneratorFunctionCase, obj.__module__)(name, **args)