-
Notifications
You must be signed in to change notification settings - Fork 199
test(api): liquid classes blowout properties #17875
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
Merged
y3rsh
merged 3 commits into
chore_release-8.4.0
from
AUTH-1557_build_blowout_properties-test
Mar 25, 2025
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
188 changes: 188 additions & 0 deletions
188
api/tests/opentrons/protocol_api/test_lc_blowout_properties.py
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,188 @@ | ||
| """Tests for liquid class blowout properties in the Opentrons protocol API.""" | ||
|
|
||
| from pydantic import ValidationError | ||
| import pytest | ||
| from typing import Any | ||
| from hypothesis import given, strategies as st, settings | ||
|
|
||
| from opentrons.protocol_api._liquid_properties import ( | ||
| _build_blowout_properties, | ||
| ) | ||
| from opentrons_shared_data.liquid_classes.liquid_class_definition import ( | ||
| BlowoutProperties, | ||
| BlowoutParams, | ||
| BlowoutLocation, | ||
| ) | ||
|
|
||
| from . import ( | ||
| boolean_looking_values, | ||
| invalid_values, | ||
| negative_or_zero_floats_and_ints, | ||
| positive_non_zero_floats_and_ints, | ||
| ) | ||
|
|
||
|
|
||
| def test_blowout_properties_enable_and_disable() -> None: | ||
| """Test that enable and disable work as expected.""" | ||
| bp = _build_blowout_properties( | ||
| BlowoutProperties( | ||
| enable=False, | ||
| params=BlowoutParams(location=BlowoutLocation.DESTINATION, flowRate=100), | ||
| ) | ||
| ) | ||
| bp.enabled = True | ||
| assert bp.enabled is True | ||
| bp.enabled = False | ||
| assert bp.enabled is False | ||
|
|
||
|
|
||
| def test_blowout_properties_none_instantiation_combos() -> None: | ||
| """Test that none values raise.""" | ||
| with pytest.raises(ValidationError): | ||
| _build_blowout_properties( | ||
| BlowoutProperties(enable=None, params=BlowoutParams(location=None, flowRate=None)) # type: ignore | ||
| ) | ||
| with pytest.raises(ValidationError): | ||
| _build_blowout_properties( | ||
| BlowoutProperties(enable=True, params=BlowoutParams(location=None, flowRate=100)) # type: ignore | ||
| ) | ||
|
|
||
|
|
||
| @given(bad_enable=boolean_looking_values) | ||
| @settings(deadline=None, max_examples=50) | ||
| def test_blowout_properties_enabled_bad_values(bad_enable: Any) -> None: | ||
| """Test that invalid enable values raise.""" | ||
| with pytest.raises(ValidationError): | ||
| _build_blowout_properties( | ||
| BlowoutProperties( | ||
| enable=bad_enable, | ||
| params=BlowoutParams(location=BlowoutLocation.TRASH, flowRate=50), | ||
| ) | ||
| ) | ||
| bp = _build_blowout_properties( | ||
| BlowoutProperties( | ||
| enable=False, | ||
| params=BlowoutParams(location=BlowoutLocation.TRASH, flowRate=50), | ||
| ) | ||
| ) | ||
| with pytest.raises(ValueError): | ||
| bp.enabled = bad_enable | ||
|
|
||
|
|
||
| @given(good_flow_rate=positive_non_zero_floats_and_ints) | ||
| @settings(deadline=None, max_examples=50) | ||
| def test_blowout_properties_flow_rate(good_flow_rate: Any) -> None: | ||
| """Test that valid flow rate values are accepted.""" | ||
| _build_blowout_properties( | ||
| BlowoutProperties( | ||
| enable=True, | ||
| params=BlowoutParams( | ||
| location=BlowoutLocation.DESTINATION, flowRate=good_flow_rate | ||
| ), | ||
| ) | ||
| ) | ||
| bp = _build_blowout_properties( | ||
| BlowoutProperties( | ||
| enable=True, | ||
| params=BlowoutParams(location=BlowoutLocation.TRASH, flowRate=1), | ||
| ) | ||
| ) | ||
| bp.flow_rate = good_flow_rate | ||
| assert bp.flow_rate == float(good_flow_rate) | ||
|
|
||
|
|
||
| @given(bad_flow_rate=st.one_of(invalid_values, negative_or_zero_floats_and_ints)) | ||
| @settings(deadline=None, max_examples=50) | ||
| def test_blowout_properties_flow_rate_bad_values(bad_flow_rate: Any) -> None: | ||
| """Test that invalid flow rate values raise.""" | ||
| with pytest.raises(ValidationError): | ||
| _build_blowout_properties( | ||
| BlowoutProperties( | ||
| enable=True, | ||
| params=BlowoutParams( | ||
| location=BlowoutLocation.TRASH, flowRate=bad_flow_rate | ||
| ), | ||
| ) | ||
| ) | ||
| bp = _build_blowout_properties( | ||
| BlowoutProperties( | ||
| enable=True, | ||
| params=BlowoutParams(location=BlowoutLocation.TRASH, flowRate=50), | ||
| ) | ||
| ) | ||
| with pytest.raises(ValueError): | ||
| bp.flow_rate = bad_flow_rate | ||
|
|
||
|
|
||
| @given( | ||
| good_location=st.one_of( | ||
| st.just(BlowoutLocation.DESTINATION), | ||
| st.just(BlowoutLocation.TRASH), | ||
| st.just(BlowoutLocation.SOURCE), | ||
| ) | ||
| ) | ||
| @settings(deadline=None, max_examples=50) | ||
| def test_blowout_properties_location_enum(good_location: Any) -> None: | ||
| """Test that valid location values are accepted.""" | ||
| bp = _build_blowout_properties( | ||
| BlowoutProperties( | ||
| enable=True, params=BlowoutParams(location=good_location, flowRate=50) | ||
| ) | ||
| ) | ||
| assert bp.location == good_location | ||
| bp = _build_blowout_properties( | ||
| BlowoutProperties( | ||
| enable=True, | ||
| params=BlowoutParams(location=BlowoutLocation.TRASH, flowRate=50), | ||
| ) | ||
| ) | ||
|
|
||
| bp.location = good_location | ||
| assert bp.location == good_location | ||
|
|
||
|
|
||
| @given( | ||
| good_location=st.one_of( | ||
| st.just("destination"), | ||
| st.just("trash"), | ||
| st.just("source"), | ||
| ) | ||
| ) | ||
| @settings(deadline=None, max_examples=50) | ||
| def test_blowout_properties_location_str(good_location: Any) -> None: | ||
| """Test that valid location values are accepted.""" | ||
| bp = _build_blowout_properties( | ||
| BlowoutProperties( | ||
| enable=True, params=BlowoutParams(location=good_location, flowRate=50) | ||
| ) | ||
| ) | ||
| assert bp.location is not None and bp.location.value == good_location | ||
| bp = _build_blowout_properties( | ||
| BlowoutProperties( | ||
| enable=True, | ||
| params=BlowoutParams(location=BlowoutLocation.TRASH, flowRate=50), | ||
| ) | ||
| ) | ||
| bp.location = good_location | ||
| assert bp.location is not None and bp.location.value == good_location | ||
|
|
||
|
|
||
| @given(bad_location=st.one_of(invalid_values, st.just("chute"))) | ||
| @settings(deadline=None, max_examples=50) | ||
| def test_blowout_properties_location_bad(bad_location: Any) -> None: | ||
| """Test that invalid location values raise.""" | ||
| with pytest.raises(ValidationError): | ||
| bp = _build_blowout_properties( | ||
| BlowoutProperties( | ||
| enable=True, params=BlowoutParams(location=bad_location, flowRate=50) | ||
| ) | ||
| ) | ||
|
|
||
| bp = _build_blowout_properties( | ||
| BlowoutProperties( | ||
| enable=True, | ||
| params=BlowoutParams(location=BlowoutLocation.TRASH, flowRate=50), | ||
| ) | ||
| ) | ||
| with pytest.raises(ValueError): | ||
| bp.location = bad_location |
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
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oo this is confusing. We have a
BlowOutParamsand aBlowoutParams🙈