Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

test functions for validate_mesh_structure_pairs #114

Merged
merged 11 commits into from
Feb 21, 2024
Merged

test functions for validate_mesh_structure_pairs #114

merged 11 commits into from
Feb 21, 2024

Conversation

viktorpm
Copy link
Collaborator

@viktorpm viktorpm commented Jan 29, 2024

Description

What is this PR

  • Bug fix
  • Addition of a new feature
  • Other

Why is this PR needed?

To complete validate_mesh_structure_pairs function with test functions.

What does this PR do?

Adds test functions for validate_mesh_structure_pairs validation function in validate_atlases.py.

References

closes #111

How has this PR been tested?

Test functions have been tested manually using BrainGlobeAtlas("allen_mouse_100um") and BrainGlobeAtlas("admba_3d_e11_5_mouse_16u")

Is this a breaking change?

No

Does this PR require an update to the documentation?

No

Checklist:

  • The code has been tested locally
  • Tests have been added to cover all new functionality (unit & integration)
  • The documentation has been updated to reflect any changes
  • The code has been formatted with pre-commit

Copy link

codecov bot commented Jan 29, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (a4acdb4) 0.00% compared to head (860129a) 0.00%.
Report is 5 commits behind head on main.

❗ Current head 860129a differs from pull request most recent head 972b0d6. Consider uploading reports for the commit 972b0d6 to get more accurate results

Additional details and impacted files
@@          Coverage Diff          @@
##            main    #114   +/-   ##
=====================================
  Coverage   0.00%   0.00%           
=====================================
  Files         24      24           
  Lines       1943    1943           
=====================================
  Misses      1943    1943           

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

@alessandrofelder alessandrofelder marked this pull request as ready for review January 30, 2024 15:57
Copy link
Member

@alessandrofelder alessandrofelder left a comment

Choose a reason for hiding this comment

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

Thanks @viktorpm - this is a good start... the structure for the necessary changes is there.

I have a few comments for improvement:

  • there should also be a test where validate_mesh_structure_pairs doesn't raise an error.
  • I don't understand how both these tests can pass (but they seem to)? From looking at the code in the validation function, logically, only one of them can pass? Because once an assertion error is hit, the second assertion will not be executed. I wonder whether theres a problem in the match argument of pytest.raises? What am I missing?
  • the sentence in the "why is this PR needed" section of this PR's description is incomplete :)

Copy link
Member

@alessandrofelder alessandrofelder left a comment

Choose a reason for hiding this comment

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

Thanks for this @viktorpm !
We're almost there - think one of the tests need a small re-think otherwise 👍

Comment on lines +99 to +112
Expected behaviour:
Currently no atlas fails the validation function this way so the [] is always empty
--> this test function should always raise an error
Copy link
Member

Choose a reason for hiding this comment

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

I don't understand this. Some thoughts:

  • I don't think a test function should ever raise an error
  • pytest.raises checks whether a function in the source code raises an error in the expected case - it doesn't raise an error itself (the name is slightly confusing).
  • this is a test for the catch_missing_structures function
  • in this test, we should therefore pass a different atlas with missing structures to catch_missing_structures - one that we expect to raise the expected error - so we can check that catch_missing_structures works as expected.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks @alessandrofelder for clarifying this! I was overcomplicating it a bit in my head :)
So can I just mock an atlas with a missing structure and pass that to the test function?

Copy link
Member

Choose a reason for hiding this comment

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

So can I just mock an atlas with a missing structure ...

Indeed. You may not even need to use the mocking framework to do this. You can remove a key-value-pair from the atlas.structures dict.

... and pass that to the test function?

I would formulate this as "create it in the test function and pass it to the tested function".

Comment on lines 183 to 191
validation_results[atlas_name].append(
(validation_function.__name__, None, str("Pass"))
)
except AssertionError as error:
failed_validations[atlas_name].append((validation_function, error))
validation_results[atlas_name].append(
(validation_function.__name__, str(error), str("Fail"))
)

return successful_validations, failed_validations
return validation_results
Copy link
Member

Choose a reason for hiding this comment

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

Think we should to rebase or merge main here, as there's some changes here that are the same as those already in current main, ie commit hash: 03392f3 (but with a different commit hash: cfccbb8).

These changes are unrelated to the current PR as far as I can tell?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I see what you mean but I'm gonna need your help with this

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@alessandrofelder, can we do this together whenever you have the time?

Copy link
Member

@alessandrofelder alessandrofelder left a comment

Choose a reason for hiding this comment

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

Great - I am happy with this now.

tests/test_unit/test_validation.py Outdated Show resolved Hide resolved
@viktorpm viktorpm merged commit 76a513a into main Feb 21, 2024
7 checks passed
@viktorpm viktorpm deleted the issue_111 branch February 21, 2024 16:31
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Write basic tests for validate_mesh_structure_pairs
2 participants