""" Test suite for the sodar package. """ __author__ = 'Chris Calloway' __email__ = 'cbc@chriscalloway.org' __copyright__ = 'Copyright 2009 UNC-CH Department of Marine Science' __license__ = 'GPL2' import os import unittest import doctest def setUpData(data_dir,data_file): """ Get data from test file. setUpData(data_dir,data_file) -> (data,data_path,) Where: data_dir is a str representation of a relative path in tests/data, data_file is a str representation of a data file within data_dir, data_path is a str representation of the absolute path of data_file, data is a str representation of the contents of data_file. """ module_dir = os.path.abspath(os.path.dirname(__file__)) data_path = os.path.join(module_dir,'data',data_dir,data_file) data = open(data_path).read() return (data,data_path,) def setUpGoodMndData(): """ Get data from a known good Scintec .mnd file. setUpGoodMndData() -> (mnd,path,profile,variables,observation,) Where: mnd is a str representation of a known good .mnd daily sodar file, mnd_path is a str representation of the absolute path to the file, profile is a list of str objects representing a known good profile from the file, variables is a list of str objects representing a list of known good variables from the file, observation is a list of str objects representing a list of known good observation values from the file in the same order as variables. """ mnd_dir = os.path.join('scintec','good',) mnd_file = '091117.mnd' mnd,mnd_path = setUpData(mnd_dir,mnd_file) profile = mnd.split('\n\n')[2].split('\n') profile = [line.strip() for line in profile if line] variables = profile[1].split()[1:] observation = profile[2].split() return (mnd,mnd_path,profile,variables,observation,) def setUpGoodMnd(test): """ Doctest setUp() for a good Scintec .mnd file. """ mnd,mnd_path,profile,variables,observation = setUpGoodMndData() test.globs.update(good_mnd=mnd, good_path=mnd_path, good_profile=profile, good_variables=variables, good_observation=observation) def test_suite(): """ Return unittest.TestSuite for setup.py test. """ suite = [] suite.append(doctest.DocTestSuite(module='sodar.scintec.maindata', setUp=setUpGoodMnd, optionflags= doctest.NORMALIZE_WHITESPACE)) return unittest.TestSuite(suite)