Exemple #1
0
    def prepare_test_args(self,
                          label='fast',
                          verbose=1,
                          extra_argv=None,
                          doctests=False,
                          coverage=False):
        """
        Run tests for module using nose.

        This method does the heavy lifting for the `test` method. It takes all
        the same arguments, for details see `test`.

        See Also
        --------
        test

        """

        # if doctests is in the extra args, remove it and set the doctest
        # flag so the NumPy doctester is used instead
        if extra_argv and '--with-doctest' in extra_argv:
            extra_argv.remove('--with-doctest')
            doctests = True

        argv = self._test_argv(label, verbose, extra_argv)
        if doctests:
            argv += ['--with-numpydoctest']

        if coverage:
            argv += [
                '--cover-package=%s' % self.package_name, '--with-coverage',
                '--cover-tests', '--cover-inclusive', '--cover-erase'
            ]

        # bypass these samples under distutils
        argv += ['--exclude', 'f2py_ext']
        argv += ['--exclude', 'f2py_f90_ext']
        argv += ['--exclude', 'gen_ext']
        argv += ['--exclude', 'pyrex_ext']
        argv += ['--exclude', 'swig_ext']
        argv += ['--exclude', 'array_from_pyobj']

        nose = import_nose()

        # construct list of plugins, omitting the existing doctest plugin
        import nose.plugins.builtin
        from noseclasses import NumpyDoctest, KnownFailure
        plugins = [NumpyDoctest(), KnownFailure()]
        for p in nose.plugins.builtin.plugins:
            plug = p()
            if plug.name == 'doctest':
                # skip the builtin doctest plugin
                continue

            plugins.append(plug)

        return argv, plugins
Exemple #2
0
    def prepare_test_args(self,
                          label='fast',
                          verbose=1,
                          extra_argv=None,
                          doctests=False,
                          coverage=False):
        ''' Run tests for module using nose

        %(test_header)s
        doctests : boolean
            If True, run doctests in module, default False
        coverage : boolean
            If True, report coverage of NumPy code, default False
            (Requires the coverage module:
             http://nedbatchelder.com/code/modules/coverage.html)
        '''

        # if doctests is in the extra args, remove it and set the doctest
        # flag so the NumPy doctester is used instead
        if extra_argv and '--with-doctest' in extra_argv:
            extra_argv.remove('--with-doctest')
            doctests = True

        argv = self._test_argv(label, verbose, extra_argv)
        if doctests:
            argv += ['--with-numpydoctest']

        if coverage:
            argv += [
                '--cover-package=%s' % self.package_name, '--with-coverage',
                '--cover-tests', '--cover-inclusive', '--cover-erase'
            ]

        # bypass these samples under distutils
        argv += ['--exclude', 'f2py_ext']
        argv += ['--exclude', 'f2py_f90_ext']
        argv += ['--exclude', 'gen_ext']
        argv += ['--exclude', 'pyrex_ext']
        argv += ['--exclude', 'swig_ext']
        argv += ['--exclude', 'array_from_pyobj']

        nose = import_nose()

        # construct list of plugins, omitting the existing doctest plugin
        import nose.plugins.builtin
        from noseclasses import NumpyDoctest, KnownFailure
        plugins = [NumpyDoctest(), KnownFailure()]
        for p in nose.plugins.builtin.plugins:
            plug = p()
            if plug.name == 'doctest':
                # skip the builtin doctest plugin
                continue

            plugins.append(plug)

        return argv, plugins
Exemple #3
0
    def prepare_test_args(self,
                          label='fast',
                          verbose=1,
                          extra_argv=None,
                          doctests=False,
                          coverage=False):
        """
        Run tests for module using nose.

        This method does the heavy lifting for the `test` method. It takes all
        the same arguments, for details see `test`.

        See Also
        --------
        test

        """
        # fail with nice error message if nose is not present
        import_nose()
        # compile argv
        argv = self._test_argv(label, verbose, extra_argv)
        # bypass tests noted for exclude
        for ename in self.excludes:
            argv += ['--exclude', ename]
        # our way of doing coverage
        if coverage:
            argv += [
                '--cover-package=%s' % self.package_name, '--with-coverage',
                '--cover-tests', '--cover-erase'
            ]
        # construct list of plugins
        import nose.plugins.builtin
        from noseclasses import KnownFailure, Unplugger
        plugins = [KnownFailure()]
        plugins += [p() for p in nose.plugins.builtin.plugins]
        # add doctesting if required
        doctest_argv = '--with-doctest' in argv
        if doctests == False and doctest_argv:
            doctests = True
        plug = self._get_custom_doctester()
        if plug is None:
            # use standard doctesting
            if doctests and not doctest_argv:
                argv += ['--with-doctest']
        else:  # custom doctesting
            if doctest_argv:  # in fact the unplugger would take care of this
                argv.remove('--with-doctest')
            plugins += [Unplugger('doctest'), plug]
            if doctests:
                argv += ['--with-' + plug.name]
        return argv, plugins
