Add missing conversion tests in unit conversion#86434
Merged
Merged
Conversation
epenet
commented
Jan 23, 2023
Contributor
Author
epenet
left a comment
There was a problem hiding this comment.
It seems that diff isn't very friendly on this PR.
Most of the code change is just moving stuff around, merging the parametrisation of all the test_XXX_convert into a single dictionary constant.
Comment on lines
+430
to
+441
| unit_ratio_item = _GET_UNIT_RATIO[converter] | ||
| assert unit_ratio_item[0] != unit_ratio_item[1], "ratio units should be different" | ||
|
|
||
| assert converter in _CONVERTED_VALUE, "converter is not present in _CONVERTED_VALUE" | ||
| converted_value_items = _CONVERTED_VALUE[converter] | ||
| for valid_unit in converter.VALID_UNITS: | ||
| assert any( | ||
| item | ||
| for item in converted_value_items | ||
| # item[1] is from_unit, item[3] is to_unit | ||
| if valid_unit in {item[1], item[3]} | ||
| ), f"Unit `{valid_unit}` is not tested in _CONVERTED_VALUE" |
Contributor
Author
There was a problem hiding this comment.
This is the second half of the code change: ensure that all units are in the _CONVERTED_VALUE parametrization dictionary.
Comment on lines
+105
to
+108
| # Dict containing a conversion test for every know unit. | ||
| _CONVERTED_VALUE: dict[ | ||
| type[BaseUnitConverter], list[tuple[float, str | None, float, str | None]] | ||
| ] = { |
Contributor
Author
There was a problem hiding this comment.
This is the first half of the PR: merged the parametrization lists into a single dictionary.
Comment on lines
+511
to
+521
| @pytest.mark.parametrize( | ||
| "converter,value,from_unit,expected,to_unit", | ||
| [ | ||
| # Process all items in _CONVERTED_VALUE | ||
| (converter, list_item[0], list_item[1], list_item[2], list_item[3]) | ||
| for converter, item in _CONVERTED_VALUE.items() | ||
| for list_item in item | ||
| ], | ||
| ) | ||
| def test_unit_conversion( | ||
| converter: type[BaseUnitConverter], |
Contributor
Author
There was a problem hiding this comment.
This is where we use the new dictionary.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Proposed change
As follow-up to #86340
ElectricPotentialConverter,UnitlessRatioConverterdidn't have unit conversion tested.PressureConverterwas also missing a test forUnitOfPressure.BAR.Type of change
Additional information
Checklist
black --fast homeassistant tests)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest.requirements_all.txt.Updated by running
python3 -m script.gen_requirements_all..coveragerc.To help with the load of incoming pull requests: