From: <bao...@us...> - 2006-05-10 09:24:17
|
Revision: 103 Author: baoilleach Date: 2006-05-10 02:23:55 -0700 (Wed, 10 May 2006) ViewCVS: http://svn.sourceforge.net/cclib/?rev=103&view=rev Log Message: ----------- Separated out different tests into different tests files. Running testall.py will still run all of the tests, but it's also possible to just run tests for single-point calcs (testSP.py) or geoopt calcs (GeoOpt.py). Needs to be tidied up a bit more as there is some duplicated code in __main__. Modified Paths: -------------- trunk/test/testall.py Added Paths: ----------- trunk/test/testGeoOpt.py trunk/test/testSP.py Copied: trunk/test/testGeoOpt.py (from rev 101, trunk/test/testall.py) =================================================================== --- trunk/test/testGeoOpt.py (rev 0) +++ trunk/test/testGeoOpt.py 2006-05-10 09:23:55 UTC (rev 103) @@ -0,0 +1,85 @@ +import os, unittest +from cclib.parser import GAMESS,G03,ADF,Jaguar +from Numeric import array +from testall import getfile + +class GenericGeoOptTest(unittest.TestCase): + def testhomos(self): + """Is the index of the homo equal to 34?""" + self.assertEquals(self.data.homos,array([34])) + + def testnatom(self): + """Is the number of atoms equal to 20?""" + self.assertEquals(self.data.natom,20) + + def testnbasis(self): + """Is the number of basis set functions equal to 60?""" + self.assertEquals(self.data.nbasis,60) + + def testscfenergy(self): + """Is the SCF energy within 3eV(?) of -382.3?""" + self.assert_(self.data.scfenergies[-1]+382.3<3) + + def testnormalisesym(self): + """Did this subclasses overwrite normalisesym?""" + self.assertNotEquals(self.data.normalisesym("A"),"ERROR: This should be overwritten by this subclass") + + def testlengthmoenergies(self): + """Is the number of evalues equal to 60?""" + self.assertEquals(60,len(self.data.moenergies[0])) + + def testsymlabels(self): + """Are all the symmetry labels either Ag/u or Bg/u?""" + sumwronglabels = sum([x not in ['Ag','Bu','Au','Bg'] for x in self.data.mosyms[0]]) + self.assertEquals(sumwronglabels,0) + + def testscfvaluetype(self): + """Do the scf values have the right type?""" + self.assert_(type(self.data.scfvalues[0])==type(array([])) and type(self.data.scfvalues)==type([])) + + def testscfvaluedim(self): + """Do the scf values have the right dimensions?""" + self.assert_(len(self.data.scfvalues)==len(self.data.geovalues) and len(self.data.scfvalues[0])==len(self.data.scftargets)) + +class GaussianGeoOptTest(GenericGeoOptTest): + def setUp(self): + self.data = getfile(G03,"basicGaussian03","dvb_gopt.out") + +class GamessUSGeoOptTest(GenericGeoOptTest): + def setUp(self): + self.data = getfile(GAMESS,"basicGAMESS-US","dvb_gopt_a.out") + +class PCGamessGeoOptTest(GenericGeoOptTest): + def setUp(self): + self.data = getfile(GAMESS,"basicPCGAMESS","dvb_gopt_a.out") + +class ADFGeoOptTest(GenericGeoOptTest): + def setUp(self): + self.data = getfile(ADF,"basicADF2004.01","dvb_gopt.adfout") + + def testscfvaluedim(self): + """Do the scf values have the right dimensions? + ADF calculations one more SCF cycle after the geometry is converged""" + self.assert_(len(self.data.scfvalues)==len(self.data.geovalues)+1 and len(self.data.scfvalues[0])==len(self.data.scftargets)) + +class JaguarGeoOptTest(GenericGeoOptTest): + def setUp(self): + self.data = getfile(Jaguar,"basicJaguar","eg01","dvb_gopt.out") + +names = [ "Gaussian", "PCGamess", "GAMESS", "ADF", "Jaguar" ] +tests = [ GaussianGeoOptTest, PCGamessGeoOptTest, + GamessUSGeoOptTest, ADFGeoOptTest, + JaguarGeoOptTest ] + +if __name__=="__main__": + total = errors = failures = 0 + for name,test in zip(names,tests): + print "\n**** Testing %s Geo Opt ****" % name + myunittest = unittest.makeSuite(test) + a = unittest.TextTestRunner(verbosity=2).run(myunittest) + total += a.testsRun + errors += len(a.errors) + failures += len(a.failures) + + print "\n\n********* SUMMARY OF Geo Opt **************" + print "TOTAL: %d\tPASSED: %d\tFAILED: %d\tERRORS: %d" % (total,total-(errors+failures),failures,errors) Copied: trunk/test/testSP.py (from rev 101, trunk/test/testall.py) =================================================================== --- trunk/test/testSP.py (rev 0) +++ trunk/test/testSP.py 2006-05-10 09:23:55 UTC (rev 103) @@ -0,0 +1,48 @@ +import os, unittest +from cclib.parser import GAMESS,G03,ADF,Jaguar +from Numeric import array +from testall import getfile + +class GenericSPTest(unittest.TestCase): + """Restricted single point calculations with MO coeffs and overlap info.""" + def testdimaooverlaps(self): + """Are the dims of the overlap matrix consistent with nbasis?""" + self.assertEquals(self.data.aooverlaps.shape,(self.data.nbasis,self.data.nbasis)) + + def testdimmocoeffs(self): + """Are the dimensions of mocoeffs equal to 1 x nindep x nbasis?""" + self.assertEquals(self.data.mocoeffs.shape,(1,self.data.nindep,self.data.nbasis)) + +class GaussianSPTest(GenericSPTest): + def setUp(self): + self.data = getfile(G03,"basicGaussian03","dvb_sp.out") + +class GamessUSSPTest(GenericSPTest): + def setUp(self): + self.data = getfile(GAMESS,"basicGAMESS-US","dvb_sp.out") + +class PCGamessSPTest(GenericSPTest): + def setUp(self): + self.data = getfile(GAMESS,"basicPCGAMESS","dvb_sp.out") + +class ADFSPTest(GenericSPTest): + def setUp(self): + self.data = getfile(ADF,"basicADF2004.01","dvb_sp_b.adfout") + +names = [ "Gaussian", "PCGamess", "GAMESS", "ADF", "Jaguar" ] +tests = [ GaussianSPTest, PCGamessSPTest, + GamessUSSPTest, ADFSPTest ] + +if __name__=="__main__": + total = errors = failures = 0 + + for name,test in zip(names,tests): + print "\n**** Testing %s SP ****" % name + myunittest = unittest.makeSuite(test) + a = unittest.TextTestRunner(verbosity=2).run(myunittest) + total += a.testsRun + errors += len(a.errors) + failures += len(a.failures) + + print "\n\n********* SUMMARY OF SP **************" + print "TOTAL: %d\tPASSED: %d\tFAILED: %d\tERRORS: %d" % (total,total-(errors+failures),failures,errors) Modified: trunk/test/testall.py =================================================================== --- trunk/test/testall.py 2006-05-10 01:51:02 UTC (rev 102) +++ trunk/test/testall.py 2006-05-10 09:23:55 UTC (rev 103) @@ -1,96 +1,7 @@ -import os, unittest -from cclib.parser import GAMESS,G03,ADF,Jaguar -from Numeric import array +import unittest +import os +from cclib.parser import G03,GAMESS,ADF,Jaguar -class GenericSPTest(unittest.TestCase): - """Restricted single point calculations with MO coeffs and overlap info.""" - def testdimaooverlaps(self): - """Are the dims of the overlap matrix consistent with nbasis?""" - self.assertEquals(self.data.aooverlaps.shape,(self.data.nbasis,self.data.nbasis)) - - def testdimmocoeffs(self): - """Are the dimensions of mocoeffs equal to 1 x nindep x nbasis?""" - self.assertEquals(self.data.mocoeffs.shape,(1,self.data.nindep,self.data.nbasis)) - -class GaussianSPTest(GenericSPTest): - def setUp(self): - self.data = getfile(G03,"basicGaussian03","dvb_sp.out") - -class GamessUSSPTest(GenericSPTest): - def setUp(self): - self.data = getfile(GAMESS,"basicGAMESS-US","dvb_sp.out") - -class PCGamessSPTest(GenericSPTest): - def setUp(self): - self.data = getfile(GAMESS,"basicPCGAMESS","dvb_sp.out") - -class ADFSPTest(GenericSPTest): - def setUp(self): - self.data = getfile(ADF,"basicADF2004.01","dvb_sp_b.adfout") - -class GenericGeoOptTest(unittest.TestCase): - def testhomos(self): - """Is the index of the homo equal to 34?""" - self.assertEquals(self.data.homos,array([34])) - - def testnatom(self): - """Is the number of atoms equal to 20?""" - self.assertEquals(self.data.natom,20) - - def testnbasis(self): - """Is the number of basis set functions equal to 60?""" - self.assertEquals(self.data.nbasis,60) - - def testscfenergy(self): - """Is the SCF energy within 3eV(?) of -382.3?""" - self.assert_(self.data.scfenergies[-1]+382.3<3) - - def testnormalisesym(self): - """Did this subclasses overwrite normalisesym?""" - self.assertNotEquals(self.data.normalisesym("A"),"ERROR: This should be overwritten by this subclass") - - def testlengthmoenergies(self): - """Is the number of evalues equal to 60?""" - self.assertEquals(60,len(self.data.moenergies[0])) - - def testsymlabels(self): - """Are all the symmetry labels either Ag/u or Bg/u?""" - sumwronglabels = sum([x not in ['Ag','Bu','Au','Bg'] for x in self.data.mosyms[0]]) - self.assertEquals(sumwronglabels,0) - - def testscfvaluetype(self): - """Do the scf values have the right type?""" - self.assert_(type(self.data.scfvalues[0])==type(array([])) and type(self.data.scfvalues)==type([])) - - def testscfvaluedim(self): - """Do the scf values have the right dimensions?""" - self.assert_(len(self.data.scfvalues)==len(self.data.geovalues) and len(self.data.scfvalues[0])==len(self.data.scftargets)) - -class GaussianGeoOptTest(GenericGeoOptTest): - def setUp(self): - self.data = getfile(G03,"basicGaussian03","dvb_gopt.out") - -class GamessUSGeoOptTest(GenericGeoOptTest): - def setUp(self): - self.data = getfile(GAMESS,"basicGAMESS-US","dvb_gopt_a.out") - -class PCGamessGeoOptTest(GenericGeoOptTest): - def setUp(self): - self.data = getfile(GAMESS,"basicPCGAMESS","dvb_gopt_a.out") - -class ADFGeoOptTest(GenericGeoOptTest): - def setUp(self): - self.data = getfile(ADF,"basicADF2004.01","dvb_gopt.adfout") - - def testscfvaluedim(self): - """Do the scf values have the right dimensions? - ADF calculations one more SCF cycle after the geometry is converged""" - self.assert_(len(self.data.scfvalues)==len(self.data.geovalues)+1 and len(self.data.scfvalues[0])==len(self.data.scftargets)) - -class JaguarGeoOptTest(GenericGeoOptTest): - def setUp(self): - self.data = getfile(Jaguar,"basicJaguar","eg01","dvb_gopt.out") - def getfile(parser,*location): """Returns a parsed logfile.""" if parser.__name__ in ['GAMESS','ADF','Jaguar']: @@ -116,32 +27,31 @@ print "LUMO", " ".join(["%+2.4f" % x.moenergies[0,x.homos[0]+1] for x in logfiles]) print "H-L ", " ".join(["%2.4f" % (x.moenergies[0,x.homos[0]+1]-x.moenergies[0,x.homos[0]],) for x in logfiles]) +def importName(modulename, name): + """Import from a module whose name is determined at run-time. + + Taken from Python Cookbook 2nd ed O'Reilly Recipe 16.3 + """ + try: + module = __import__(modulename, globals(), locals(), [name]) + except ImportError: + return None + return getattr(module, name) - + if __name__=="__main__": - names = [ "Gaussian", "PCGamess", "GAMESS", "ADF", "Jaguar" ] - tests = [ GaussianGeoOptTest, PCGamessGeoOptTest, - GamessUSGeoOptTest, ADFGeoOptTest, - JaguarGeoOptTest ] total = errors = failures = 0 - for name,test in zip(names,tests): - print "\n**** Testing %s Geo Opt ****" % name - myunittest = unittest.makeSuite(test) - a = unittest.TextTestRunner(verbosity=2).run(myunittest) - total += a.testsRun - errors += len(a.errors) - failures += len(a.failures) + for module in [ "testGeoOpt", "testSP" ]: + names = importName(module, "names") # i.e. from testGeoOpt import names + tests = importName(module, "tests") # i.e. from testGeoOpt import tests + for name,test in zip(names,tests): + print "\n**** Testing %s (%s) ****" % (name, module) + myunittest = unittest.makeSuite(test) + a = unittest.TextTestRunner(verbosity=2).run(myunittest) + total += a.testsRun + errors += len(a.errors) + failures += len(a.failures) - tests = [ GaussianSPTest, PCGamessSPTest, - GamessUSSPTest, ADFSPTest ] - for name,test in zip(names,tests): - print "\n**** Testing %s SP ****" % name - myunittest = unittest.makeSuite(test) - a = unittest.TextTestRunner(verbosity=2).run(myunittest) - total += a.testsRun - errors += len(a.errors) - failures += len(a.failures) - print "\n\n********* SUMMARY OF EVERYTHING **************" print "TOTAL: %d\tPASSED: %d\tFAILED: %d\tERRORS: %d" % (total,total-(errors+failures),failures,errors) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |