Commit 470fd20d authored by Marco Kurzynski's avatar Marco Kurzynski
Browse files

added dim and var test

parent 8174ee5a
......@@ -39,8 +39,6 @@ def compare_nc(nc1, nc2, percent_error=0.0, ignore=[]):
for dim in dims:
nc1_dim = nc1.dimensions[dim]
nc2_dim = nc2.dimensions[dim]
if nc1_dim.name != nc2_dim.name:
print(f"{tcolor.GREEN} Dimension {dim} names do not match\n< {nc1_dim.name}\n> {nc2_dim.name}")
if nc1_dim.size != nc2_dim.size:
print(f"{tcolor.GREEN} Dimension {dim} sizes do not match\n< {nc1_dim.size}\n> {nc2_dim.size}")
nc1_dims.remove(dim)
......@@ -96,7 +94,7 @@ def compare_nc(nc1, nc2, percent_error=0.0, ignore=[]):
var1 = nc1[var_key]
var2 = nc2[var_key]
if var2.shape != var1.shape:
print(f"{tcolor.GREEN} Shape {var1.size} and {var2.size} differ{tcolor.ENDC}")
print(f"{tcolor.GREEN} Variable {var_key} shapes do not match\n< {var1.size}\n> {var2.size}{tcolor.ENDC}")
ret = -1
elif var1[:].any() and var2[:].any():
......@@ -117,10 +115,10 @@ def compare_nc(nc1, nc2, percent_error=0.0, ignore=[]):
nc2_variables.remove(var_key)
if nc1_variables:
print(f"{tcolor.GREEN} Attributes {nc1_attrs} only in {nc1.filepath()}{tcolor.ENDC}")
print(f"{tcolor.GREEN} Variables {nc1_variables} only in {nc1.filepath()}{tcolor.ENDC}")
ret = -1
if nc2_variables:
print(f"{tcolor.GREEN} Attributes {nc2_attrs} only in {nc2.filepath()}{tcolor.ENDC}")
print(f"{tcolor.GREEN} Variables {nc2_variables} only in {nc2.filepath()}{tcolor.ENDC}")
ret = -1
return ret
......
......@@ -72,11 +72,52 @@ def test_dimensions(tmp_path, capsys):
# make dimensions with different shapes
nc_files[0].createDimension("dim1", None) # unlimited
nc_files[1].createDimension("dim1", 1)
nc_files[0].createDimension("only1", 1)
for f in nc_files: f.sync()
ret = compare.main(argv=[str(tmp_path / "nc1.nc"), str(tmp_path / "nc2.nc")])
captured = capsys.readouterr()
print(f"return val: {ret}")
assert 0
print(captured.out)
assert 'Dimension dim1 sizes do not match' in captured.out
assert f"Dimensions ['only1'] only in {str(tmp_path / 'nc1.nc')}" in captured.out
def test_variables(tmp_path, capsys):
# test nc
nc_files = [Dataset(str(tmp_path / "nc1.nc"), mode="w"), Dataset(str(tmp_path / "nc2.nc"), mode="w")]
# make dimensions with different shapes
for f in nc_files:
f.createDimension("dim1", 1)
f.createDimension("dim2", 2)
f.sync()
# two variables with different dimensions
nc_files[0].createVariable("var1", "i", dimensions=["dim1"])
nc_files[1].createVariable("var1", "i", dimensions=["dim2"])
# variable only in one file
nc_files[0].createVariable("var2", "i")
# data will be outside margin of error
nc1_var1 = nc_files[0].createVariable("var3", "i", dimensions=["dim1"])
nc2_var1 = nc_files[1].createVariable("var3", "i", dimensions=["dim1"])
# data will be inside margin of error
nc1_var2 = nc_files[0].createVariable("var4", "i", dimensions=["dim1"])
nc2_var2 = nc_files[1].createVariable("var4", "i", dimensions=["dim1"])
nc1_var1[:] = [2]
nc2_var1[:] = [4]
nc1_var2[:] = [2]
nc2_var2[:] = [3]
for f in nc_files: f.sync()
ret = compare.main(argv=[str(tmp_path / "nc1.nc"), str(tmp_path / "nc2.nc"), "--percent-error", "50"])
captured = capsys.readouterr()
print(captured.out)
assert 'Variable var1 shapes do not match' in captured.out
assert f"Variables ['var2'] only in {str(tmp_path / 'nc1.nc')}" in captured.out
assert f"FP Error: variable var3" in captured.out
assert f"FP Error: variable var4" not in captured.out
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment