Пример #1
0
    def prepare_test_args(self, verbose=1, extra_argv=None, coverage=False,
            capture=True, knownfailure=True):
        """
        Prepare arguments for the `test` method.

        Takes the same arguments as `test`.
        """
        # fail with nice error message if nose is not present
        nose = import_nose()

        # compile argv
        argv = self._test_argv(verbose, extra_argv)

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

        # Capture output only if needed
        if not capture:
            argv += ['-s']

        # construct list of plugins
        plugins = []
        if knownfailure:
            plugins.append(KnownFailure())
        plugins += [p() for p in nose.plugins.builtin.plugins]

        return argv, plugins
Пример #2
0
    def prepare_test_args(self,
                          verbose=1,
                          extra_argv=None,
                          coverage=False,
                          capture=True,
                          knownfailure=True):
        """
        Prepare arguments for the `test` method.

        Takes the same arguments as `test`.
        """
        # fail with nice error message if nose is not present
        nose = import_nose()

        # compile argv
        argv = self._test_argv(verbose, extra_argv)

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

        # Capture output only if needed
        if not capture:
            argv += ['-s']

        # construct list of plugins
        plugins = []
        if knownfailure:
            plugins.append(KnownFailure())
        plugins += [p() for p in nose.plugins.builtin.plugins]

        return argv, plugins
Пример #3
0
def assert_raises_regex(exception_class,
                        expected_regexp,
                        callable_obj=None,
                        *args,
                        **kwargs):
    """
    Fail unless an exception of class exception_class and with message that
    matches expected_regexp is thrown by callable when invoked with arguments
    args and keyword arguments kwargs.
    Name of this function adheres to Python 3.2+ reference, but should work in
    all versions down to 2.6.
    Notes
    -----
    .. versionadded:: 1.8.0
    """
    __tracebackhide__ = True  # Hide traceback for py.test
    nose = import_nose()

    if sys.version_info.major >= 3:
        funcname = nose.tools.assert_raises_regex
    else:
        # Only present in Python 2.7, missing from unittest in 2.6
        funcname = nose.tools.assert_raises_regexp

    return funcname(exception_class, expected_regexp, callable_obj, *args,
                    **kwargs)
Пример #4
0
    def _show_system_info(self):
        nose = import_nose()

        import theano
        print("Theano version %s" % theano.__version__)
        theano_dir = os.path.dirname(theano.__file__)
        print("theano is installed in %s" % theano_dir)

        super(TheanoNoseTester, self)._show_system_info()
Пример #5
0
    def _show_system_info(self):
        nose = import_nose()

        import theano
        print "Theano version %s" % theano.__version__
        theano_dir = os.path.dirname(theano.__file__)
        print "theano is installed in %s" % theano_dir

        super(TheanoNoseTester, self)._show_system_info()
Пример #6
0
    def _show_system_info(self):
        nose = import_nose()

        import pygpu
        #print ("pygpu version %s" % pygpu.__version__)
        pygpu_dir = os.path.dirname(pygpu.__file__)
        print("pygpu is installed in %s" % pygpu_dir)

        super(NoseTester, self)._show_system_info()
Пример #7
0
    def _show_system_info(self):
        nose = import_nose()

        import pygpu
        #print ("pygpu version %s" % pygpu.__version__)
        pygpu_dir = os.path.dirname(pygpu.__file__)
        print ("pygpu is installed in %s" % pygpu_dir)

        super(NoseTester, self)._show_system_info()
Пример #8
0
def run_module_suite(file_to_run=None, argv=None):
    """
    Overload numpy's run_module_suite to allow passing arguments to nose.

    Any argument passed to 'argv' will be passed onto nose.

    For example, 'run_module_suite(argv=["","-A","not slow"])' will only run
    tests that are not labelled with the decorator 'slow'.

    This is particularly useful if argv is passed 'sys.argv'.
    """
    if file_to_run is None:
        f = sys._getframe(1)
        file_to_run = f.f_locals.get('__file__', None)
        if file_to_run is None:
            raise AssertionError
    if argv is None:
        argv = [""]
    import_nose().run(argv=argv + [file_to_run])
Пример #9
0
def run_module_suite(file_to_run=None,argv=None):
    """
    Overload numpy's run_module_suite to allow passing arguments to nose.

    Any argument passed to 'argv' will be passed onto nose.

    For example, 'run_module_suite(argv=["","-A","not slow"])' will only run
    tests that are not labelled with the decorator 'slow'.

    This is particularly useful if argv is passed 'sys.argv'.
    """
    if file_to_run is None:
        f = sys._getframe(1)
        file_to_run = f.f_locals.get('__file__', None)
        if file_to_run is None:
            raise AssertionError
    if argv is None:
        argv = [""]
    import_nose().run(argv=argv+[file_to_run])
Пример #10
0
def test_main(with_coverage=False):
    """``main`` function for test modules"""
    frame = sys._getframe(1)
    mod_name = frame.f_locals.get('__name__', None)
    if mod_name == "__main__":
        file_to_run = frame.f_locals.get('__file__', None)
        if file_to_run is not None:
            argv = ['', file_to_run, '-vv', '-s']
            if with_coverage:
                module = get_base_module(file_to_run)
                if module is not None:
                    argv = argv + ['--with-coverage', '--cover-package', module]
                    # reload module so it can be instrumented by coverage
                    sys.modules.pop(module)
                    # reloading here 
                    #reload(sys.modules[module])
            import_nose().run(argv=argv)
            #run_module_suite(file_to_run)
        else:
            print "Could not determine the file name of the current file. Probably this function has been called by execfile."
Пример #11
0
def assert_raises_regex(exception_class, expected_regexp, callable_obj=None, *args, **kwargs):
    """
    Fail unless an exception of class exception_class and with message that
    matches expected_regexp is thrown by callable when invoked with arguments
    args and keyword arguments kwargs.
    Name of this function adheres to Python 3.2+ reference, but should work in
    all versions down to 2.6.
    Notes
    -----
    .. versionadded:: 1.8.0
    """
    __tracebackhide__ = True  # Hide traceback for py.test
    nose = import_nose()

    if sys.version_info.major >= 3:
        funcname = nose.tools.assert_raises_regex
    else:
        # Only present in Python 2.7, missing from unittest in 2.6
        funcname = nose.tools.assert_raises_regexp

    return funcname(exception_class, expected_regexp, callable_obj, *args, **kwargs)