Skip to content

Refactor: modernize helper_methods + port Mainsail layer formulas to jobStatusPage#208

Draft
gmmcosta15 wants to merge 2 commits intodevfrom
refactor/helper-methods
Draft

Refactor: modernize helper_methods + port Mainsail layer formulas to jobStatusPage#208
gmmcosta15 wants to merge 2 commits intodevfrom
refactor/helper-methods

Conversation

@gmmcosta15
Copy link
Copy Markdown
Collaborator

@gmmcosta15 gmmcosta15 commented Apr 13, 2026

Description

  • Feature
  • Bug fix
  • Code refactor
  • Documentation

Refactors helper_methods.py and jobStatusPage.py, and adds a full unit test suite for JobStatusWidget.

jobStatusPage.py

  • _VALID_STATES / _INVALID_STATES -> frozenset class constants (avoid per-call realloc)
  • on_gcode_move_update - 7 individual guards collapsed into one compound or guard
  • on_print_stats_update - if/if -> if/elif chains (mutually exclusive branches)
  • _post_event helper - DRY up duplicated QApplication.postEvent pattern
  • _load_thumbnails - manual loop -> walrus list comprehension
  • Removed no-op QPixmap.scaled() to identical dimensions
  • Removed spurious self.show() on thumbnail collapse

helper_methods.py

  • Mainsail layer formula extracted to calculate_current_layer / calculate_max_layers
  • jobStatusPage updated to call the new helpers

tests/widgets/test_job_status_page_unit.py - 40 unit tests

  • TestOnPrintStart (4), TestHandlePrintState (7), TestOnPrintStatsUpdate (6)
  • TestOnGcodeMoveUpdate (8), TestVirtualSdcardUpdate (3)
  • TestPauseResumePrint (6), TestHandleCancel (4), TestOnFileInfo (5)

tests/widgets/conftest.py

  • Ensures BlocksScreen/ on sys.path for lib.* imports
  • Clears empty lib.* namespace stubs registered by the network conftest so widget tests can coexist in the full make test-fast run

Motivation

The refactors reduce duplicated code and allocation overhead in the hottest print-progress paths. The test suite documents the expected slot behaviour and will catch regressions in the state machine, signal wiring, and layer-calculation logic.

Tests

Widget tests alone: 40 passed

@gmmcosta15 gmmcosta15 requested a review from HugoCLSC April 13, 2026 09:41
@gmmcosta15 gmmcosta15 self-assigned this Apr 13, 2026
@gmmcosta15 gmmcosta15 marked this pull request as ready for review April 13, 2026 09:41
@gmmcosta15 gmmcosta15 marked this pull request as draft April 13, 2026 12:59
@gmmcosta15 gmmcosta15 marked this pull request as draft April 13, 2026 12:59
- 40 unit tests across 8 test classes covering all public slots: on_print_start, _handle_print_state, on_print_stats_update, on_gcode_move_update, virtual_sdcard_update, pause_resume_print, handleCancel, on_fileinfo
- tests/widgets/conftest.py: fix cross-suite isolation (clears empty lib.* stubs registered by network conftest, ensures BlocksScreen/on sys.path)
- jobStatusPage: frozenset class constants, compound guard, if/elif chains, _post_event helper, walrus list comprehension, removed no-op QPixmap.scaled, removed spurious show() on collapse
@gmmcosta15 gmmcosta15 marked this pull request as ready for review April 13, 2026 16:42
@gmmcosta15 gmmcosta15 marked this pull request as draft April 13, 2026 16:43
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.

1 participant