Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions continuous_integration/environment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ dependencies:
- trollsift
- numpy
- satpy>=0.32.0
- universal_pathlib
- rasterio
- pyorbital
- pip
Expand Down
102 changes: 49 additions & 53 deletions trollflow2/tests/test_dict_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,56 +146,56 @@
writer: geotiff
"""

input_mda = {'orig_platform_name': 'noaa15', 'orbit_number': 7993,
'start_time': dt.datetime(2019, 2, 17, 6, 0, 11, 100000), 'stfrac': 1,
'end_time': dt.datetime(2019, 2, 17, 6, 15, 10, 400000), 'etfrac': 4, 'status': 'OK',
'format': 'CF', 'data_processing_level': '2', 'orbit': 7993, 'module': 'ppsMakePhysiography',
'platform_name': 'NOAA-15', 'pps_version': 'v2018', 'file_was_already_processed': False,
'dataset': [{'uri': '/home/a001673/data/satellite/test_trollflow2/S_NWC_CMA_noaa15_07993_20190217T0600111Z_20190217T0615104Z.nc', # noqa
'uid': 'S_NWC_CMA_noaa15_07993_20190217T0600111Z_20190217T0615104Z.nc'},
{'uri': '/home/a001673/data/satellite/test_trollflow2/S_NWC_CTTH_noaa15_07993_20190217T0600111Z_20190217T0615104Z.nc', # noqa
'uid': 'S_NWC_CTTH_noaa15_07993_20190217T0600111Z_20190217T0615104Z.nc'},
{'uri': '/home/a001673/data/satellite/test_trollflow2/S_NWC_CT_noaa15_07993_20190217T0600111Z_20190217T0615104Z.nc', # noqa
'uid': 'S_NWC_CT_noaa15_07993_20190217T0600111Z_20190217T0615104Z.nc'}],
'sensor': ['avhrr']}


class TestProdList(unittest.TestCase):
input_mda = {"orig_platform_name": "noaa15", "orbit_number": 7993,
"start_time": dt.datetime(2019, 2, 17, 6, 0, 11, 100000), "stfrac": 1,
"end_time": dt.datetime(2019, 2, 17, 6, 15, 10, 400000), "etfrac": 4, "status": "OK",
"format": "CF", "data_processing_level": "2", "orbit": 7993, "module": "ppsMakePhysiography",
"platform_name": "NOAA-15", "pps_version": "v2018", "file_was_already_processed": False,
"dataset": [{"uri": "/home/a001673/data/satellite/test_trollflow2/S_NWC_CMA_noaa15_07993_20190217T0600111Z_20190217T0615104Z.nc", # noqa
"uid": "S_NWC_CMA_noaa15_07993_20190217T0600111Z_20190217T0615104Z.nc"},
{"uri": "/home/a001673/data/satellite/test_trollflow2/S_NWC_CTTH_noaa15_07993_20190217T0600111Z_20190217T0615104Z.nc", # noqa
"uid": "S_NWC_CTTH_noaa15_07993_20190217T0600111Z_20190217T0615104Z.nc"},
{"uri": "/home/a001673/data/satellite/test_trollflow2/S_NWC_CT_noaa15_07993_20190217T0600111Z_20190217T0615104Z.nc", # noqa
"uid": "S_NWC_CT_noaa15_07993_20190217T0600111Z_20190217T0615104Z.nc"}],
"sensor": ["avhrr"]}


class TestProdList:
"""Test case for the product list handling."""

def test_iter(self):
"""Test plist_iter."""
from trollflow2.dict_tools import plist_iter
prodlist = read_config(raw_string=yaml_test1)['product_list']
expected = [{'areaname': 'euron1_in_fname', 'area': 'euron1', 'productname': 'cloud_top_height_in_fname', 'product': 'cloud_top_height', # noqa
'min_coverage': 20.0, 'something': 'foo',
'output_dir': '/tmp/satdmz/pps/www/latest_2018/', 'format': 'png', 'writer': 'simple_image',
'fname_pattern': '{platform_name:s}_{start_time:%Y%m%d_%H%M}_{areaname:s}_ctth_static.{format}'},
{'areaname': 'euron1_in_fname', 'area': 'euron1', 'productname': 'cloud_top_height_in_fname', 'product': 'cloud_top_height', 'fill_value': 0, # noqa
'min_coverage': 20.0, 'something': 'foo',
'output_dir': '/tmp/satdmz/pps/www/latest_2018/', 'format': 'jpg', 'writer': 'simple_image',
'fname_pattern': '{platform_name:s}_{start_time:%Y%m%d_%H%M}_{areaname:s}_ctth_static.{format}'},
{'areaname': 'germ_in_fname', 'area': 'germ', 'productname': 'cloudtype_in_fname', 'product': 'cloudtype', # noqa
'output_dir': '/tmp/satdmz/pps/www/latest_2018/', 'min_coverage': 5.0, 'something': 'foo',
'fname_pattern': '{start_time:%Y%m%d_%H%M}_{areaname:s}_{productname}.{format}',
'format': 'png', 'writer': 'simple_image'},
{'areaname': 'omerc_bb', 'area': 'omerc_bb', 'productname': 'ct', 'product': 'ct', 'min_coverage': 5.0, 'something': 'foo', # noqa
'output_dir': '/tmp', 'format': 'nc', 'writer': 'cf'},
{'areaname': 'omerc_bb', 'area': 'omerc_bb', 'productname': 'cloud_top_height', 'product': 'cloud_top_height', # noqa
'output_dir': '/tmp', 'format': 'tif', 'min_coverage': 5.0, 'something': 'foo',
'writer': 'geotiff'}]
for i, exp in zip(plist_iter(prodlist), expected):
self.assertDictEqual(i[0], exp)

prodlist = read_config(raw_string=yaml_test2)['product_list']
for i, exp in zip(plist_iter(prodlist), expected):
self.assertDictEqual(i[0], exp)


class TestConfigValue(unittest.TestCase):
prodlist = read_config(raw_string=yaml_test1)["product_list"]
expected = [{"areaname": "euron1_in_fname", "area": "euron1", "productname": "cloud_top_height_in_fname", "product": "cloud_top_height", # noqa
"min_coverage": 20.0, "something": "foo",
"output_dir": "/tmp/satdmz/pps/www/latest_2018/", "format": "png", "writer": "simple_image",
"fname_pattern": "{platform_name:s}_{start_time:%Y%m%d_%H%M}_{areaname:s}_ctth_static.{format}"},

Check warning on line 173 in trollflow2/tests/test_dict_tools.py

View check run for this annotation

codefactor.io / CodeFactor

trollflow2/tests/test_dict_tools.py#L170-L173

Probable insecure usage of temp file/directory. (B108)
{"areaname": "euron1_in_fname", "area": "euron1", "productname": "cloud_top_height_in_fname", "product": "cloud_top_height", "fill_value": 0, # noqa
"min_coverage": 20.0, "something": "foo",
"output_dir": "/tmp/satdmz/pps/www/latest_2018/", "format": "jpg", "writer": "simple_image",
"fname_pattern": "{platform_name:s}_{start_time:%Y%m%d_%H%M}_{areaname:s}_ctth_static.{format}"},

Check warning on line 177 in trollflow2/tests/test_dict_tools.py

View check run for this annotation

codefactor.io / CodeFactor

trollflow2/tests/test_dict_tools.py#L174-L177

Probable insecure usage of temp file/directory. (B108)
{"areaname": "germ_in_fname", "area": "germ", "productname": "cloudtype_in_fname", "product": "cloudtype", # noqa
"output_dir": "/tmp/satdmz/pps/www/latest_2018/", "min_coverage": 5.0, "something": "foo",
"fname_pattern": "{start_time:%Y%m%d_%H%M}_{areaname:s}_{productname}.{format}",
"format": "png", "writer": "simple_image"},

Check warning on line 181 in trollflow2/tests/test_dict_tools.py

View check run for this annotation

codefactor.io / CodeFactor

trollflow2/tests/test_dict_tools.py#L178-L181

Probable insecure usage of temp file/directory. (B108)
{"areaname": "omerc_bb", "area": "omerc_bb", "productname": "ct", "product": "ct", "min_coverage": 5.0, "something": "foo", # noqa
"output_dir": "/tmp", "format": "nc", "writer": "cf"},

Check warning on line 183 in trollflow2/tests/test_dict_tools.py

View check run for this annotation

codefactor.io / CodeFactor

trollflow2/tests/test_dict_tools.py#L182-L183

Probable insecure usage of temp file/directory. (B108)
{"areaname": "omerc_bb", "area": "omerc_bb", "productname": "cloud_top_height", "product": "cloud_top_height", # noqa
"output_dir": "/tmp", "format": "tif", "min_coverage": 5.0, "something": "foo",
"writer": "geotiff"}]

Check warning on line 186 in trollflow2/tests/test_dict_tools.py

View check run for this annotation

codefactor.io / CodeFactor

trollflow2/tests/test_dict_tools.py#L184-L186

Probable insecure usage of temp file/directory. (B108)
for res, exp in zip(plist_iter(prodlist), expected):
assert res[0] == exp

prodlist = read_config(raw_string=yaml_test2)["product_list"]
for res, exp in zip(plist_iter(prodlist), expected):
assert res[0] == exp


class TestConfigValue:
"""Test case for get_config_value."""

def setUp(self):
def setup_method(self):
"""Set up the test case."""
self.prodlist = read_config(raw_string=yaml_test1)
self.path = "/product_list/areas/germ/products/cloudtype"
Expand All @@ -205,43 +205,39 @@
from trollflow2.dict_tools import get_config_value
expected = "/tmp/satdmz/pps/www/latest_2018/"
res = get_config_value(self.prodlist, self.path, "output_dir")
self.assertEqual(res, expected)
assert res == expected

def test_config_value_parent_level(self):
"""Test getting a config value from the parent level."""
from trollflow2.dict_tools import get_config_value
expected = "{start_time:%Y%m%d_%H%M}_{areaname:s}_{productname}.{format}"
res = get_config_value(self.prodlist, self.path, "fname_pattern")
self.assertEqual(res, expected)
assert res == expected

def test_config_value_common(self):
"""Test getting a common config value."""
from trollflow2.dict_tools import get_config_value
expected = "foo"
res = get_config_value(self.prodlist, self.path, "something")
self.assertEqual(res, expected)
assert res == expected

def test_config_value_missing(self):
"""Test getting a missing config value."""
from trollflow2.dict_tools import get_config_value
res = get_config_value(self.prodlist, self.path, "nothing")
self.assertIsNone(res)
assert res is None

def test_config_value_missing_own_default(self):
"""Test getting a missing value with default."""
from trollflow2.dict_tools import get_config_value
res = get_config_value(self.prodlist, self.path, "nothing",
default=42)
self.assertEqual(res, 42)
assert res == 42

def test_null_area(self):
"""Test area labeled as null."""
from trollflow2.dict_tools import get_config_value
path = "/product_list/areas/None/products/cloudtype"
expected = "/tmp/satdmz/pps/www/latest_2018/"
res = get_config_value(self.prodlist, path, "output_dir")
self.assertEqual(res, expected)


if __name__ == '__main__':
unittest.main()
assert res == expected
Loading
Loading