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 |
return setUpData(mnd_dir,mnd_file) |
---|
44 |
|
---|
45 |
def setUpGoodMnd(test): |
---|
46 |
""" |
---|
47 |
Test set up for a good Scintec .mnd file. |
---|
48 |
""" |
---|
49 |
|
---|
50 |
mnd_path,mnd = setUpGoodMndData() |
---|
51 |
mnd_path,mnd_file = os.path.split(mnd_path) |
---|
52 |
test.globs.update(good_mnd=mnd, |
---|
53 |
good_name=mnd_file, |
---|
54 |
good_path=mnd_path) |
---|
55 |
|
---|
56 |
def test_suite(): |
---|
57 |
""" |
---|
58 |
Return unittest.TestSuite for setup.py test. |
---|
59 |
""" |
---|
60 |
|
---|
61 |
suite = [] |
---|
62 |
suite.append(doctest.DocTestSuite(module='sodar.scintec.maindata', |
---|
63 |
setUp=setUpGoodMnd)) |
---|
64 |
return unittest.TestSuite(suite) |
---|