Completed
Pull Request — develop (#12)
by Adam
30s
created

TestRsrReader.test_rsr_reponse()   B

Complexity

Conditions 3

Size

Total Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
c 1
b 0
f 0
dl 0
loc 25
rs 8.8571
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
if sys.version_info < (2, 7):
27
    import unittest2 as unittest
28
else:
29
    import unittest
30
31
from pyspectral.rsr_reader import RelativeSpectralResponse
32
33
import mock
34
from mock import patch
35
36
TEST_CONFIG = {}
37
TEST_CONFIG['rsr_dir'] = '/test/path/to/rsr/data'
38
39
40
class TestRsrReader(unittest.TestCase):
41
42
    """Class for testing pyspectral.rsr_reader"""
43
44
    def setUp(self):
45
        """Setup the test"""
46
        pass
47
48
    @mock.patch('os.path.exists')
49
    @mock.patch('os.path.isfile')
50
    @mock.patch('pyspectral.rsr_reader.RelativeSpectralResponse.load')
51
    @mock.patch('pyspectral.rsr_reader.download_rsr')
52
    def test_rsr_reponse(self, download_rsr, load, isfile, exists):
53
        """Test the relative_"""
54
        load.return_code = None
55
        download_rsr.return_code = None
56
        isfile.return_code = True
57
        exists.return_code = True
58
59
        with patch('pyspectral.rsr_reader.get_config', return_value=TEST_CONFIG):
60
            test_rsr = RelativeSpectralResponse('GOES-16', 'abi')
61
62
        self.assertEqual(test_rsr.platform_name, 'GOES-16')
63
        self.assertEqual(test_rsr.instrument, 'abi')
64
        self.assertEqual(
65
            test_rsr.filename, '/test/path/to/rsr/data/rsr_abi_GOES-16.h5')
66
67
        with patch('pyspectral.rsr_reader.get_config', return_value=TEST_CONFIG):
68
            test_rsr = RelativeSpectralResponse(
69
                filename='/test/path/to/rsr/data/rsr_abi_GOES-16.h5')
70
71
        self.assertEqual(
72
            test_rsr.filename, '/test/path/to/rsr/data/rsr_abi_GOES-16.h5')
73
74
    def tearDown(self):
75
        """Clean up"""
76
        pass
77
78
79
def suite():
80
    """The test suite for test_rsr_reader.
81
    """
82
    loader = unittest.TestLoader()
83
    mysuite = unittest.TestSuite()
84
    mysuite.addTest(loader.loadTestsFromTestCase(TestRsrReader))
85
86
    return mysuite
87