unittest ValueError

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Chris Fonnesbeck

    #1

    unittest ValueError

    I have built the following unit test, observing the examples laid out
    in the python docs:

    class testMCMC(unitte st.TestCase):

    def setUp(self):

    # Create an instance of the sampler
    self.sampler = DisasterSampler ()

    def testCoalMiningD isasters(self):
    """Run coal mining disasters example sampler"""

    print 'Running coal mining disasters test case ...'

    # Specify the nimber of iterations to execute
    iterations = 10000
    thin = 2
    burn = 5000
    chains = 2

    # Run MCMC simulation
    for i in range(chains):

    self.failUnless (self.sampler.s ample(iteration s, burn=burn,
    thin=thin, plot=True))

    # Run convergence diagnostics
    self.sampler.co nvergence()

    # Plot autocorrelation
    self.sampler.au tocorrelation()

    # Goodness of fit
    self.failIf(sel f.sampler.goodn ess(iterations/10)['overall'] < 0.05)


    def test():
    # Run unit tests
    unittest.main()

    However, when I run test() from the python shell, it dies:

    In [2]: test()

    ----------------------------------------------------------------------
    Ran 0 tests in 0.000s

    OK
    ---------------------------------------------------------------------------
    exceptions.Syst emExit Traceback (most
    recent call last)

    /Users/chris/<ipython console>

    /Library/Frameworks/Python.framewor k/Versions/2.4/lib/python2.4/site-packages/PyMC/MCMC.py
    in test()
    2986
    2987 def test():
    2988 # Run unit tests
    -2989 unittest.main()
    global unittest.main = <class 'unittest.TestP rogram'>
    2990

    /Library/Frameworks/Python.framewor k/Versions/2.4/lib/python2.4/unittest.py
    in __init__(self=< unittest.TestPr ogram object at 0x10e6c10>,
    module='__main_ _', defaultTest=Non e, argv=['/usr/local/bin/ipython'],
    testRunner=None , testLoader=<uni ttest.TestLoade r object at 0x5feb30>)
    757 self.progName = os.path.basenam e(argv[0])
    758 self.parseArgs( argv)
    --759 self.runTests()
    self.runTests = <bound method TestProgram.run Tests of
    <unittest.TestP rogram object at 0x10e6c10>>
    760
    761 def usageExit(self, msg=None):

    /Library/Frameworks/Python.framewor k/Versions/2.4/lib/python2.4/unittest.py
    in runTests(self=< unittest.TestPr ogram object at 0x10e6c10>)
    795 self.testRunner = TextTestRunner( verbosity=self. verbosity)
    796 result = self.testRunner .run(self.test)
    --797 sys.exit(not result.wasSucce ssful())
    global sys.exit = <built-in function exit>
    result.wasSucce ssful = <bound method
    _TextTestResult .wasSuccessful of <unittest._Text TestResult run=0
    errors=0 failures=0>>
    798
    799 main = TestProgram

    SystemExit: False
    Type exit or quit to exit IPython (%Exit or %Quit do so unconditionally ).

    In [3]: from PyMC import testMCMC

    In [4]: foo = testMCMC()
    ---------------------------------------------------------------------------
    exceptions.Valu eError Traceback (most
    recent call last)

    /Users/chris/<ipython console>

    /Library/Frameworks/Python.framewor k/Versions/2.4/lib/python2.4/unittest.py
    in __init__(self=< PyMC.MCMC.testM CMC testMethod=runT est>,
    methodName='run Test')
    206 self.__testMeth odDoc = testMethod.__do c__
    207 except AttributeError:
    --208 raise ValueError, "no such test method in %s: %s" % \
    global ValueError = undefined
    self.__class__ = <class 'PyMC.MCMC.test MCMC'>
    methodName = 'runTest'
    209 (self.__class__ , methodName)
    210

    ValueError: no such test method in <class 'PyMC.MCMC.test MCMC'>: runTest


    I have no idea why this is happening. My TestCase class begins with
    "test", the method begins with "test", yet no tests are seen. Also, I
    do not get the runTest ValueError. I assumed that you get this method
    for free win TestCase. The examples certainly do not have this method,
    so I am not sure what the problem is.

    Thanks for any help,
    --
    Chris Fonnesbeck + Atlanta, GA + http://trichech.us
Working...