1
|
|
|
#!/usr/bin/env python |
2
|
|
|
# -*- coding: utf-8 -*- |
3
|
|
|
|
4
|
|
|
# Copyright (c) 2017 Adam.Dybbroe |
5
|
|
|
|
6
|
|
|
# Author(s): |
7
|
|
|
|
8
|
|
|
# Adam.Dybbroe <[email protected]> |
9
|
|
|
|
10
|
|
|
# This program is free software: you can redistribute it and/or modify |
11
|
|
|
# it under the terms of the GNU General Public License as published by |
12
|
|
|
# the Free Software Foundation, either version 3 of the License, or |
13
|
|
|
# (at your option) any later version. |
14
|
|
|
|
15
|
|
|
# This program is distributed in the hope that it will be useful, |
16
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
17
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18
|
|
|
# GNU General Public License for more details. |
19
|
|
|
|
20
|
|
|
# You should have received a copy of the GNU General Public License |
21
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
22
|
|
|
|
23
|
|
|
"""Unit testing the generic rsr hdf5 reader |
24
|
|
|
""" |
25
|
|
|
import sys |
26
|
|
|
from pyspectral.rsr_reader import RelativeSpectralResponse |
27
|
|
|
from mock import patch |
28
|
|
|
if sys.version_info < (2, 7): |
29
|
|
|
import unittest2 as unittest |
30
|
|
|
else: |
31
|
|
|
import unittest |
32
|
|
|
|
33
|
|
|
|
34
|
|
|
TEST_CONFIG = {} |
35
|
|
|
TEST_CONFIG['rsr_dir'] = '/test/path/to/rsr/data' |
36
|
|
|
|
37
|
|
|
|
38
|
|
|
class TestRsrReader(unittest.TestCase): |
39
|
|
|
|
40
|
|
|
"""Class for testing pyspectral.rsr_reader""" |
41
|
|
|
|
42
|
|
|
def setUp(self): |
43
|
|
|
"""Setup the test""" |
44
|
|
|
pass |
45
|
|
|
|
46
|
|
|
@patch('os.path.exists') |
47
|
|
|
@patch('os.path.isfile') |
48
|
|
|
@patch('pyspectral.rsr_reader.RelativeSpectralResponse.load') |
49
|
|
|
@patch('pyspectral.rsr_reader.download_rsr') |
50
|
|
|
def test_rsr_reponse(self, download_rsr, load, isfile, exists): |
51
|
|
|
"""Test the relative_""" |
52
|
|
|
load.return_code = None |
53
|
|
|
download_rsr.return_code = None |
54
|
|
|
isfile.return_code = True |
55
|
|
|
exists.return_code = True |
56
|
|
|
|
57
|
|
|
with patch('pyspectral.rsr_reader.get_config', return_value=TEST_CONFIG): |
58
|
|
|
test_rsr = RelativeSpectralResponse('GOES-16', 'abi') |
59
|
|
|
|
60
|
|
|
self.assertEqual(test_rsr.platform_name, 'GOES-16') |
61
|
|
|
self.assertEqual(test_rsr.instrument, 'abi') |
62
|
|
|
self.assertEqual( |
63
|
|
|
test_rsr.filename, '/test/path/to/rsr/data/rsr_abi_GOES-16.h5') |
64
|
|
|
|
65
|
|
|
with patch('pyspectral.rsr_reader.get_config', return_value=TEST_CONFIG): |
66
|
|
|
test_rsr = RelativeSpectralResponse( |
67
|
|
|
filename='/test/path/to/rsr/data/rsr_abi_GOES-16.h5') |
68
|
|
|
|
69
|
|
|
self.assertEqual( |
70
|
|
|
test_rsr.filename, '/test/path/to/rsr/data/rsr_abi_GOES-16.h5') |
71
|
|
|
|
72
|
|
|
def tearDown(self): |
73
|
|
|
"""Clean up""" |
74
|
|
|
pass |
75
|
|
|
|
76
|
|
|
|
77
|
|
|
def suite(): |
78
|
|
|
"""The test suite for test_rsr_reader. |
79
|
|
|
""" |
80
|
|
|
loader = unittest.TestLoader() |
81
|
|
|
mysuite = unittest.TestSuite() |
82
|
|
|
mysuite.addTest(loader.loadTestsFromTestCase(TestRsrReader)) |
83
|
|
|
|
84
|
|
|
return mysuite |
85
|
|
|
|