Skip to content

Commit

Permalink
Fix enhancement config loading when yaml file is empty (#387)
Browse files Browse the repository at this point in the history
* Fix enhancement config loading when yaml file is empty

* Force libkea installation due to conda issues

conda-forge/gdal-feedstock#220

* Use kealib instead of libkea and drop krb5 fix

* Remove kealib test because it didn't fix travis

* Try new conda hack to get a usable gdal environment
  • Loading branch information
djhoese authored Aug 14, 2018
1 parent fbe75c2 commit 4eeb646
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
7 changes: 4 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ env:
- PYTHON_VERSION=$TRAVIS_PYTHON_VERSION
- NUMPY_VERSION=stable
- MAIN_CMD='python setup.py'
# 'krb5' is added as a workaround for an issue with gdal
# see: https://github.com/conda-forge/gdal-feedstock/issues/205
- CONDA_DEPENDENCIES='xarray dask toolz Cython sphinx cartopy pillow matplotlib scipy pyyaml pyproj pyresample coveralls coverage codecov behave netcdf4 h5py h5netcdf gdal rasterio imageio pyhdf mock krb5 libtiff'
- CONDA_DEPENDENCIES='xarray dask toolz Cython sphinx cartopy pillow matplotlib scipy pyyaml pyproj pyresample coveralls coverage codecov behave netcdf4 h5py h5netcdf gdal rasterio imageio pyhdf mock libtiff'
- PIP_DEPENDENCIES='trollsift trollimage pyspectral pyorbital'
- SETUP_XVFB=False
- EVENT_TYPE='push pull_request'
Expand All @@ -28,6 +26,9 @@ matrix:
install:
- git clone --depth 1 git://github.com/astropy/ci-helpers.git
- source ci-helpers/travis/setup_conda.sh
# See https://github.com/conda/conda/issues/7626#issuecomment-412922028
- conda config --remove channels defaults
- conda install -y $CONDA_DEPENDENCIES
script:
- coverage run --source=satpy setup.py test
- coverage run -a --source=satpy -m behave satpy/tests/features --tags=-download
Expand Down
15 changes: 15 additions & 0 deletions satpy/tests/test_writers.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ class TestEnhancerUserConfigs(unittest.TestCase):
ENH_ENH_FN = os.path.join('enhancements', ENH_FN)
ENH_FN2 = 'test_sensor2.yaml'
ENH_ENH_FN2 = os.path.join('enhancements', ENH_FN2)
ENH_FN3 = 'test_empty.yaml'

TEST_CONFIGS = {
ENH_FN: """
Expand Down Expand Up @@ -175,6 +176,7 @@ class TestEnhancerUserConfigs(unittest.TestCase):
sensor_name: visir/test_sensor2
""",
ENH_FN3: """""",
}

@classmethod
Expand All @@ -196,6 +198,19 @@ def tearDownClass(cls):
elif os.path.isfile(fn):
os.remove(fn)

def test_enhance_empty_config(self):
"""Test Enhancer doesn't fail with empty enhancement file."""
from satpy.writers import Enhancer, get_enhanced_image
from xarray import DataArray
ds = DataArray(np.arange(1, 11.).reshape((2, 5)),
attrs=dict(sensor='test_empty', mode='L'),
dims=['y', 'x'])
e = Enhancer()
self.assertIsNotNone(e.enhancement_tree)
get_enhanced_image(ds, enhancer=e)
self.assertSetEqual(set(e.sensor_enhancement_configs),
{self.ENH_FN3})

def test_enhance_with_sensor_no_entry(self):
"""Test enhancing an image that has no configuration sections."""
from satpy.writers import Enhancer, get_enhanced_image
Expand Down
7 changes: 6 additions & 1 deletion satpy/writers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,12 @@ def add_config_to_tree(self, *decision_dict):
for config_file in decision_dict:
if os.path.isfile(config_file):
with open(config_file) as fd:
enhancement_section = yaml.load(fd).get(self.prefix, {})
enhancement_config = yaml.load(fd)
if enhancement_config is None:
# empty file
continue
enhancement_section = enhancement_config.get(
self.prefix, {})
if not enhancement_section:
LOG.debug("Config '{}' has no '{}' section or it is empty".format(config_file, self.prefix))
continue
Expand Down

0 comments on commit 4eeb646

Please sign in to comment.