-
Notifications
You must be signed in to change notification settings - Fork 1
Merge Template #16
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
base: main
Are you sure you want to change the base?
Merge Template #16
Changes from all commits
44415ba
c65d503
c81fee6
fb2fe67
128da6d
d00fcd3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -16,19 +16,33 @@ | |||||||||||||||||||||||||||||||||||||||
| PROJECT_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | ||||||||||||||||||||||||||||||||||||||||
| sys.path.append(PROJECT_ROOT) | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| # Create mock for streamlit before importing ParameterManager | ||||||||||||||||||||||||||||||||||||||||
| # Mock streamlit before importing ParameterManager so that the imported module | ||||||||||||||||||||||||||||||||||||||||
| # uses a controllable `st.session_state` (a plain dict) instead of the real one, | ||||||||||||||||||||||||||||||||||||||||
| # which requires a running Streamlit app context. This allows unit-testing | ||||||||||||||||||||||||||||||||||||||||
| # ParameterManager's preset logic (apply_preset, clear_parameter_session_state) | ||||||||||||||||||||||||||||||||||||||||
| # in isolation. | ||||||||||||||||||||||||||||||||||||||||
| mock_streamlit = MagicMock() | ||||||||||||||||||||||||||||||||||||||||
| mock_streamlit.session_state = {} | ||||||||||||||||||||||||||||||||||||||||
| sys.modules['streamlit'] = mock_streamlit | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| # Create mock for pyopenms | ||||||||||||||||||||||||||||||||||||||||
| mock_pyopenms = MagicMock() | ||||||||||||||||||||||||||||||||||||||||
| mock_pyopenms.__version__ = "2.9.1" | ||||||||||||||||||||||||||||||||||||||||
| sys.modules['pyopenms'] = mock_pyopenms | ||||||||||||||||||||||||||||||||||||||||
| # Temporarily replace streamlit in sys.modules so that ParameterManager's | ||||||||||||||||||||||||||||||||||||||||
| # `import streamlit as st` picks up the mock. Restore immediately after import | ||||||||||||||||||||||||||||||||||||||||
| # so other test files (e.g., test_gui.py AppTest) get the real streamlit. | ||||||||||||||||||||||||||||||||||||||||
| _original_streamlit = sys.modules.get('streamlit') | ||||||||||||||||||||||||||||||||||||||||
| sys.modules['streamlit'] = mock_streamlit | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| # Now import after mocks are set up | ||||||||||||||||||||||||||||||||||||||||
| from src.workflow.ParameterManager import ParameterManager | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| if _original_streamlit is not None: | ||||||||||||||||||||||||||||||||||||||||
| sys.modules['streamlit'] = _original_streamlit | ||||||||||||||||||||||||||||||||||||||||
| else: | ||||||||||||||||||||||||||||||||||||||||
| sys.modules.pop('streamlit', None) | ||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+30
to
+38
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Guard If the import on Line 33 fails, Lines 35-38 never run, leaving the mocked 🛡️ Suggested patch _original_streamlit = sys.modules.get('streamlit')
-sys.modules['streamlit'] = mock_streamlit
-
-from src.workflow.ParameterManager import ParameterManager
-
-if _original_streamlit is not None:
- sys.modules['streamlit'] = _original_streamlit
-else:
- sys.modules.pop('streamlit', None)
+try:
+ sys.modules['streamlit'] = mock_streamlit
+ from src.workflow.ParameterManager import ParameterManager
+finally:
+ if _original_streamlit is not None:
+ sys.modules['streamlit'] = _original_streamlit
+ else:
+ sys.modules.pop('streamlit', None)📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| # Remove cached src.workflow modules that were imported with mocked streamlit so | ||||||||||||||||||||||||||||||||||||||||
| # that AppTest (in test_gui.py) re-imports them fresh with the real package. | ||||||||||||||||||||||||||||||||||||||||
| for _key in list(sys.modules.keys()): | ||||||||||||||||||||||||||||||||||||||||
| if _key.startswith('src.workflow'): | ||||||||||||||||||||||||||||||||||||||||
| sys.modules.pop(_key, None) | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| @pytest.fixture | ||||||||||||||||||||||||||||||||||||||||
| def temp_workflow_dir(): | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
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.
🧩 Analysis chain
🏁 Script executed:
Repository: OpenMS/quantms-web
Length of output: 494
🏁 Script executed:
rg "tracking_consent" src/common/common.py -B 2 -A 2Repository: OpenMS/quantms-web
Length of output: 935
🏁 Script executed:
Repository: OpenMS/quantms-web
Length of output: 409
🏁 Script executed:
rg "tracking_consent\[" --type py -B 1 -A 1Repository: OpenMS/quantms-web
Length of output: 744
🏁 Script executed:
Repository: OpenMS/quantms-web
Length of output: 925
🏁 Script executed:
Repository: OpenMS/quantms-web
Length of output: 1178
🏁 Script executed:
Repository: OpenMS/quantms-web
Length of output: 76
🏁 Script executed:
Repository: OpenMS/quantms-web
Length of output: 763
🏁 Script executed:
Repository: OpenMS/quantms-web
Length of output: 4341
Use a truthy
.get()consent check instead of direct dict indexing with equality comparison.At line 409, directly accessing
["matomo"]with== Trueis non-idiomatic (Ruff E712) and risksKeyErrorif the key is absent. The suggested.get("matomo")approach is safer and more Pythonic. This pattern should be applied consistently to the other analytics checks at lines 398 and 403 as well.✅ Suggested patch
🧰 Tools
🪛 Ruff (0.15.5)
[error] 409-409: Avoid equality comparisons to
True; usest.session_state.tracking_consent["matomo"]:for truth checksReplace with
st.session_state.tracking_consent["matomo"](E712)
🤖 Prompt for AI Agents