-
Notifications
You must be signed in to change notification settings - Fork 0
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
RDRP-781: Unit tests for remaining staging helpers #249
base: develop
Are you sure you want to change the base?
Conversation
Hi @CBROWN-ONS and @AnneONS - I've requested a review from you both. Really keen for any ideas to make these better. The new tests are testing functions that contain paths to the config. If they are run in full, they go to real configs which contain all the variables so they error on the test data. I couldn't find a way to avoid this, however, because those functions are already unit tested, I have concentrated on checking that the appropriate functions are called within these tests. Grateful for your thoughts. Thanks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Jen.
I've not come across much of the unittest package. so this was a nice thing for me to learn reading through your code :).
While the mocking is neat, and seems to work as intended, I have some suggestions for improving the maintainability and robustness of the tests.
To begin with, there are functions within the load_validate_mapper
function that aren't being included in the mock tests, where as some are. This is rather inconsistent in a way.
Next, the function is able to be tested using real data, rather than mocks. For example, you are able to write out schemas/configs/jsons to temp paths, and read them back in, using pytest. This allows for real testing of the function, ensuring it is able to act as intended, and not just call the functions. This will more accurately test that the function is acting in the correct way, making the tests more secure.
Using pytest would also align it with the rest of the tests in this module.
In general, the main processes of this function include reading from files, therefore it seems like a requirement that this is happening during the tests, rather than mocks being implemented.
More tests can also be included, such as checking that the messages are being written to the logger. This is unrelated to the mocking approach, and more of a feature request.
Thanks, I'm happy to answer any questions you might have.
|
||
@patch("src.utils.local_file_mods.load_local_json") | ||
@patch("src.staging.validation.validate_data_with_schema") | ||
@patch("src.staging.spp_snapshot_processing.full_responses") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unused
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As above
def test_load_validate_secondary_snapshot( | ||
self, | ||
mock_combine_schemas_validate_full_df, | ||
mock_full_responses, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unused
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As above
def test_load_val_snapshot_json_correct_response_rate( | ||
self, | ||
mock_combine_schemas_validate_full_df, | ||
mock_full_responses, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unused
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As above, I think the mock for the function full_responses is being used
|
||
@patch("src.utils.local_file_mods.load_local_json") | ||
@patch("src.staging.validation.validate_data_with_schema") | ||
@patch("src.staging.spp_snapshot_processing.full_responses") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unused
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is being used
HI @CBROWN-ONS, thanks for your review and writing out your thoughts clearly. I could show you this if you are interested. |
Ticket changed: hard coded path were relative so just unit tests for:
load_validate_mapper()
load_val_snapshot_json()
Removed as no longer needed:
load_validate_secondary_snapshot()
Pull Request submission
Insert detailed bullet points about your changes here!
Insert any instructions to help the reviewer, e.g. "install new requirements from
requirements.txt
"*Let the reviewer know what data files are needed (and if applicable, where they are to be found)
Closes or fixes
Closes #
Code
Documentation
Any new code includes all the following forms of documentation:
Args
andreturns
for all major functionsData
Testing
Peer Review Section
requirements.txt
Final approval (post-review)
The author has responded to my review and made changes to my satisfaction.
Review comments
Insert detailed comments here!
These might include, but not exclusively:
that it is likely to interact with?)
works correctly?)
Your suggestions should be tailored to the code that you are reviewing.
Be critical and clear, but not mean. Ask questions and set actions.