[Tutor] unittest problem
Guillermo Fernandez Castellanos
guillermo.fernandez at epfl.ch
Tue Mar 2 07:15:36 EST 2004
hi,
I think the mail did not arrive to the mailing list, so I send it again .Sorry
if I send it twice...
I'm doing a little test of unittest module. I'm having some problems making it
run. I guess is more a problem of OO design that unittest problem though...
Ï have a test.py program with the following code:
import os
import unittest
import begohandler
import test_begohandler
=>import test_statemachine
import test_syslogparse
class Base(unittest.TestCase):
def setUp(self):
if os.path.isfile('test.db'):
begohandler.do_opendb('test.db')
else:
print 'No database to open! Create it first'
sys.exit(1)
def tearDown(self):
begohandler.do_closedb()
pass
if __name__ == '__main__':
runner=unittest.TextTestRunner()
runner.run(unittest.makeSuite(test_syslogparse.syslogparseTest,'test'))
runner.run(unittest.makeSuite(test_begohandler.begohandlerTest,'test'))
=> runner.run(unittest.makeSuite(test_statemachine.statemachineTest,'test'))
When launching my program with the => lines commented, no problem. When no
lines are commented, I obtain the following error:
$ python test.py
Traceback (most recent call last):
File "test.py", line 5, in ?
import test_begohandler
File "/home/cfernand/bego/code/lib/test_begohandler.py", line 4, in ?
import test
File "/home/cfernand/bego/code/lib/test.py", line 6, in ?
import test_statemachine
File "/home/cfernand/bego/code/lib/test_statemachine.py", line 6, in ?
class statemachineTest(test.Base):
AttributeError: 'module' object has no attribute 'Base'
I have veryfied again and again the error, but I'm unable to find what it is.
I've also looked possible differences between test_begohandler.py and
test_statemachine.py that could lead to an error, but I haven't finded any
difference between both.
Thanks a lot for any hint that could help me solve this problem.
Enclosed are the other test_* files.
Guille
________________________________________________________
test_statemachine.py:
import unittest
import statemachine
import test
class statemachineTest(test.Base):
def testget_macsessions(self):
statemachine.get_macsessions(['%'])
def testget_apsessions(self):
statemachine.get_apsessions(['%'])
def testget_roamsessions(self):
statemachine.get_roamsessions(['%'])
def testget_macroamstats(self):
statemachine.get_macroamstats(['%'])
def testget_aproamstats(self):
statemachine.get_aproamstats(['%'])
def testget_maxmacapday(self):
statemachine.get_maxmacapday(['%'])
def testget_maxmacap(self):
statemachine.get_maxmacap(['%'])
if __name__ == '__main__':
unittest.main()
________________________________________________________
test_begohandler.py:
import unittest
import begohandler
import test
class begohandlerTest(test.Base):
def testget_apmaclist(self):
begohandler.get_apmaclist(['%'])
def testget_macaplist(self):
begohandler.get_macaplist(['%'])
def testget_aphistory(self):
begohandler.get_aphistory(['%'])
def testget_machistory(self):
begohandler.get_machistory(['%'])
def testget_macs(self):
begohandler.get_macs()
def testget_apnames(self):
begohandler.get_apnames()
def testget_msgstats(self):
begohandler.get_msgstats()
def testget_macmsgstats(self):
begohandler.get_macmsgstats(['%'])
def testget_apmsgstats(self):
begohandler.get_apmsgstats(['%'])
def testget_macsday(self):
begohandler.get_macsday()
def testget_daysmac(self):
begohandler.get_daysmac()
def testget_daysmacstat(self):
begohandler.get_daysmacstat()
def testget_apmacday(self):
begohandler.get_apmacday()
def testget_apdaymacs(self):
begohandler.get_apdaymacs()
if __name__ == '__main__':
unittest.main()
________________________________________________________
test_syslogparse.py:
import os
import sys
import unittest
import syslogparse
class syslogparseTest(unittest.TestCase):
# first and second added to names in order to force to execute
# first the parsefiledb and then the appendfiledb
def testfirstdo_parsefiledb(self):
try:
os.remove('test.db')
print 'test.db removed'
except:
pass
if not os.path.isfile('./test.txt') or not
os.path.isfile('./testappend.txt'):
print 'guille'
sys.exit(0)
syslogparse.run('test.txt','test.db')
def testseconddo_appendfiledb(self):
syslogparse.run('testappend.txt','test.db',True)
if __name__ == '__main__':
unittest.main()
________________________________________________________
More information about the Tutor
mailing list