Ejemplo n.º 1
0
 def test_verbose_indent(self):
     """Test indent symbol
     """
     verbose.indent = "."
     verbose(2, self.msg)
     self.failUnlessEqual(self.sout.getvalue(), "..%s\n" % self.msg)
     verbose.indent = " "            # restore
Ejemplo n.º 2
0
 def test_verbose_indent(self):
     """Test indent symbol
     """
     verbose.indent = "."
     verbose(2, self.msg)
     self.failUnlessEqual(self.sout.getvalue(), "..%s\n" % self.msg)
     verbose.indent = " "            # restore
Ejemplo n.º 3
0
 def test_verbose_below(self):
     """Test if outputs at lower levels and indents
     by default with spaces
     """
     verbose(2, self.msg)
     self.failUnlessEqual(self.sout.getvalue(),
                          "  %s\n" % self.msg)
Ejemplo n.º 4
0
 def test_verbose_below(self):
     """Test if outputs at lower levels and indents
     by default with spaces
     """
     verbose(2, self.msg)
     self.failUnlessEqual(self.sout.getvalue(),
                          "  %s\n" % self.msg)
Ejemplo n.º 5
0
 def test_cr(self):
     """Test if works fine with carriage return (cr) symbol"""
     verbose(2, self.msg, cr=True)
     verbose(2, "rewrite", cr=True)
     verbose(1, "rewrite 2", cr=True)
     verbose(1, " add", cr=False, lf=False)
     verbose(1, " finish")
     target = '\r  %s\r              \rrewrite' % self.msg + \
              '\r       \rrewrite 2 add finish\n'
     self.failUnlessEqual(self.sout.getvalue(), target)
Ejemplo n.º 6
0
 def test_cr(self):
     """Test if works fine with carriage return (cr) symbol"""
     verbose(2, self.msg, cr=True)
     verbose(2, "rewrite", cr=True)
     verbose(1, "rewrite 2", cr=True)
     verbose(1, " add", cr=False, lf=False)
     verbose(1, " finish")
     target = '\r  %s\r              \rrewrite' % self.msg + \
              '\r       \rrewrite 2 add finish\n'
     self.failUnlessEqual(self.sout.getvalue(), target)
Ejemplo n.º 7
0
    def _set_active(self, active):
        """Set active logging set
        """
        # just unique entries... we could have simply stored Set I guess,
        # but then smth like debug.active += ["BLAH"] would not work
        from mvpa.base import verbose
        self.__active = []
        registered_keys = self.__registered.keys()
        for item in list(set(active)):
            if item == '':
                continue
            if isinstance(item, basestring):
                if item in ['?', 'list', 'help']:
                    self.print_registered(detailed=(item != '?'))
                    raise SystemExit(0)
                if item.upper() == "ALL":
                    verbose(2, "Enabling all registered debug handlers")
                    self.__active = registered_keys
                    break
                # try to match item as it is regexp
                regexp_str = "^%s$" % item
                try:
                    regexp = re.compile(regexp_str)
                except:
                    raise ValueError, \
                          "Unable to create regular expression out of  %s" % item
                matching_keys = filter(regexp.match, registered_keys)
                toactivate = matching_keys
                if len(toactivate) == 0:
                    ids = self.registered.keys()
                    ids.sort()
                    raise ValueError, \
                          "Unknown debug ID '%s' was asked to become active," \
                          " or regular expression '%s' did not get any match" \
                          " among known ids: %s" \
                          % (item, regexp_str, ids)
            else:
                toactivate = [item]

            # Lets check if asked items are known
            for item_ in toactivate:
                if not (item_ in registered_keys):
                    raise ValueError, \
                          "Unknown debug ID %s was asked to become active" \
                          % item_
            self.__active += toactivate

        self.__active = list(set(self.__active)) # select just unique ones
        self.__maxstrlength = max([len(str(x)) for x in self.__active] + [0])
        if len(self.__active):
            verbose(2, "Enabling debug handlers: %s" % `self.__active`)
Ejemplo n.º 8
0
 def test_no_lf(self):
     """Test if it works fine with no newline (LF) symbol"""
     verbose(2, self.msg, lf=False)
     verbose(2, " continue ", lf=False)
     verbose(2, "end")
     verbose(0, "new %s" % self.msg)
     self.failUnlessEqual(self.sout.getvalue(),
                          "  %s continue end\nnew %s\n" % \
                          (self.msg, self.msg))
