Skip to content

Commit

Permalink
Refactor test to reduce code duplication.
Browse files Browse the repository at this point in the history
  • Loading branch information
strandgren committed Sep 18, 2023
1 parent a4c9c18 commit ba655df
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions satpy/tests/test_modifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,21 +159,24 @@ def test_imcompatible_areas(self, sunz_ds2, sunz_sza):
class TestSunZenithReducer:
"""Test case for the sun zenith reducer."""

def test_basic_default_provided(self, sunz_ds1, sunz_sza):
"""Test default settings with sza data available."""
@classmethod
def setup_class(cls):
"""Initialze SunZenithReducer classes that shall be tested."""
from satpy.modifiers.geometry import SunZenithReducer
comp = SunZenithReducer(name='sza_reduction_test_default', modifiers=tuple())
res = comp((sunz_ds1, sunz_sza), test_attr='test')
cls.default = SunZenithReducer(name='sza_reduction_test_default', modifiers=tuple())
cls.custom = SunZenithReducer(name='sza_reduction_test_custom', modifiers=tuple(),
correction_limit=70, max_sza=95, strength=3.0)

def test_default_settings(self, sunz_ds1, sunz_sza):
"""Test default settings with sza data available."""
res = self.default((sunz_ds1, sunz_sza), test_attr='test')
np.testing.assert_allclose(res.values,
np.array([[0.00242814, 0.00235669], [0.00245885, 0.00238707]]),
rtol=1e-5)

def test_basic_lims_provided(self, sunz_ds1, sunz_sza):
def test_custom_settings(self, sunz_ds1, sunz_sza):
"""Test custom settings with sza data available."""
from satpy.modifiers.geometry import SunZenithReducer
comp = SunZenithReducer(name='sza_reduction_test_custom', modifiers=tuple(),
correction_limit=70, max_sza=95, strength=3.0)
res = comp((sunz_ds1, sunz_sza), test_attr='test')
res = self.custom((sunz_ds1, sunz_sza), test_attr='test')
np.testing.assert_allclose(res.values,
np.array([[0.01041319, 0.01030033], [0.01046164, 0.01034834]]),
rtol=1e-5)
Expand Down

0 comments on commit ba655df

Please sign in to comment.