NCCOOS Trac Projects: Top | Web | Platforms | Processing | Viz | Sprints | Sandbox | (Wind)

root/DPWP/tags/v1.0.0beta0/tests/testpd0split.py

Revision 40 (checked in by cbc, 17 years ago)

--

Line 
1 import unittest
2
3 class TestPd0Split(unittest.TestCase):
4
5     def setUp(self):
6         import os
7         self.dataPath = os.path.join(os.path.dirname(__file__),'data')
8         try:
9             import adcp.pd0 as pd0
10             self.pd0 = pd0
11         except:
12             # possible if executed as script
13             import sys,os
14             sys.path.append(os.path.split(os.path.dirname(__file__))[0])
15             import pd0
16             self.pd0 = pd0
17
18     def testSimpleSplit(self):
19         import os,StringIO
20         wavesFile = StringIO.StringIO()
21         currentsFile = StringIO.StringIO()
22         rawFile = open(os.path.join(self.dataPath,
23                                     'pd0Raw.in'),
24                        'rb')
25         try:
26             wavesTruthFile = open(os.path.join(self.dataPath,
27                                                'pd0Waves.out'),
28                                   'rb')
29             wavesTruthData = wavesTruthFile.read()
30             try:
31                 currentsTruthFile = open(os.path.join(self.dataPath,
32                                                       'pd0Currents.out'),
33                                          'rb')
34                 currentsTruthData = currentsTruthFile.read()
35                 try:
36                     self.pd0.split(rawFile, wavesFile, currentsFile)
37                 finally:
38                     currentsTruthFile.close()
39             finally:
40                 wavesTruthFile.close()
41         finally:
42             rawFile.close()
43         wavesData = wavesFile.getvalue()
44         currentsData = currentsFile.getvalue()
45         wavesFile.close()
46         currentsFile.close()
47         self.assertEqual(wavesData,
48                          wavesTruthData,
49                          'Waves data is not truthed in raw PD0 split')
50         self.assertEqual(currentsData,
51                          currentsTruthData,
52                          'Currents data is not truthed in raw PD0 split')
53
54 def test_suite():
55     suite = unittest.TestSuite()
56     suite.addTest(unittest.makeSuite(TestPd0Split))
57     return suite               
58
59 if __name__ == '__main__':
60     TestRunner = unittest.TextTestRunner
61     TestRunner().run(test_suite())
Note: See TracBrowser for help on using the browser.