forked from pytroll/satpy
/
test_slstr_l2.py
73 lines (64 loc) · 2.85 KB
/
test_slstr_l2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (c) 2018 Satpy developers
#
# This file is part of satpy.
#
# satpy is free software: you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation, either version 3 of the License, or (at your option) any later
# version.
#
# satpy is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# satpy. If not, see <http://www.gnu.org/licenses/>.
"""Module for testing the satpy.readers.slstr_l2 module."""
import unittest
from unittest import mock
from unittest.mock import MagicMock
import xarray as xr
from satpy.readers.slstr_l2 import SLSTRL2FileHandler
class TestSLSTRL2Reader(unittest.TestCase):
"""Test Sentinel-3 SST L2 reader."""
@mock.patch('xarray.open_dataset')
def test_instantiate(self, mocked_dataset):
"""Test initialization of file handlers."""
filename_info = {}
tmp = MagicMock(start_time='20191120T125002Z', stop_time='20191120T125002Z')
tmp.rename.return_value = tmp
xr.open_dataset.return_value = tmp
SLSTRL2FileHandler('somedir/somefile.nc', filename_info, None)
mocked_dataset.assert_called()
mocked_dataset.reset_mock()
@mock.patch('xarray.open_dataset')
def test_get_dataset(self, mocked_dataset):
"""Test retrieval of datasets."""
filename_info = {}
tmp = MagicMock(start_time='20191120T125002Z', stop_time='20191120T125002Z')
tmp.rename.return_value = tmp
xr.open_dataset.return_value = tmp
test = SLSTRL2FileHandler('somedir/somefile.nc', filename_info, None)
test.nc = {'longitude': xr.Dataset(),
'latitude': xr.Dataset(),
'sea_surface_temperature': xr.Dataset(),
'sea_ice_fraction': xr.Dataset(),
}
test.get_dataset('longitude', {'standard_name': 'longitude'})
test.get_dataset('latitude', {'standard_name': 'latitude'})
test.get_dataset('sea_surface_temperature', {'standard_name': 'sea_surface_temperature'})
test.get_dataset('sea_ice_fraction', {'standard_name': 'sea_ice_fraction'})
with self.assertRaises(KeyError):
test.get_dataset('erroneous dataset', {'standard_name': 'erroneous dataset'})
mocked_dataset.assert_called()
mocked_dataset.reset_mock()
def suite():
"""Test suite for test_slstr_l2."""
loader = unittest.TestLoader()
mysuite = unittest.TestSuite()
mysuite.addTest(loader.loadTestsFromTestCase(TestSLSTRL2Reader))
return mysuite
if __name__ == '__main__':
unittest.main()