""" 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_path, data) 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 to 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_path, data,) def setUpGoodMndData(): """ Get data from a known good Scintec .mnd file. """ mnd_dir = os.path.join('scintec','good',) mnd_file = '091117.mnd' mnd_path,mnd = setUpData(mnd_dir,mnd_file) mnd_path,mnd_file = os.path.split(mnd_path) 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_path,mnd_file,mnd,profile,variables,observation,) def setUpGoodMnd(test): """ Test set up for a good Scintec .mnd file. """ mnd_path,mnd_file,mnd,profile,variables,observation = setUpGoodMndData() test.globs.update(good_mnd=mnd, good_name=mnd_file, 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)