Skip to content

Commit

Permalink
Refactor tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lahtinep committed Jun 20, 2024
1 parent 7c536c2 commit b6361a1
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions satpy/tests/reader_tests/test_fci_l1c_nc.py
Original file line number Diff line number Diff line change
Expand Up @@ -927,26 +927,32 @@ def _mock_np2str(val):
return val


def test_reusing_shared_segment_info():
"""Test that certain data are reused after the first segment has been handled.
This is the case where something has been already handled and stored to filetype_info["shared_info"] dict.
"""
def parse_fdhsi_filename_info(filename):
"""Parse filename info from the filename."""
from trollsift import parse

filename = ("W_XX-EUMETSAT-Darmstadt,IMG+SAT,MTI1+FCI-1C-RRAD-FDHSI-FD--CHK-BODY--DIS-NC4E_C_"
"EUMT_20231102061023_IDPFI_OPE_20231102060835_20231102060908_N_JLS_C_0037_0037.nc")
fmt = ("{pflag}_{location_indicator},{data_designator},MTI{spacecraft_id:1d}+{data_source}-1C-RRAD-FDHSI-"
"{coverage}-{subsetting}-{component1}-BODY-{component3}-{purpose}-{format}_{oflag}_{originator}_"
"{processing_time:%Y%m%d%H%M%S}_{facility_or_tool}_{environment}_{start_time:%Y%m%d%H%M%S}_{end_time:%Y%m%d%H%M%S}_"
"{processing_mode}_{special_compression}_{disposition_mode}_{repeat_cycle_in_day:>04d}_{count_in_repeat_cycle:>04d}.nc")
filename_info = parse(fmt, filename)
return filename_info


def test_reusing_shared_segment_info():
"""Test that certain data are reused after the first segment has been handled.
This is the case where something has been already handled and stored to filetype_info["shared_info"] dict.
"""
filename = TEST_FILENAMES["fdhsi"][0]
filename_info = parse_fdhsi_filename_info(filename)
filetype_info = {
"shared_info": {
"attr/platform": "mock-satellite"
},
"required_netcdf_variables": ["attr/platform"]
}

with mock.patch("satpy.readers.netcdf_utils.NetCDF4FsspecFileHandler._get_file_handle"):
with mock.patch("satpy.readers.netcdf_utils.np2str", _mock_np2str):
fh_ = FCIL1cNCFileHandler(filename, filename_info, filetype_info)
Expand All @@ -955,16 +961,10 @@ def test_reusing_shared_segment_info():

def test_store_shared_segment_info():
"""Test that certain data are collected to filetype_info["shared_info"] from the first segment."""
from trollsift import parse

filename = ("W_XX-EUMETSAT-Darmstadt,IMG+SAT,MTI1+FCI-1C-RRAD-FDHSI-FD--CHK-BODY--DIS-NC4E_C_"
"EUMT_20231102061023_IDPFI_OPE_20231102060835_20231102060908_N_JLS_C_0037_0037.nc")
fmt = ("{pflag}_{location_indicator},{data_designator},MTI{spacecraft_id:1d}+{data_source}-1C-RRAD-FDHSI-"
"{coverage}-{subsetting}-{component1}-BODY-{component3}-{purpose}-{format}_{oflag}_{originator}_"
"{processing_time:%Y%m%d%H%M%S}_{facility_or_tool}_{environment}_{start_time:%Y%m%d%H%M%S}_{end_time:%Y%m%d%H%M%S}_"
"{processing_mode}_{special_compression}_{disposition_mode}_{repeat_cycle_in_day:>04d}_{count_in_repeat_cycle:>04d}.nc")
filename_info = parse(fmt, filename)
filename = TEST_FILENAMES["fdhsi"][0]
filename_info = parse_fdhsi_filename_info(filename)
filetype_info = {"required_netcdf_variables": ["attr/platform"]}

with mock.patch("satpy.readers.netcdf_utils.NetCDF4FsspecFileHandler._get_file_handle") as get_file_handle:
get_file_handle.return_value.platform = "mock-satellite"
with mock.patch("satpy.readers.netcdf_utils.np2str", _mock_np2str):
Expand Down

0 comments on commit b6361a1

Please sign in to comment.