コード例 #1
0
ファイル: main.py プロジェクト: gorlins/PyMVPA
def main():
    if __debug__:
        from mvpa.base import debug
        # Lets add some targets which provide additional testing
        debug.active += ['CHECK_.*']
        # NOTE: it had to be done here instead of test_clf.py for
        # instance, since for CHECK_RETRAIN it has to be set before object
        # gets created, ie while importing clfs.warehouse

    suites = collectTestSuites()

    # and make global test suite
    ts = unittest.TestSuite(suites.values())

    # no MVPA warnings during whole testsuite
    warning.handlers = []

    # No python warnings (like ctypes version for slmr)
    import warnings
    warnings.simplefilter('ignore')

    class TextTestRunnerPyMVPA(unittest.TextTestRunner):
        """Extend TextTestRunner to print out random seed which was
        used in the case of failure"""
        def run(self, test):
            result = super(TextTestRunnerPyMVPA, self).run(test)
            if not result.wasSuccessful():
                print "MVPA_SEED=%s" % _random_seed
                sys.exit(1)
            return result

    # finally run it
    TextTestRunnerPyMVPA(
            verbosity=int(cfg.get('tests', 'verbosity', default=1))
                ).run(ts)
コード例 #2
0
ファイル: __init__.py プロジェクト: geeragh/PyMVPA
def run(limit=None, verbosity=None):
    """Runs the full or a subset of the PyMVPA unittest suite.

    Parameters
    ----------
    limit : None or list
      If None, the full test suite is run. Alternatively, a list with test IDs
      can be provides. IDs are the base filenames of the test implementation,
      e.g. the ID for the suite in 'mvpa/tests/test_niftidataset.py' is
      'niftidataset'.
    verbosity : None or int
      Verbosity of unittests execution. If None, controlled by PyMVPA
      configuration tests/verbosity
    """
    if __debug__:
        from mvpa.base import debug
        # Lets add some targets which provide additional testing
        debug.active += ['CHECK_.*']

    # collect all tests
    suites = collect_test_suites()

    if limit is None:
        # make global test suite (use them all)
        ts = unittest.TestSuite(suites.values())
    else:
        ts = unittest.TestSuite([suites[s] for s in limit])

    # no MVPA warnings during whole testsuite (but restore handlers later on)
    handler_backup = warning.handlers
    warning.handlers = []

    # No python warnings (like ctypes version for slmr)
    import warnings
    warnings.simplefilter('ignore')

    class TextTestRunnerPyMVPA(unittest.TextTestRunner):
        """Extend TextTestRunner to print out random seed which was
        used in the case of failure"""
        def run(self, test):
            """Run the bloody test and puke the seed value if failed"""
            result = super(TextTestRunnerPyMVPA, self).run(test)
            if not result.wasSuccessful():
                print "MVPA_SEED=%s" % _random_seed

    if verbosity is None:
        verbosity = int(cfg.get('tests', 'verbosity', default=1))

    # finally run it
    TextTestRunnerPyMVPA(verbosity=verbosity).run(ts)

    # and nose tests
    run_nose_tests()

    # restore warning handlers
    warning.handlers = handler_backup
コード例 #3
0
ファイル: externals.py プロジェクト: geeragh/PyMVPA
def __check_matplotlib():
    """Check for presence of matplotlib and set backend if requested."""
    import matplotlib
    backend = cfg.get('matplotlib', 'backend')
    if backend:
        matplotlib.use(backend)
        import warnings
        # And disable useless warning from matplotlib in the future
        warnings.filterwarnings(
            'ignore', 'This call to matplotlib.use() has no effect.*',
            UserWarning)
コード例 #4
0
ファイル: externals.py プロジェクト: geeragh/PyMVPA
def __check_rpy2():
    """Check either rpy2 is available and also set it for the sane execution
    """
    import rpy2
    versions['rpy2'] = rpy2.__version__

    import rpy2.robjects
    r = rpy2.robjects.r
    r.options(warn=cfg.get('rpy', 'warn', default=-1))

    # To shut R up while it is importing libraries to do not ruin out
    # doctests
    r.library = lambda libname: \
                r("suppressPackageStartupMessages(library(%r))" % libname)
