diff --git a/fre/app/remap_pp_components/tests/test_remap_pp_components.py b/fre/app/remap_pp_components/tests/test_remap_pp_components.py index bd83a11ad..d673f8a98 100644 --- a/fre/app/remap_pp_components/tests/test_remap_pp_components.py +++ b/fre/app/remap_pp_components/tests/test_remap_pp_components.py @@ -4,6 +4,7 @@ import logging from pathlib import Path import pytest +import xarray as xr import fre.app.remap_pp_components.remap_pp_components as rmp # Test paths @@ -332,7 +333,7 @@ def test_remap_offline_diagnostics(monkeypatch): assert Path(f"{os.getenv('outputDir')}/atmos_scalar/{STATIC_FREQ}/{STATIC_CHUNK}/empty.nc").exists() ## COMPARE INPUT AND OUTPUT FILES ## -def test_nccmp_ncgen_remap(): +def test_compare_ncgen_remap(): """ This test compares the results of ncgen and rewrite_remap, making sure that the remapped files are identical. @@ -340,13 +341,15 @@ def test_nccmp_ncgen_remap(): comp_name = "atmos_scalar_CNAME" output_nc_file = f"{comp_name}.198001-198412.co2mass.nc" - nccmp = [ "nccmp", "-d", - Path(f"{REMAP_IN}/{NATIVE_GRID}/atmos_scalar/{FREQ}/{CHUNK}/{DATA_NC_FILES[0]}"), - Path(f"{REMAP_OUT}/{comp_name}/{PRODUCT}/monthly/5yr/{output_nc_file}") ] - sp = subprocess.run( nccmp, check = False) - assert sp.returncode == 0 + with xr.open_dataset( + Path(f"{REMAP_IN}/{NATIVE_GRID}/atmos_scalar/{FREQ}/{CHUNK}/{DATA_NC_FILES[0]}"), + decode_cf=False, decode_times=False) as ds_in, \ + xr.open_dataset( + Path(f"{REMAP_OUT}/{comp_name}/{PRODUCT}/monthly/5yr/{output_nc_file}"), + decode_cf=False, decode_times=False) as ds_out: + xr.testing.assert_equal(ds_in, ds_out) -def test_nccmp_ncgen_remap_ens_mem(): +def test_compare_ncgen_remap_ens_mem(): """ This test compares the results of ncgen and rewrite_remap, making sure that the remapped files are identical. @@ -358,14 +361,15 @@ def test_nccmp_ncgen_remap_ens_mem(): remap_ens_in = f"{TEST_OUTDIR}/ncgen-ens-output" remap_ens_out = f"{TEST_OUTDIR}/remap-ens-output" - nccmp = [ "nccmp", "-d", - Path(f"{remap_ens_in}/{NATIVE_GRID}/ens_01/atmos_scalar/{FREQ}/{CHUNK}/{DATA_NC_FILES[0]}"), - Path(f"{remap_ens_out}/{comp_name}/{PRODUCT}/ens_01/monthly/5yr/{output_nc_file}") ] + with xr.open_dataset( + Path(f"{remap_ens_in}/{NATIVE_GRID}/ens_01/atmos_scalar/{FREQ}/{CHUNK}/{DATA_NC_FILES[0]}"), + decode_cf=False, decode_times=False) as ds_in, \ + xr.open_dataset( + Path(f"{remap_ens_out}/{comp_name}/{PRODUCT}/ens_01/monthly/5yr/{output_nc_file}"), + decode_cf=False, decode_times=False) as ds_out: + xr.testing.assert_equal(ds_in, ds_out) - sp = subprocess.run( nccmp, check = False) - assert sp.returncode == 0 - -def test_nccmp_ncgen_remap_statics(): +def test_compare_ncgen_remap_statics(): """ This test compares the results of ncgen and remap, making sure that the remapped static files are identical. @@ -373,14 +377,15 @@ def test_nccmp_ncgen_remap_statics(): comp_name = "atmos_scalar_CNAME" output_nc_file = f"{comp_name}.bk.nc" - nccmp = [ "nccmp", "-d", - Path(f"{REMAP_IN}/{NATIVE_GRID}/atmos_static_scalar/" - f"{STATIC_FREQ}/{STATIC_CHUNK}/{STATIC_DATA_NC_FILES[0]}"), - Path(f"{REMAP_OUT}/static/{comp_name}/" - f"{STATIC_FREQ}/{STATIC_CHUNK}/{output_nc_file}")] - - sp = subprocess.run( nccmp, check = False) - assert sp.returncode == 0 + with xr.open_dataset( + Path(f"{REMAP_IN}/{NATIVE_GRID}/atmos_static_scalar/" + f"{STATIC_FREQ}/{STATIC_CHUNK}/{STATIC_DATA_NC_FILES[0]}"), + decode_cf=False, decode_times=False) as ds_in, \ + xr.open_dataset( + Path(f"{REMAP_OUT}/static/{comp_name}/" + f"{STATIC_FREQ}/{STATIC_CHUNK}/{output_nc_file}"), + decode_cf=False, decode_times=False) as ds_out: + xr.testing.assert_equal(ds_in, ds_out) ## VARIABLE FILTERING TESTS ## def test_remap_variable_filtering():