Beispiel #1
0
    def test_shared_by_class_name(self):
        ex = self.get_fake_ex()
        app = NoseApp()

        app.shared_extension(cls=ex)

        self.assertIsInstance(extensions.get(ex.name), ex)
Beispiel #2
0
    def test_shared_by_name(self):
        ex = self.get_fake_ex()
        app = NoseApp()

        app.shared_extension(name='test', cls=ex)

        self.assertIsInstance(extensions.get('test'), ex)
Beispiel #3
0
    def runTest(self):
        from noseapp.core import extensions

        extensions.set('test', dict(test='test'))
        self.assertEqual(extensions.get('test').get('test'), 'test')

        extensions.clear()
        self.assertRaises(extensions.ExtensionNotFound, extensions.get, 'test')
Beispiel #4
0
    def test_shared_with_args_kwargs(self):
        ex = self.get_fake_ex()
        app = NoseApp()

        app.shared_extension(cls=ex, args=(1, 2), kwargs={'test': 'test'})

        get_ex = extensions.get(ex.name)

        self.assertIsInstance(get_ex, ex)
        self.assertEqual(len(get_ex.args), 2)
        self.assertEqual(get_ex.kwargs.get('test'), 'test')
Beispiel #5
0
    def update_by_require(self, require):
        """
        Update extension storage by require from extensions tmp

        :param require: extensions names
        :type require: list
        """
        self.__require.extend(require)

        for ext_name in require:
            self.__extensions[ext_name] = extensions.get(ext_name)
Beispiel #6
0
    def setup_extensions(cls, require):
        """
        Init require extensions

        :param require: extensions list
        :type require: list or tuple
        """
        if require and hasattr(require, '__iter__'):
            for ext_name in require:
                setattr(cls, ext_name, extensions.get(ext_name))

        return cls
Beispiel #7
0
    def test_shared_data(self):
        data = {'test': 'test'}

        app = NoseApp()
        app.shared_data('test_data', data)

        get_data = extensions.get('test_data')

        self.assertEqual(get_data.get('test'), 'test')

        get_data['test'] = 1

        self.assertEqual(data.get('test'), 'test')
Beispiel #8
0
    def __call__(self,
                 program_data,
                 shuffle=None,
                 case_name=None,
                 method_name=None):
        """
        Build suite. After call suite instance will be
        created instance of nose.suite.ContextSuite

        :param program_data: instance of ProgramData
        :type program_data: noseapp.core.program.ProgramData

        :param shuffle: callable object for randomize test case list
        :param case_name: test name for build
        :param method_name: test case method name for build

        :raises: RuntimeError
        :rtype: noseapp.core.suite.base.BaseSuite
        """
        if not self.__of_app:
            raise RuntimeError('Suite can not be building, not mounted to app')

        self.__is_build = True

        for ext_name in self.context.require:
            ext = extensions.get(ext_name)
            self.context.add_extension(ext_name, ext)

        if callable(shuffle):
            shuffle(self.__context.test_cases)

        def make_suites():
            suites = []

            if case_name:
                case = loader.load_case_from_suite(case_name, self)
                tests = loader.load_tests_from_test_case(
                    case.mount_to_suite(self),
                    method_name=method_name,
                )

                suites.append(
                    program_data.suite_class(
                        tests,
                        context=case,
                        config=program_data.config,
                        pre_run_handlers=self.__context.pre_run,
                        post_run_handlers=self.__context.post_run,
                        resultProxy=program_data.result_proxy_factory,
                    ),
                )
            else:
                for case in self.__context.test_cases:
                    tests = loader.load_tests_from_test_case(
                        case.mount_to_suite(self),
                    )

                    suites.append(
                        program_data.suite_class(
                            tests,
                            context=case,
                            config=program_data.config,
                            pre_run_handlers=self.__context.pre_run,
                            post_run_handlers=self.__context.post_run,
                            resultProxy=program_data.result_proxy_factory,
                        ),
                    )

            return suites

        return program_data.suite_class(
            make_suites(),
            context=self.__context,
            config=program_data.config,
        )