Skip to content

Add coverage tests for mainApp, Landing_page and Bin_Phase_env (71% -> 79%) - #146

Merged
Koyandechirag merged 1 commit into
FOSSEE:masterfrom
riteshtummalawork:tests/mainapp-landing-binphase
Nov 15, 2026
Merged

Koyandechirag merged 1 commit into
FOSSEE:masterfrom
riteshtummalawork:tests/mainapp-landing-binphase

Conversation

@riteshtummalawork

Copy link
Copy Markdown

Summary

Adds unit tests for the remaining low-coverage modules mainApp.py, Landing_page.py and utils/Bin_Phase_env.py. No application code is changed.

Module Before After
mainApp.py 53% 99%
Landing_page.py 66% 97%
utils/Bin_Phase_env.py 73% 100%
Overall 71% 79%

Full suite: 470 passed on 3 runs (Windows, Python 3.13, QT_QPA_PLATFORM=offscreen), measured with the same --cov=src/main/python command as the CI workflow.

What's covered

tests/test_main_app.py (+74 tests)

  • DragButtonFilter / DropFilter: a press followed by a long or short move, the drag carrying the component type, drop creating the component at the mapped scene position, non-text drags ignored.
  • component(): compounds required; MaterialStream gets the selected compounds; unknown types ignored; drop position used; click-to-add grid (5 per row, 180px apart, wrapping 150px down); the fallback positioning path when add_unit_operation returns None.
  • new() / new_file() / new_project(): counters, dock widgets, compounds and container reset, one initial Undo snapshot, deleted dock widgets skipped, errors reported; Save / Don't Save / Cancel, including a cancelled Save As.
  • Undo/redo: canvas restored and re-applied, initial state, empty history, error handling, undo_redo_helper.
  • Save/open: a real save → new → open round trip that checks the components come back; Save As cancelled; canvas not capturable; unwritable path; open via dialog, cancelled, unsupported format, corrupt file, saved results shown; _legacy_sim_to_snapshot (items, positions, compounds, rebuilt connections).
  • Simulation: thread started with the mode, project .mo found or missing, start failure unlocks the UI, terminate() (omc process, async exception, revert when more than one thread was affected), closeEvent.
  • Panel collapse/expand, Binary Phase Envelope guard, selected-compounds panel, Delete/Backspace handling, and the module-level select_compounds.

tests/test_landing_page.py (+28 tests)

Preload (success and failure); start simulation via its timer; compound selector shown and landing page restored when the main window closes; _cleanup_main_window stashing old windows and clearing the Graphics lists (including error paths); opening a project, with the delayed canvas fit, empty projects, fit errors, open failures and the preloaded window stashed; IntroPage handlers; fit_canvas; restoring and draining override cursors; closeEvent; the About window; run().

tests/test_bin_phase_env.py (+32 tests)

Thermo package fallback when thermopackage.txt is missing; mode switching detaching the old inputs; every validation message; OMC lookup via OPENMODELICAHOME (omc and omc.exe), the Windows glob and default path, and the Linux /opt/local, plus not found; the generated Graph.mo/PlotGraph.mos content; OMC not found or failing to launch (cwd restored); the error summary; empty or unusable result CSVs; unparseable values skipped; numbered plot tabs and axis labels; the plot's mouse-move and hover handlers; temporary files removed.

Test hygiene

  • Modal dialogs (QMessageBox.about/critical/warning, exec_(), file dialogs) are always patched, so nothing can block a headless CI run.
  • No real simulation threads or OpenModelica processes are started.
  • Undo/redo files go to a temporary folder rather than Simulator/undo_redo.
  • Each test's MainApp window is destroyed in tearDown. Leaving the windows alive made test_main_app.py take over 3 minutes, because each new window restyles every existing one; with cleanup it takes about 37s.

Note

The remaining uncovered lines are Landing_page.py's if __name__ == "__main__" block and import fallback, and one line in mainApp.py. I also noticed that DragButtonFilter ignores a drag that starts at exactly (0, 0) on the button, because QPoint(0, 0) is falsy. It's harmless, so I left it unchanged.

🤖 Generated with Claude Code

Raises overall coverage from 71% to 79%:
- mainApp.py 53% -> 99%: drag/drop filters, component placement grid
  and fallback, new/new_file/new_project, undo/redo, save/open round
  trip, legacy .sim conversion, simulate/terminate, closeEvent.
- Landing_page.py 66% -> 97%: preload, start/open project flows and
  errors, window stashing, delayed canvas fit, IntroPage handlers,
  fit_canvas, close, About and run().
- Bin_Phase_env.py 73% -> 100%: input validation, OMC lookup on
  Windows/Linux, OMC failures, empty/bad results, temp file cleanup
  and plot mouse handlers.

Tests never open real modal dialogs or start simulation threads, keep
undo/redo files in a temporary folder, and destroy each MainApp window
in tearDown so the suite stays fast. No application code changed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Koyandechirag
Koyandechirag merged commit 4e14785 into FOSSEE:master Nov 15, 2026
1 check passed
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.

3 participants