import unittest class TestPd0Split(unittest.TestCase): def setUp(self): import os self.dataPath = os.path.join(os.path.dirname(__file__),'data') try: import adcp.pd0 as pd0 self.pd0 = pd0 except: # possible if executed as script import sys,os sys.path.append(os.path.split(os.path.dirname(__file__))[0]) import pd0 self.pd0 = pd0 def testSimpleSplit(self): import os,StringIO wavesFile = StringIO.StringIO() currentsFile = StringIO.StringIO() rawFile = open(os.path.join(self.dataPath, 'pd0Raw.in'), 'rb') try: wavesTruthFile = open(os.path.join(self.dataPath, 'pd0Waves.out'), 'rb') wavesTruthData = wavesTruthFile.read() try: currentsTruthFile = open(os.path.join(self.dataPath, 'pd0Currents.out'), 'rb') currentsTruthData = currentsTruthFile.read() try: self.pd0.split(rawFile, wavesFile, currentsFile) finally: currentsTruthFile.close() finally: wavesTruthFile.close() finally: rawFile.close() wavesData = wavesFile.getvalue() currentsData = currentsFile.getvalue() wavesFile.close() currentsFile.close() self.assertEqual(wavesData, wavesTruthData, 'Waves data is not truthed in raw PD0 split') self.assertEqual(currentsData, currentsTruthData, 'Currents data is not truthed in raw PD0 split') def test_suite(): suite = unittest.TestSuite() suite.addTest(unittest.makeSuite(TestPd0Split)) return suite if __name__ == '__main__': TestRunner = unittest.TextTestRunner TestRunner().run(test_suite())