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

root/sodar/branches/scintec-branch/sodar/tests/suite.py

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

Create maindata.Observation class.

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_path, data)
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 to 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_path, data,)
35
36 def setUpGoodMndData():
37     """
38     Get data from a known good Scintec .mnd file.
39     """
40    
41     mnd_dir = os.path.join('scintec','good',)
42     mnd_file = '091117.mnd'
43     mnd_path,mnd = setUpData(mnd_dir,mnd_file)
44     mnd_path,mnd_file = os.path.split(mnd_path)
45     profile = mnd.split('\n\n')[2].split('\n')
46     profile = [line.strip() for line in profile if line]
47     variables = profile[1].split()[1:]
48     observation = profile[2].split()
49     return (mnd_path,mnd_file,mnd,profile,variables,observation,)
50
51 def setUpGoodMnd(test):
52     """
53     Test set up for a good Scintec .mnd file.
54     """
55    
56     mnd_path,mnd_file,mnd,profile,variables,observation = setUpGoodMndData()
57     test.globs.update(good_mnd=mnd,
58                       good_name=mnd_file,
59                       good_path=mnd_path,
60                       good_profile=profile,
61                       good_variables=variables,
62                       good_observation=observation)
63
64 def test_suite():
65     """
66     Return unittest.TestSuite for setup.py test.
67     """
68    
69     suite = []
70     suite.append(doctest.DocTestSuite(module='sodar.scintec.maindata',
71                                       setUp=setUpGoodMnd,
72                                       optionflags=
73                                           doctest.NORMALIZE_WHITESPACE))
74     return unittest.TestSuite(suite)
Note: See TracBrowser for help on using the browser.