Package mvpa :: Package tests :: Module test_report

[hide private]
[frames] | no frames]

# Source Code for Module mvpa.tests.test_report

      1  # emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
      2  # vi: set ft=python sts=4 ts=4 sw=4 et:
      3  ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##
      4  #
      5  #   See COPYING file distributed along with the PyMVPA package for the
      6  #   copyright and license terms.
      7  #
      8  ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##
      9  """Unit tests for PyMVPA simple report facility"""
     10
     11  import unittest, os
     12  from tempfile import mktemp
     13
     14  from mvpa.base import verbose, externals
     15
     16  from mvpa.base.report_dummy import Report as DummyReport
     17  _test_classes = [ DummyReport ]
     18
     19  from tests_warehouse import sweepargs
     20
     21  if externals.exists('reportlab', raiseException=False):
     22      from mvpa.base.report import Report
     23      _test_classes += [ Report ]
     24
     25  if __debug__:
     26      from mvpa.base import debug
     27
     28 -class ReportTest(unittest.TestCase):
     29      """Just basic testing of reports -- pretty much that nothing fails
     30      """
     31
     32      @sweepargs(rc=_test_classes)
     33 -    def testBasic(self, rc):
     34          """Test all available reports, real or dummy for just working
     35          """
     36          dirname = mktemp('mvpa', 'test_report')
     37          report = rc('UnitTest report',
     38                      title="Sample report for testing",
     39                      path=dirname)
     40          isdummy = isinstance(report, DummyReport)
     41
     42          ohandlers = verbose.handlers
     43          verbose.handlers = [report]
     44          verbose.level = 3
     45          verbose(1, "Starting")
     46          verbose(2, "Level 2")
     47
     48          if not isdummy:
     49              self.failUnless(len(report._story) == 2,
     50                              msg="We should have got some lines from verbose")
     51
     52          if __debug__:
     53              odhandlers = debug.handlers
     54              debug.handlers = [report]
     55              oactive = debug.active
     56              debug.active = ['TEST'] + debug.active
     57              debug('TEST', "Testing report as handler for debug")
     58              if not isdummy:
     59                  self.failUnless(len(report._story) == 4,
     60                              msg="We should have got some lines from debug")
     61              debug.active = oactive
     62              debug.handlers = odhandlers
     63
     64          os.makedirs(dirname)
     65
     66          if externals.exists('pylab plottable'):
     67              if not isdummy:
     68                  clen = len(report._story)
     69              import pylab as P
     70              P.ioff()
     71              P.close('all')
     72              P.figure()
     73              P.plot([1, 2], [3, 2])
     74
     75              P.figure()
     76              P.plot([2, 10], [3, 2])
     77              P.title("Figure 2 must be it")
     78              report.figures()
     79
     80              if not isdummy:
     81                  self.failUnless(
     82                      len(report._story) == clen+2,
     83                      msg="We should have got some lines from figures")
     84
     85          report.text("Dugi bugi")
     86          # make sure we don't puke on xml like text with crap
     87          report.text("<kaj>$lkj&*()^$%#%</kaj>")
     88          report.text("locals:\n%s globals:\n%s" % (`locals()`, `globals()`))
     89          # bloody XML - just to check that there is no puke
     90          report.xml("<b>Dugi bugi</b>")
     91          report.save()
     92
     93          if externals.exists('pylab'):
     94              import pylab as P
     95              P.close('all')
     96              P.ion()
     97
     98          # cleanup
     99          if os.path.exists(dirname):
    100              # poor man recursive remove
    101              for f in os.listdir(dirname):
    102                  try:
    103                      os.remove(os.path.join(dirname, f))
    104                  except:
    105                      # could be a directory... but no deeper ones expected
    106                      for f2 in os.listdir(os.path.join(dirname, f)):
    107                          os.remove(os.path.join(dirname, f, f2))
    108                      os.rmdir(os.path.join(dirname, f))
    109              os.rmdir(dirname)
    110          verbose.handlers = ohandlers
    111
    112
    113 -def suite():
    114      return unittest.makeSuite(ReportTest)
    115
    116
    117  if __name__ == '__main__':
    118      import runner
    119