Skip to content

Commit

Permalink
fix attribute tests
Browse files Browse the repository at this point in the history
  • Loading branch information
anton-seaice committed Apr 16, 2024
1 parent 469ecfc commit e1296bc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
4 changes: 1 addition & 3 deletions esmgrids/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,13 @@ def cice_from_mom():
parser.add_argument("--ocean_mask", type=str, help="Input MOM ocean_mask.nc mask file")
parser.add_argument("--cice_grid", type=str, default="grid.nc", help="Output CICE grid file")
parser.add_argument("--cice_kmt", type=str, default="kmt.nc", help="Output CICE kmt file")
# to-do: add argument for CRS?


args = parser.parse_args()
ocean_hgrid = os.path.abspath(args.ocean_hgrid)
ocean_mask = os.path.abspath(args.ocean_mask)
cice_grid = os.path.abspath(args.cice_grid)
cice_kmt = os.path.abspath(args.cice_kmt)

# to-do: need to input package version here
runcmd = (
f"Created using esmgrid {__version__}: "
f"cice_from_mom --ocean_hgrid={ocean_hgrid} --ocean_mask={ocean_mask} "
Expand Down
19 changes: 11 additions & 8 deletions test/test_cice_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,16 +205,19 @@ def test_crs_exist(cice_grid):
def test_inputs_logged(cice_grid, mom_grid):
# Test: have the source data been logged ?

assert hasattr(cice_grid.ds, "inputfile"), "inputfile attribute missing"
assert hasattr(cice_grid.kmt_ds, "inputfile"), "inputfile attribute missing"

input_md5 = run(["md5sum", cice_grid.ds.inputfile], capture_output=True, text=True)
input_md5 = input_md5.stdout.split(" ")[0]
mask_md5 = run(["md5sum", cice_grid.kmt_ds.inputfile], capture_output=True, text=True)
mask_md5 = mask_md5.stdout.split(" ")[0]

assert (
cice_grid.ds.inputfile
== (mom_grid.path + " (md5 hash: " + input_md5 + "), " + mom_grid.mask_path + " (md5 hash: " + mask_md5 + ")"),
"inputfile attribute incorrect ({cice_grid.ds.inputfile} != {mom_grid.path})",
)
for ds in [cice_grid.ds, cice_grid.kmt_ds]:
assert (
ds.inputfile
== (mom_grid.path + " (md5 hash: " + input_md5 + "), " + mom_grid.mask_path + " (md5 hash: " + mask_md5 + ")"),
"inputfile attribute incorrect ({ds.inputfile} != {mom_grid.path})",
)

assert hasattr(ds, "inputfile"), "inputfile attribute missing"

assert hasattr(ds, "history"), "history attribute missing"

0 comments on commit e1296bc

Please sign in to comment.