From 97562e2c883ba1ebd1e26bd083eff158a4a0697c Mon Sep 17 00:00:00 2001 From: Derek Maggio Date: Thu, 4 Apr 2024 13:38:14 -0700 Subject: [PATCH 1/3] fix: Fix return of patched function When we patch the _read_settings_file function we are not including flags that are set to internal_only=True. --- api/tests/opentrons/config/test_advanced_settings.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/api/tests/opentrons/config/test_advanced_settings.py b/api/tests/opentrons/config/test_advanced_settings.py index b81b9149c67..61aa6d8dd63 100644 --- a/api/tests/opentrons/config/test_advanced_settings.py +++ b/api/tests/opentrons/config/test_advanced_settings.py @@ -57,12 +57,12 @@ def mock_settings( @pytest.fixture def mock_read_settings_file_ot2( - mock_settings_values_ot2: Dict[str, Optional[bool]], + mock_settings_values_ot2_all: Dict[str, Optional[bool]], mock_settings_version: int, ) -> Generator[MagicMock, None, None]: with patch("opentrons.config.advanced_settings._read_settings_file") as p: p.return_value = advanced_settings.SettingsData( - settings_map=mock_settings_values_ot2, + settings_map=mock_settings_values_ot2_all, version=mock_settings_version, ) yield p @@ -168,19 +168,19 @@ def test_get_all_adv_settings_empty( async def test_set_adv_setting( mock_read_settings_file_ot2: MagicMock, - mock_settings_values_ot2: MagicMock, + mock_settings_values_ot2_all: MagicMock, mock_write_settings_file: MagicMock, mock_settings_version: int, restore_restart_required: None, ) -> None: - for k, v in mock_settings_values_ot2.items(): + for k, v in mock_settings_values_ot2_all.items(): # Toggle the advanced setting await advanced_settings.set_adv_setting(k, not v) mock_write_settings_file.assert_called_with( # Only the current key is toggled { nk: nv if nk != k else not v - for nk, nv in mock_settings_values_ot2.items() + for nk, nv in mock_settings_values_ot2_all.items() }, mock_settings_version, CONFIG["feature_flags_file"], From 9fd469cde5fd70d76c95c35154fcac8719f8ad60 Mon Sep 17 00:00:00 2001 From: Derek Maggio Date: Thu, 4 Apr 2024 13:48:06 -0700 Subject: [PATCH 2/3] Add change for flex --- api/tests/opentrons/config/test_advanced_settings.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/api/tests/opentrons/config/test_advanced_settings.py b/api/tests/opentrons/config/test_advanced_settings.py index 61aa6d8dd63..a937b1498a5 100644 --- a/api/tests/opentrons/config/test_advanced_settings.py +++ b/api/tests/opentrons/config/test_advanced_settings.py @@ -33,6 +33,14 @@ def mock_settings_values_flex() -> Dict[str, Optional[bool]]: if RobotTypeEnum.FLEX in s.robot_type and not s.internal_only } +@pytest.fixture +def mock_settings_values_flex_all() -> Dict[str, Optional[bool]]: + return { + s.id: False + for s in advanced_settings.settings + if RobotTypeEnum.FLEX in s.robot_type + } + @pytest.fixture def mock_settings_values_empty() -> Dict[str, Optional[bool]]: @@ -70,12 +78,12 @@ def mock_read_settings_file_ot2( @pytest.fixture def mock_read_settings_file_flex( - mock_settings_values_flex: Dict[str, Optional[bool]], + mock_settings_values_flex_all: Dict[str, Optional[bool]], mock_settings_version: int, ) -> Generator[MagicMock, None, None]: with patch("opentrons.config.advanced_settings._read_settings_file") as p: p.return_value = advanced_settings.SettingsData( - settings_map=mock_settings_values_flex, + settings_map=mock_settings_values_flex_all, version=mock_settings_version, ) yield p From eb03fffe098e4d50b336ddd7e848358412d3cfae Mon Sep 17 00:00:00 2001 From: Derek Maggio Date: Thu, 4 Apr 2024 13:51:07 -0700 Subject: [PATCH 3/3] chore: formatting --- api/src/opentrons/config/advanced_settings.py | 3 ++- api/src/opentrons/config/feature_flags.py | 4 +--- api/tests/opentrons/config/test_advanced_settings.py | 1 + 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/api/src/opentrons/config/advanced_settings.py b/api/src/opentrons/config/advanced_settings.py index 9b53f893589..f4c75701901 100644 --- a/api/src/opentrons/config/advanced_settings.py +++ b/api/src/opentrons/config/advanced_settings.py @@ -250,7 +250,7 @@ class Setting(NamedTuple): ), robot_type=[RobotTypeEnum.OT2, RobotTypeEnum.FLEX], internal_only=True, - ) + ), ] if ( @@ -719,6 +719,7 @@ def _migrate31to32(previous: SettingsMap) -> SettingsMap: newmap["enableOEMMode"] = None return newmap + def _migrate32to33(previous: SettingsMap) -> SettingsMap: """Migrate to version 33 of the feature flags file. diff --git a/api/src/opentrons/config/feature_flags.py b/api/src/opentrons/config/feature_flags.py index b88e741b3dc..e9772a01ee8 100644 --- a/api/src/opentrons/config/feature_flags.py +++ b/api/src/opentrons/config/feature_flags.py @@ -79,6 +79,4 @@ def enable_error_recovery_experiments() -> bool: def enable_performance_metrics(robot_type: RobotTypeEnum) -> bool: - return advs.get_setting_with_env_overload( - "enablePerformanceMetrics", robot_type - ) + return advs.get_setting_with_env_overload("enablePerformanceMetrics", robot_type) diff --git a/api/tests/opentrons/config/test_advanced_settings.py b/api/tests/opentrons/config/test_advanced_settings.py index a937b1498a5..17122fca0dd 100644 --- a/api/tests/opentrons/config/test_advanced_settings.py +++ b/api/tests/opentrons/config/test_advanced_settings.py @@ -33,6 +33,7 @@ def mock_settings_values_flex() -> Dict[str, Optional[bool]]: if RobotTypeEnum.FLEX in s.robot_type and not s.internal_only } + @pytest.fixture def mock_settings_values_flex_all() -> Dict[str, Optional[bool]]: return {