Ejemplo n.º 9
0
 def test_no_lf(self):
     """Test if it works fine with no newline (LF) symbol"""
     verbose(2, self.msg, lf=False)
     verbose(2, " continue ", lf=False)
     verbose(2, "end")
     verbose(0, "new %s" % self.msg)
     self.failUnlessEqual(self.sout.getvalue(),
                          "  %s continue end\nnew %s\n" % \
                          (self.msg, self.msg))
Ejemplo n.º 10
0
    def aux_basic(self, dirname, rc):
        """Helper function -- to assure that all filehandlers
           get closed so we could remove trash directory.

           Otherwise -- .nfs* files on NFS-mounted drives cause problems
           """
        report = rc('UnitTest report',
                    title="Sample report for testing",
                    path=dirname)
        isdummy = isinstance(report, DummyReport)

        ohandlers = verbose.handlers
        verbose.handlers = [report]
        verbose.level = 3
        verbose(1, "Starting")
        verbose(2, "Level 2")

        if not isdummy:
            self.failUnless(len(report._story) == 2,
                            msg="We should have got some lines from verbose")

        if __debug__:
            odhandlers = debug.handlers
            debug.handlers = [report]
            oactive = debug.active
            debug.active = ['TEST'] + debug.active
            debug('TEST', "Testing report as handler for debug")
            if not isdummy:
                self.failUnless(len(report._story) == 4,
                                msg="We should have got some lines from debug")
            debug.active = oactive
            debug.handlers = odhandlers

        os.makedirs(dirname)

        if externals.exists('pylab plottable'):
            if not isdummy:
                clen = len(report._story)
            import pylab as pl
            pl.ioff()
            pl.close('all')
            pl.figure()
            pl.plot([1, 2], [3, 2])

            pl.figure()
            pl.plot([2, 10], [3, 2])
            pl.title("Figure 2 must be it")
            report.figures()

            if not isdummy:
                self.failUnless(
                    len(report._story) == clen + 2,
                    msg="We should have got some lines from figures")

        report.text("Dugi bugi")
        # make sure we don't puke on xml like text with crap
        report.text("<kaj>$lkj&*()^$%#%</kaj>")
        report.text("locals:\n%s globals:\n%s" %
                    ( ` locals() `, ` globals() `))
        # bloody XML - just to check that there is no puke
        report.xml("<b>Dugi bugi</b>")
        report.save()

        if externals.exists('pylab'):
            import pylab as pl
            pl.close('all')
            pl.ion()

        verbose.handlers = ohandlers
        pass
Ejemplo n.º 11
0
    def aux_basic(self, dirname, rc):
        """Helper function -- to assure that all filehandlers
           get closed so we could remove trash directory.

           Otherwise -- .nfs* files on NFS-mounted drives cause problems
           """
        report = rc('UnitTest report',
                    title="Sample report for testing",
                    path=dirname)
        isdummy = isinstance(report, DummyReport)

        verbose.handlers = [report]
        verbose.level = 3
        verbose(1, "Starting")
        verbose(2, "Level 2")

        if not isdummy:
            self.failUnless(len(report._story) == 2,
                            msg="We should have got some lines from verbose")

        if __debug__:
            odhandlers = debug.handlers
            debug.handlers = [report]
            oactive = debug.active
            debug.active = ['TEST'] + debug.active
            debug('TEST', "Testing report as handler for debug")
            if not isdummy:
                self.failUnless(len(report._story) == 4,
                            msg="We should have got some lines from debug")
            debug.active = oactive
            debug.handlers = odhandlers

        os.makedirs(dirname)

        if externals.exists('pylab plottable'):
            if not isdummy:
                clen = len(report._story)
            import pylab as pl
            pl.ioff()
            pl.close('all')
            pl.figure()
            pl.plot([1, 2], [3, 2])

            pl.figure()
            pl.plot([2, 10], [3, 2])
            pl.title("Figure 2 must be it")
            report.figures()

            if not isdummy:
                self.failUnless(
                    len(report._story) == clen+2,
                    msg="We should have got some lines from figures")

        report.text("Dugi bugi")
        # make sure we don't puke on xml like text with crap
        report.text("<kaj>$lkj&*()^$%#%</kaj>")
        report.text("locals:\n%s globals:\n%s" % (`locals()`, `globals()`))
        # bloody XML - just to check that there is no puke
        report.xml("<b>Dugi bugi</b>")
        report.save()

        if externals.exists('pylab'):
            import pylab as pl
            pl.close('all')
            pl.ion()

        pass
Ejemplo n.º 12
0
 def test_verbose_above(self):
     """Test if it doesn't output at higher levels"""
     verbose(5, self.msg)
     self.failUnlessEqual(self.sout.getvalue(), "")
