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

add test for assert sample and rtype #341

Merged
merged 9 commits into from
Jul 31, 2024

Conversation

sbidari
Copy link
Collaborator

@sbidari sbidari commented Jul 29, 2024

This PR attempts to add tests to _assert_sample_and_rtype function defined as

def _assert_sample_and_rtype(
    rp: "RandomVariable", skip_if_none: bool = True
) -> None:

Tests included

  1. return None if (rp is None) and (skip_if_none)
  2. raises error if (rp is None) and (not skip_if_none)
  3. check rp is a valid RandomVariable
  4. check return type is a tuple and is annotated as such
  5. raises error when return type annotation is missing in sample

@sbidari sbidari linked an issue Jul 29, 2024 that may be closed by this pull request
Copy link

codecov bot commented Jul 29, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 93.23%. Comparing base (64e0ed8) to head (7001ee4).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #341      +/-   ##
==========================================
+ Coverage   92.91%   93.23%   +0.32%     
==========================================
  Files          39       39              
  Lines         917      917              
==========================================
+ Hits          852      855       +3     
+ Misses         65       62       -3     
Flag Coverage Δ
unittests 93.23% <ø> (+0.32%) ⬆️

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.

@gvegayon
Copy link
Member

This is a helper function, and I'm unsure how much it is used across the package. Should this be somehow enforced in every model/RV that received RVs?

@sbidari
Copy link
Collaborator Author

sbidari commented Jul 30, 2024

This is a helper function, and I'm unsure how much it is used across the package.

It seems the usage is split between using _assert_sample_and_rtype and asssert isinstance(some_rv, RandomVariable) . I think it would be good idea to replace assert isinstance(some_rv, RandomVariable) with _assert_sample_and_rtype to check for tuple return inaddition to RV.

Should this be somehow enforced in every model/RV that received RVs?

Deferring the more general question of enforcing this in every model/RV to @damonbayer @dylanhmorris

@damonbayer
Copy link
Collaborator

Can we keep assert isinstance(some_rv, RandomVariable) but check for the proper return type whenever a RandomVariable is instantiated?

@sbidari
Copy link
Collaborator Author

sbidari commented Jul 30, 2024

Right now, we are using assert isinstance(some_rv, RandomVariable) in some codes (eg: in hospitaladmissions.py) and _assert_sample_and_rtype(some_rv) in others (eg: in InfectionsWithFeedback ) as validation when a RandomVariable is instantiated.
We should probably use one of these throughout for uniformity. _assert_sample_and_rtype(some_rv) tests if the input_rv is a RandomVariable and the return type

@damonbayer
Copy link
Collaborator

@sbidari I am suggesting that we separate "checking that something is a random variable" from "checking that the random variable is valid."

@sbidari sbidari added this to the 🦆 Olorotitan milestone Jul 31, 2024
@sbidari
Copy link
Collaborator Author

sbidari commented Jul 31, 2024

@sbidari I am suggesting that we separate "checking that something is a random variable" from "checking that the random variable is valid."

ok! I will create a new issue for extending the use of _assert_sample_and_rtype but not remove assert isinstance(some_rv, RandomVariable)

Marking the tests as ready for review.

@sbidari sbidari marked this pull request as ready for review July 31, 2024 15:28
@damonbayer damonbayer self-requested a review July 31, 2024 16:38
Copy link
Collaborator

@damonbayer damonbayer left a comment

Choose a reason for hiding this comment

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

@sbidari let me know if you want to make the changes I suggested. They are very minor and this could be merged without the changes.

@sbidari
Copy link
Collaborator Author

sbidari commented Jul 31, 2024

@damonbayer I tried following the pattern in other tests and do not feel strongly about the match strings. I think it's probably better not importing additional packages unless necessary, will change to remove importing re.

@damonbayer damonbayer merged commit 3780889 into main Jul 31, 2024
9 checks passed
@damonbayer damonbayer deleted the 332-tests-for-_assert_sample_and_rtype branch July 31, 2024 23:00
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 this pull request may close these issues.

Tests for _assert_sample_and_rtype
3 participants