コード例 #5
0
ファイル: externals.py プロジェクト: B-Rich/PyMVPA
def _set_matplotlib_backend():
    """Check if we have custom backend to set and it is different
    from current one
    """
    backend = cfg.get('matplotlib', 'backend')
    if backend:
        import matplotlib as mpl
        mpl_backend = mpl.get_backend().lower()
        if mpl_backend != backend.lower():
            if __debug__:
                debug('EXT_', "Trying to set matplotlib backend to %s" % backend)
            mpl.use(backend)
            import warnings
            # And disable useless warning from matplotlib in the future
            warnings.filterwarnings(
                'ignore', 'This call to matplotlib.use() has no effect.*',
                UserWarning)
        elif __debug__:
            debug('EXT_',
                  "Not trying to set matplotlib backend to %s since it was "
                  "already set" % backend)
コード例 #6
0
ファイル: externals.py プロジェクト: heqing-psychology/PyMVPA
def _set_matplotlib_backend():
    """Check if we have custom backend to set and it is different
    from current one
    """
    backend = cfg.get('matplotlib', 'backend')
    if backend:
        import matplotlib as mpl
        mpl_backend = mpl.get_backend().lower()
        if mpl_backend != backend.lower():
            if __debug__:
                debug('EXT_',
                      "Trying to set matplotlib backend to %s" % backend)
            mpl.use(backend)
            import warnings
            # And disable useless warning from matplotlib in the future
            warnings.filterwarnings(
                'ignore', 'This call to matplotlib.use() has no effect.*',
                UserWarning)
        elif __debug__:
            debug(
                'EXT_',
                "Not trying to set matplotlib backend to %s since it was "
                "already set" % backend)
コード例 #7
0
ファイル: externals.py プロジェクト: gorlins/PyMVPA
def __check_matplotlib():
    """Check for presence of matplotlib and set backend if requested."""
    import matplotlib
    backend = cfg.get('matplotlib', 'backend')
    if backend:
        matplotlib.use(backend)
コード例 #8
0
ファイル: __init__.py プロジェクト: esc/PyMVPA
def run(limit=None, verbosity=None, exit_=False):
    """Runs the full or a subset of the PyMVPA unittest suite.

    Parameters
    ----------
    limit : None or list
      If None, the full test suite is run. Alternatively, a list with test IDs
      can be provides. IDs are the base filenames of the test implementation,
      e.g. the ID for the suite in 'mvpa/tests/test_niftidataset.py' is
      'niftidataset'.
    verbosity : None or int
      Verbosity of unittests execution. If None, controlled by PyMVPA
      configuration tests/verbosity.  Values >=3 enable all Python,
      and PyMVPA warnings, >=4 adds NumPy warnings, >=5 -- nose debug info.
    exit_ : bool, optional
      Either to exit with an error code upon the completion.
    """
    if __debug__:
        from mvpa.base import debug
        # Lets add some targets which provide additional testing
        debug.active += ['CHECK_.*']

    if verbosity is None:
        verbosity = int(cfg.get('tests', 'verbosity', default=1))

    # provide people with a hint about the warnings that might show up in a
    # second
    if verbosity:
        print("T: MVPA_SEED=%s" % _random_seed)
        if verbosity > 1:
            print('T: Testing for availability of external software packages.')

    # So we could see all warnings about missing dependencies
    maxcount = warning.maxcount
    warning.maxcount = 1000

    # fully test of externals
    externals.test_all_dependencies(verbosity=max(0, verbosity-1))

    if verbosity < 3:
        # no MVPA warnings during whole testsuite (but restore handlers later on)
        handler_backup = warning.handlers
        warning.handlers = []

        # No python warnings (like ctypes version for slmr)
        import warnings
        warnings.simplefilter('ignore')

    if verbosity < 4:
        # No NumPy
        np_errsettings = np.geterr()
        np.seterr(**dict([(x, 'ignore') for x in np_errsettings]))

    try:
        if externals.exists('nose'):
            # Lets just use nose
            run_tests_using_nose(limit=limit,
                                 verbosity=verbosity,
                                 exit_=exit_)
        else:
            print("T: Warning -- major bulk of tests is skipped since nose "
                  "is unavailable")
            # collect all tests
            suites = collect_test_suites(verbosity=verbosity)

            if limit is None:
                # make global test suite (use them all)
                ts = unittest.TestSuite(suites.values())
            else:
                ts = unittest.TestSuite([suites[s] for s in limit])


            class TextTestRunnerPyMVPA(unittest.TextTestRunner):
                """Extend TextTestRunner to print out random seed which was
                used in the case of failure"""
                def run(self, test):
                    """Run the bloody test and puke the seed value if failed"""
                    result = super(TextTestRunnerPyMVPA, self).run(test)
                    if not result.wasSuccessful():
                        print "MVPA_SEED=%s" % _random_seed

            # finally run it
            TextTestRunnerPyMVPA(verbosity=verbosity).run(ts)
    finally:
        # restore warning handlers
        warning.maxcount = maxcount

    if verbosity < 3:
        # restore warning handlers
        warning.handlers = handler_backup

    if verbosity < 4:
        # restore numpy settings
        np.seterr(**np_errsettings)
