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

Overflow and Type Errors added to concept.py . Required tests for qua… #77

Merged
merged 7 commits into from
Oct 11, 2024

Conversation

Vortex-21
Copy link
Contributor

Description

Added two more valiation for TypeError(specifically for NoneType objects.) and Overflow Error ( rare ) . Also added a set of tests in tests/test_quantity_class.py to check the validity of the code .

Related Issue

#68

Changes Made

  • Two more validation checks added to Quantity Class.

Testing

Tested upon valid inputs (valid strings , integers and floats), invalid inputs (invalid strings) and edge cases (empty strings, None Values).

Checklist

  • I have read the contributing guidelines
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Additional Notes

Copy link
Contributor

@adamkells adamkells left a comment

Choose a reason for hiding this comment

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

Hey @Vortex-21 , this is really great! I think the function is doing exactly the right thing and I think the test cases have great coverage. I've left a few comments on some minor issues. Most of these will be resolved by making sure to run steps 3 and 6 in the contribution guide.

.python-version Outdated
@@ -0,0 +1 @@
3.10.11
Copy link
Contributor

Choose a reason for hiding this comment

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

This file is typically used for local Python version management and shouldn't be tracked in the repository. Could you please unstage this file and add it to your .gitignore? Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unstaged ".python-version" and added to .gitignore .

pyproject.toml Outdated
@@ -35,6 +35,7 @@ termcolor = "^2.4.0"
spyne = "^2.14.0"
lxml = "^5.2.2"
xmltodict = "^0.13.0"
pytest = "^8.3.3"
Copy link
Contributor

Choose a reason for hiding this comment

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

Pytest is already in the dev dependencies so doesn't need to be added to the pyproject.toml. (If you check the contribution guide in the repo it has instructions for installing dev dependencies). Can you remove this line and regenerate the poetry.lock?

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, by installing the dev dependencies you'll get pre-commit and ruff installed. These are really neat tools that will check your code for some common style errors (number of new lines between functions, max line length) and auto-correct them when you run git commit.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

poetry.lock regenerated and dev dependencies installed !

exception_info_str = str(exception_info.value)
assert any(msg in exception_info_str for msg in ["CANNOT", "Invalid value"])

# if __name__ == '__main__':
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you remove the commented out lines?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Code formatted and commented out lines removed !

@Vortex-21
Copy link
Contributor Author

Vortex-21 commented Oct 9, 2024

Hey @Vortex-21 , this is really great! I think the function is doing exactly the right thing and I think the test cases have great coverage. I've left a few comments on some minor issues. Most of these will be resolved by making sure to run steps 3 and 6 in the contribution guide.

Good to hear that the function works fine! Apologies for the delay . I have made the necessary changes .

Copy link
Contributor

@adamkells adamkells left a comment

Choose a reason for hiding this comment

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

This is much better! There's just one more small issue that I've flagged where we're getting some testing errors. I missed this the first time round on the review but basically we don't want to raise an error for a None value passed in.

@field_validator("value")
@classmethod
def validate_value(cls, value: Union[str, float]):
if value is None:
Copy link
Contributor

Choose a reason for hiding this comment

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

I ran the testing suite and got some errors from this line. The logic here should be slightly different. If None is passed in then we want to just return None back, however if a type other than str or float is passed then we can raise the warning. I've added a suggestion below (written on my phone so will need some edits).

Suggested change
if value is None:
if value is None:
return None
elif type(value) is not str or float:
raise TypeError

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay got it ! Will make the change.

@Vortex-21
Copy link
Contributor Author

I have updated the code and removed validation for None . Updated the tests accordingly as well.

@Vortex-21
Copy link
Contributor Author

Vortex-21 commented Oct 11, 2024

Looks like in the tests/test_cdaannotator.py in line 71 and 76 medications[0].frequency.period.value and medications[0].duration.high.value which are float values , are compared to string values which causes the AssertionError in the test suite . Is this comparison expected or need to be updated ?

@adamkells
Copy link
Contributor

Yes these tests will need to be updated too. You can check them locally with "poetry run pytest".

@Vortex-21
Copy link
Contributor Author

tests updated !

Copy link
Contributor

@adamkells adamkells left a comment

Choose a reason for hiding this comment

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

Great job! Tests all passing, will merge shortly.

@adamkells adamkells merged commit ac259e0 into dotimplement:main Oct 11, 2024
5 checks passed
@jenniferjiangkells jenniferjiangkells mentioned this pull request Oct 12, 2024
5 tasks
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.

2 participants