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

root/sodar/trunk/sodar/tests/suite.py

Revision 296 (checked in by cbc, 14 years ago)

Merge scintec-branch.

Line 
1 """
2 Test suite for the sodar package.
3 """
4
5 __author__ = 'Chris Calloway'
6 __email__ = 'cbc@chriscalloway.org'
7 __copyright__ = 'Copyright 2009 UNC-CH Department of Marine Science'
8 __license__ = 'GPL2'
9
10 import os
11 import unittest
12 import doctest
13
14 def setUpData(data_dir,data_file):
15     """
16     Get data from test file.
17    
18     setUpData(data_dir,data_file) -> (data,data_path,)
19    
20     Where:
21    
22         data_dir is a str representation of a relative path in tests/data,
23        
24         data_file is a str representation of a data file within data_dir,
25        
26         data_path is a str representation of the absolute path of data_file,
27        
28         data is a str representation of the contents of data_file.
29     """
30    
31     module_dir = os.path.abspath(os.path.dirname(__file__))
32     data_path = os.path.join(module_dir,'data',data_dir,data_file)
33     data = open(data_path).read()
34     return (data,data_path,)
35
36 def setUpGoodMndData():
37     """
38     Get data from a known good Scintec .mnd file.
39    
40     setUpGoodMndData() -> (mnd,path,profile,variables,observation,)
41
42     Where:
43    
44         mnd is a str representation of a known good .mnd daily sodar file,
45        
46         mnd_path is a str representation of the absolute path to the file,
47        
48         profile is a list of str objects representing a known good profile
49         from the file,
50        
51         variables is a list of str objects representing a list of known good
52         variables from the file,
53        
54         observation is a list of str objects representing a list of known good
55         observation values from the file in the same order as variables.
56     """
57    
58     mnd_dir = os.path.join('scintec','good',)
59     mnd_file = '091117.mnd'
60     mnd,mnd_path = setUpData(mnd_dir,mnd_file)
61     profile = mnd.split('\n\n')[2].split('\n')
62     profile = [line.strip() for line in profile if line]
63     variables = profile[1].split()[1:]
64     observation = profile[2].split()
65     return (mnd,mnd_path,profile,variables,observation,)
66
67 def setUpGoodMnd(test):
68     """
69     Doctest setUp() for a good Scintec .mnd file.
70     """
71    
72     mnd,mnd_path,profile,variables,observation = setUpGoodMndData()
73     test.globs.update(good_mnd=mnd,
74                       good_path=mnd_path,
75                       good_profile=profile,
76                       good_variables=variables,
77                       good_observation=observation)
78
79 def test_suite():
80     """
81     Return unittest.TestSuite for setup.py test.
82     """
83    
84     suite = []
85     suite.append(doctest.DocTestSuite(module='sodar.scintec.maindata',
86                                       setUp=setUpGoodMnd,
87                                       optionflags=
88                                           doctest.NORMALIZE_WHITESPACE))
89     return unittest.TestSuite(suite)
Note: See TracBrowser for help on using the browser.