コード例 #9
0
ファイル: __init__.py プロジェクト: heqing-psychology/PyMVPA
def run(limit=None, verbosity=None, exit_=False):
    """Runs the full or a subset of the PyMVPA unittest suite.

    Parameters
    ----------
    limit : None or list
      If None, the full test suite is run. Alternatively, a list with test IDs
      can be provides. IDs are the base filenames of the test implementation,
      e.g. the ID for the suite in 'mvpa/tests/test_niftidataset.py' is
      'niftidataset'.
    verbosity : None or int
      Verbosity of unittests execution. If None, controlled by PyMVPA
      configuration tests/verbosity
    exit_ : bool, optional
      Either to exit with an error code upon the completion.
    """
    if __debug__:
        from mvpa.base import debug
        # Lets add some targets which provide additional testing
        debug.active += ['CHECK_.*']

    if verbosity is None:
        verbosity = int(cfg.get('tests', 'verbosity', default=1))

    # provide people with a hint about the warnings that might show up in a
    # second
    if verbosity:
        print("T: MVPA_SEED=%s" % _random_seed)
        if verbosity > 1:
            print('T: Testing for availability of external software packages.')

    # So we could see all warnings about missing dependencies
    warning.maxcount = 1000
    # fully test of externals
    externals.test_all_dependencies(verbosity=max(0, verbosity - 1))

    # no MVPA warnings during whole testsuite (but restore handlers later on)
    handler_backup = warning.handlers
    warning.handlers = []

    # No python warnings (like ctypes version for slmr)
    import warnings
    warnings.simplefilter('ignore')

    try:
        if externals.exists('nose'):
            # Lets just use nose
            run_tests_using_nose(limit=limit, verbosity=verbosity, exit_=exit_)
        else:
            print(
                "T: Warning -- major bulk of tests is skipped since nose "
                "is unavailable")
            # collect all tests
            suites = collect_test_suites(verbosity=verbosity)

            if limit is None:
                # make global test suite (use them all)
                ts = unittest.TestSuite(suites.values())
            else:
                ts = unittest.TestSuite([suites[s] for s in limit])

            class TextTestRunnerPyMVPA(unittest.TextTestRunner):
                """Extend TextTestRunner to print out random seed which was
                used in the case of failure"""
                def run(self, test):
                    """Run the bloody test and puke the seed value if failed"""
                    result = super(TextTestRunnerPyMVPA, self).run(test)
                    if not result.wasSuccessful():
                        print "MVPA_SEED=%s" % _random_seed

            if verbosity is None:
                verbosity = int(cfg.get('tests', 'verbosity', default=1))

            # finally run it
            TextTestRunnerPyMVPA(verbosity=verbosity).run(ts)
    finally:
        # restore warning handlers
        warning.handlers = handler_backup