Skip to content
Merged
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
16 changes: 15 additions & 1 deletion mapshader/tests/test_tif_to_netcdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,18 @@ def test_valid_conversion(tmpdir):

shutil.copy2(path.join(FIXTURES_DIR, input_filename), input_filepath)
runner.invoke(tif_to_netcdf, [input_filepath], standalone_mode=False)
assert filecmp.cmp(output_filepath, expected_output_filepath)

# xarray.to_netcdf can produce NETCDF3 or 4 files depending on availability of scipy.io and
# python netCDF4 libraries. Need to check both possibilities.
if not filecmp.cmp(output_filepath, expected_output_filepath):
# Files differ, but may just be different netcdf version so check contents.
from numpy.testing import assert_array_almost_equal
import xarray as xr

a = xr.open_dataset(output_filepath)
b = xr.open_dataset(expected_output_filepath)
assert a.attrs == b.attrs
assert a.spatial_ref == b.spatial_ref
assert_array_almost_equal(a.coords["x"], b.coords["x"])
assert_array_almost_equal(a.coords["y"], b.coords["y"])
assert_array_almost_equal(a.data, b.data)