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 dmrpp tests to expose data file path #323

Merged
merged 4 commits into from
Dec 3, 2024

Conversation

TomNicholas
Copy link
Member

@TomNicholas TomNicholas commented Dec 3, 2024

Comment on lines 169 to 175
def dmrparser(dmrpp_xml_str: str, tmp_path: Path, filename="test.nc") -> DMRParser:
# TODO we should actually create a dmrpp file in a temporary directory
# this would avoid the need to pass tmp_path separately

return DMRParser(
root=ET.fromstring(dmrpp_xml_str), data_filepath=tmp_path / filename
)
Copy link
Member Author

Choose a reason for hiding this comment

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

Turns out right now there is no need for this to be a fixture - fixtures are basically callables that provide something pre-packaged whilst also managing setup and teardown. But with tmp_path explicitly passed in at test execution time there is nothing to setup and teardown in here, so it can just be a function instead of a fixture.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds good! I just needed them to be separate so I can use different dmrpp XMLs to test different cases. However this dictionary approach makes more sense!

),
],
)
def test_parse_chunks(
basic_dmrpp,
tmp_path,
Copy link
Member Author

Choose a reason for hiding this comment

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

This test has the same kind of structure as the open_virtual_dataset tests I want to write in #243 - because both input test data (the parser) and the expected results need to know about the tmp_path.

</dmrpp:chunks>
</Int32>
<Group name="group1">
DMRPP_XML_STRINGS = {
Copy link
Member Author

Choose a reason for hiding this comment

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

Again these don't have setup or teardown, so each string doesn't really need its own fixture.

Copy link

codecov bot commented Dec 3, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 77.78%. Comparing base (3d7a4be) to head (4ff17d0).
Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #323      +/-   ##
==========================================
+ Coverage   77.76%   77.78%   +0.01%     
==========================================
  Files          48       48              
  Lines        3378     3398      +20     
==========================================
+ Hits         2627     2643      +16     
- Misses        751      755       +4     
Flag Coverage Δ
unittests 77.78% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ayushnag
Copy link
Contributor

ayushnag commented Dec 3, 2024

Looks good to me! Nice refactor of the two pytest fixtures

@TomNicholas TomNicholas merged commit 2bfeee3 into main Dec 3, 2024
11 checks passed
@TomNicholas TomNicholas deleted the dmrpp_tests_tmp_path branch December 3, 2024 20:26
@TomNicholas TomNicholas mentioned this pull request Dec 3, 2024
25 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants