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 cube testing objects/mocking with DummyCube #113

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

truth-quark
Copy link
Collaborator

This closes #69.

This PR covers multiple elements to switch tests to using DummyCube:

  • Replaces several Mock objs masquerading as cubes with DummyCube
  • Removes old setup cruft
  • Cleans some test fixtures
  • Adds coords to other test fixtures (fixtures better open for reuse)
  • Removes mock.patch("umpost.um2netcdf.fix_latlon_coords") in process() tests
  • BONUS: removes mock.patch("umpost.um2netcdf.fix_level_coord") in process() tests

Any comments welcome!

@truth-quark truth-quark self-assigned this Sep 26, 2024
@truth-quark truth-quark added enhancement New feature or request Release Required for next release labels Sep 26, 2024
return m_air_temp
def air_temp_cube(lat_river_coord, lon_river_coord):
# details copied from aiihca.paa1jan.subset file
air_temp = DummyCube(30204, "air_temperature",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do these codes have a specific meaning, or do you just need a distinct code for each cube type? If the former, it might benefit from using a reference dict or similar rather than having magic numbers.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The codes are in the umpost/stashvar_cmip6.py module & I've copied them across.

A reference/index dict or constants for common stash codes could certainly help...

Copy link

@marc-white marc-white left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks pretty straightforward to me.

My main comment (which only just occurred to me, and clearly is an existing issue) is that a lot of the test assert statements don't have an explanatory note after them, e.g.:

assert False, "Well this will obviously fail"

It's nice to get an explanation out of pytest as to why a test failed, rather than having to dig into the test code itself to figure out what's going on. Up to you whether this is dealt with as part of this PR, or as a new issue.

@truth-quark
Copy link
Collaborator Author

truth-quark commented Sep 27, 2024

My main comment (which only just occurred to me, and clearly is an existing issue) is that a lot of the test assert statements don't have an explanatory note after them, e.g.:

assert False, "Well this will obviously fail"

It's nice to get an explanation out of pytest as to why a test failed, rather than having to dig into the test code itself to figure out what's going on. Up to you whether this is dealt with as part of this PR, or as a new issue.

Some of this is related to the process of retro-fitting testing & the way the code operates. Quite often, a function takes inputs, modifies a cube & returns None. Error messages could make it clearer if a value hasn't been set properly.

This relates to another element: being unfamiliar with why steps are done, thus not knowing what meaningful error msg to provide (or in some cases, if the code is doing the right thing).

There's also a future refactoring step where I suspect simplification could result in shrinking the code & tests. At this stage I'm mainly focusing on code coverage to assist with the rework steps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Release Required for next release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

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