Ejemplo n.º 13
0
pymvpa_dataroot = \
        cfg.get('data', 'root',
                default=os.path.join(os.path.dirname(__file__), 'data'))
# locate PyMVPA data database root -- also might not be installed, but if it is,
# it should be at this location
pymvpa_datadbroot = \
        cfg.get('datadb', 'root',
                default=os.path.join(os.curdir, 'datadb'))

if not __debug__:
    try:
        import psyco
        psyco.profile()
    except ImportError:
        from mvpa.base import verbose
        verbose(2, "Psyco online compilation is not enabled")
else:
    # Controllable seeding of random number generator
    from mvpa.base import debug

    debug('INIT', 'mvpa')

if cfg.has_option('general', 'seed'):
    _random_seed = cfg.getint('general', 'seed')
else:
    _random_seed = int(np.random.uniform() * (2**31 - 1))


def seed(random_seed):
    """Uniform and combined seeding of all relevant random number
    generators.
Ejemplo n.º 14
0
pymvpa_dataroot = \
        cfg.get('data', 'root',
                default=os.path.join(os.path.dirname(__file__), 'data'))
# locate PyMVPA data database root -- also might not be installed, but if it is,
# it should be at this location
pymvpa_datadbroot = \
        cfg.get('datadb', 'root',
                default=os.path.join(os.curdir, 'datadb'))

if not __debug__:
    try:
        import psyco
        psyco.profile()
    except ImportError:
        from mvpa.base import verbose
        verbose(2, "Psyco online compilation is not enabled")
else:
    # Controllable seeding of random number generator
    from mvpa.base import debug

    debug('INIT', 'mvpa')

if cfg.has_option('general', 'seed'):
    _random_seed = cfg.getint('general', 'seed')
else:
    _random_seed = int(np.random.uniform()*(2**31-1))

def seed(random_seed):
    """Uniform and combined seeding of all relevant random number
    generators.
    """
Ejemplo n.º 15
0
 def test_verbose_above(self):
     """Test if it doesn't output at higher levels"""
     verbose(5, self.msg)
     self.failUnlessEqual(self.sout.getvalue(), "")
Ejemplo n.º 16
0
    def testBasic(self, rc):
        """Test all available reports, real or dummy for just working
        """
        dirname = mktemp('mvpa', 'test_report')
        report = rc('UnitTest report',
                    title="Sample report for testing",
                    path=dirname)
        isdummy = isinstance(report, DummyReport)

        ohandlers = verbose.handlers
        verbose.handlers = [report]
        verbose.level = 3
        verbose(1, "Starting")
        verbose(2, "Level 2")

        if not isdummy:
            self.failUnless(len(report._story) == 2,
                            msg="We should have got some lines from verbose")

        if __debug__:
            odhandlers = debug.handlers
            debug.handlers = [report]
            oactive = debug.active
            debug.active = ['TEST'] + debug.active
            debug('TEST', "Testing report as handler for debug")
            if not isdummy:
                self.failUnless(len(report._story) == 4,
                            msg="We should have got some lines from debug")
            debug.active = oactive
            debug.handlers = odhandlers

        os.makedirs(dirname)

        if externals.exists('pylab plottable'):
            if not isdummy:
                clen = len(report._story)
            import pylab as P
            P.ioff()
            P.close('all')
            P.figure()
            P.plot([1, 2], [3, 2])

            P.figure()
            P.plot([2, 10], [3, 2])
            P.title("Figure 2 must be it")
            report.figures()

            if not isdummy:
                self.failUnless(
                    len(report._story) == clen+2,
                    msg="We should have got some lines from figures")

        report.text("Dugi bugi")
        # make sure we don't puke on xml like text with crap
        report.text("<kaj>$lkj&*()^$%#%</kaj>")
        report.text("locals:\n%s globals:\n%s" % (`locals()`, `globals()`))
        # bloody XML - just to check that there is no puke
        report.xml("<b>Dugi bugi</b>")
        report.save()

        if externals.exists('pylab'):
            import pylab as P
            P.close('all')
            P.ion()

        # cleanup
        if os.path.exists(dirname):
            # poor man recursive remove
            for f in os.listdir(dirname):
                try:
                    os.remove(os.path.join(dirname, f))
                except:
                    # could be a directory... but no deeper ones expected
                    for f2 in os.listdir(os.path.join(dirname, f)):
                        os.remove(os.path.join(dirname, f, f2))
                    os.rmdir(os.path.join(dirname, f))
            os.rmdir(dirname)
        verbose.handlers = ohandlers