unittest ValueError

C

Chris Fonnesbeck

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

class testMCMC(unittest.TestCase):

def setUp(self):

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

def testCoalMiningDisasters(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.sample(iterations, burn=burn,
thin=thin, plot=True))

# Run convergence diagnostics
self.sampler.convergence()

# Plot autocorrelation
self.sampler.autocorrelation()

# Goodness of fit
self.failIf(self.sampler.goodness(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.SystemExit Traceback (most
recent call last)

/Users/chris/<ipython console>

/Library/Frameworks/Python.framework/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.TestProgram'>
2990

/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/unittest.py
in __init__(self=<unittest.TestProgram object at 0x10e6c10>,
module='__main__', defaultTest=None, argv=['/usr/local/bin/ipython'],
testRunner=None, testLoader=<unittest.TestLoader object at 0x5feb30>)
757 self.progName = os.path.basename(argv[0])
758 self.parseArgs(argv)
--> 759 self.runTests()
self.runTests = <bound method TestProgram.runTests of
<unittest.TestProgram object at 0x10e6c10>>
760
761 def usageExit(self, msg=None):

/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/unittest.py
in runTests(self=<unittest.TestProgram object at 0x10e6c10>)
795 self.testRunner = TextTestRunner(verbosity=self.verbosity)
796 result = self.testRunner.run(self.test)
--> 797 sys.exit(not result.wasSuccessful())
global sys.exit = <built-in function exit>
result.wasSuccessful = <bound method
_TextTestResult.wasSuccessful of <unittest._TextTestResult 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.ValueError Traceback (most
recent call last)

/Users/chris/<ipython console>

/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/unittest.py
in __init__(self=<PyMC.MCMC.testMCMC testMethod=runTest>,
methodName='runTest')
206 self.__testMethodDoc = testMethod.__doc__
207 except AttributeError:
--> 208 raise ValueError, "no such test method in %s: %s" % \
global ValueError = undefined
self.__class__ = <class 'PyMC.MCMC.testMCMC'>
methodName = 'runTest'
209 (self.__class__, methodName)
210

ValueError: no such test method in <class 'PyMC.MCMC.testMCMC'>: 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,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,074
Latest member
StanleyFra

Latest Threads

Top