Exemple #4
0
    def test(self,
             label='fast',
             verbose=1,
             extra_argv=None,
             doctests=False,
             coverage=False,
             **kwargs):
        ''' Run tests for module using nose

        %(test_header)s
        doctests : boolean
            If True, run doctests in module, default False
        coverage : boolean
            If True, report coverage of NumPy code, default False
            (Requires the coverage module:
             http://nedbatchelder.com/code/modules/coverage.html)
        '''

        old_args = set(
            ['level', 'verbosity', 'all', 'sys_argv', 'testcase_pattern'])
        unexpected_args = set(kwargs.keys()) - old_args
        if len(unexpected_args) > 0:
            ua = ', '.join(unexpected_args)
            raise TypeError("test() got unexpected arguments: %s" % ua)

        # issue a deprecation warning if any of the pre-1.2 arguments to
        # test are given
        if old_args.intersection(kwargs.keys()):
            warnings.warn("This method's signature will change in the next " \
                          "release; the level, verbosity, all, sys_argv, " \
                          "and testcase_pattern keyword arguments will be " \
                          "removed. Please update your code.",
                          DeprecationWarning, stacklevel=2)

        # Use old arguments if given (where it makes sense)
        # For the moment, level and sys_argv are ignored

        # replace verbose with verbosity
        if kwargs.get('verbosity') is not None:
            verbose = kwargs.get('verbosity')
            # cap verbosity at 3 because nose becomes *very* verbose beyond that
            verbose = min(verbose, 3)

        import utils
        utils.verbose = verbose

        # if all evaluates as True, omit attribute filter and run doctests
        if kwargs.get('all'):
            label = ''
            doctests = True

        # if doctests is in the extra args, remove it and set the doctest
        # flag so the NumPy doctester is used instead
        if extra_argv and '--with-doctest' in extra_argv:
            extra_argv.remove('--with-doctest')
            doctests = True

        argv = self._test_argv(label, verbose, extra_argv)
        if doctests:
            argv += ['--with-numpydoctest']
            print "Running unit tests and doctests for %s" % self.package_name
        else:
            print "Running unit tests for %s" % self.package_name

        if coverage:
            argv += [
                '--cover-package=%s' % self.package_name, '--with-coverage',
                '--cover-tests', '--cover-inclusive', '--cover-erase'
            ]

        # bypass these samples under distutils
        argv += ['--exclude', 'f2py_ext']
        argv += ['--exclude', 'f2py_f90_ext']
        argv += ['--exclude', 'gen_ext']
        argv += ['--exclude', 'pyrex_ext']
        argv += ['--exclude', 'swig_ext']
        argv += ['--exclude', 'array_from_pyobj']

        self._show_system_info()

        nose = import_nose()

        # Because nose currently discards the test result object, but we need
        # to return it to the user, override TestProgram.runTests to retain
        # the result
        class NumpyTestProgram(nose.core.TestProgram):
            def runTests(self):
                """Run Tests. Returns true on success, false on failure, and
                sets self.success to the same value.
                """
                if self.testRunner is None:
                    self.testRunner = nose.core.TextTestRunner(
                        stream=self.config.stream,
                        verbosity=self.config.verbosity,
                        config=self.config)
                plug_runner = self.config.plugins.prepareTestRunner(
                    self.testRunner)
                if plug_runner is not None:
                    self.testRunner = plug_runner
                self.result = self.testRunner.run(self.test)
                self.success = self.result.wasSuccessful()
                return self.success

        # reset doctest state on every run
        import doctest
        doctest.master = None

        # construct list of plugins, omitting the existing doctest plugin
        import nose.plugins.builtin
        from noseclasses import NumpyDoctest, KnownFailure
        plugins = [NumpyDoctest(), KnownFailure()]
        for p in nose.plugins.builtin.plugins:
            plug = p()
            if plug.name == 'doctest':
                continue

            plugins.append(plug)

        t = NumpyTestProgram(argv=argv, exit=False, plugins=plugins)
        return t.result