Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor coord mocks when #63/lat long fixes is merged #69

Open
truth-quark opened this issue Aug 13, 2024 · 1 comment · May be fixed by #113
Open

Refactor coord mocks when #63/lat long fixes is merged #69

truth-quark opened this issue Aug 13, 2024 · 1 comment · May be fixed by #113

Comments

@truth-quark
Copy link
Collaborator

truth-quark commented Aug 13, 2024

When #63 is merged, I'll refactor the test_process_...() test setup to remove the coord mock & ensure the prod code is called.

Removing the fix_level_coord() & cubewrite() mocks can be handled in separate PRs (working on a model of gradually improving tests as um2nc is improved).

Originally posted by @truth-quark in #58 (comment)

To clarify tasks:

Replace buggy implementation with DummyCube with no coord attrs:

def set_default_attrs(cube, item_code: int, var_name: str):
"""Add subset of default attributes to flesh out cube like objects."""
cube.__dict__.update({"item_code": item_code,
"var_name": var_name,
"long_name": "",
"coord": {"latitude": 0.0, # TODO: real val = ?
"longitude": 0.0}, # TODO: real val

Remove these mocks & the tests should pass:

mock.patch("umpost.um2netcdf.fix_latlon_coords"),

@truth-quark
Copy link
Collaborator Author

From exploratory work on branch 69/refactor-cube-mocks:

Before:

def set_default_attrs(cube, item_code: int, var_name: str):
"""Add subset of default attributes to flesh out cube like objects."""
cube.__dict__.update({"item_code": item_code,
"var_name": var_name,
"long_name": "",
"coord": {"latitude": 0.0, # TODO: real val = ?
"longitude": 0.0}, # TODO: real val
"cell_methods": [],
"data": None,
})
section, item = um2nc.to_stash_code(item_code)
cube.attributes = {um2nc.STASH: DummyStash(section, item)}
@pytest.fixture
def air_temp_cube():
# data copied from aiihca.paa1jan.subset file
name = "air_temperature"
m_air_temp = mock.NonCallableMagicMock(spec=iris.cube.Cube, name=name)
set_default_attrs(m_air_temp, 30204, name)
return m_air_temp

After:

@pytest.fixture
def air_temp_cube(lat_river_coord, lon_river_coord):
# details copied from aiihca.paa1jan.subset file
air_temp = DummyCube(30204, "air_temperature",
coords=[lat_river_coord, lon_river_coord])
return air_temp

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant