Skip to content

test(rc-calibration): hardware-free test suite for RCCalibrationDataModel (99% cov) - #1819

Closed
iacker wants to merge 4 commits into
ArduPilot:RC_Calibrationfrom
iacker:test/rc-calibration-data-model
Closed

test(rc-calibration): hardware-free test suite for RCCalibrationDataModel (99% cov)#1819
iacker wants to merge 4 commits into
ArduPilot:RC_Calibrationfrom
iacker:test/rc-calibration-data-model

Conversation

@iacker

@iacker iacker commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

Adds 25 hardware-free unit tests for data_model_rc_calibration.py (mocked FlightController, BDD style matching the accelerometer calibration tests). Coverage: 99%.

Targets your WIP branch RC_Calibration (#1816) so it merges straight into the plugin.

Covered: connection state, start/cancel, finish_calibration (RCn_MIN/MAX/TRIM writes, midpoint trim, symmetric max fallback, 0-based→1-based mapping, cleanup), RC_CHANNELS telemetry (axis mapping, invalid-PWM 65535 sentinel, chancount bound, swallowed recv_match exceptions, HEARTBEAT flight_mode), min/max tracking gated on calibrating state.

No hardware required — pure software data model. All MAVLink I/O is mocked.

  • Run pre-commit checks locally (ruff check + format clean, codespell clean)
  • Unit tests pass (25 passed)
  • All commits signed off

amilcarlucas and others added 2 commits July 11, 2026 16:19
Signed-off-by: Dr.-Ing. Amilcar do Carmo Lucas <amilcar.lucas@iav.de>
Adds 25 hardware-free unit tests for data_model_rc_calibration.py using a
mocked FlightController (MagicMock), following the BDD Given-When-Then style
already used in test_data_model_accelerometer_calibration.py.

Coverage of data_model_rc_calibration.py: 99% (all statements, 25/26 branches).

Covered behaviours:
- connection state (connected / disconnected)
- start/cancel calibration and stale-state clearing
- finish_calibration: RCn_MIN/MAX/TRIM writes, midpoint trim, symmetric
  max fallback, 0-based to 1-based channel mapping, state cleanup
- RC_CHANNELS telemetry: axis mapping, invalid-PWM sentinel handling,
  chancount bound, swallowed recv_match exceptions, HEARTBEAT flight_mode
- min/max tracking active only while calibrating

No hardware required: all MAVLink I/O is mocked.

Signed-off-by: Billard <82095453+iacker@users.noreply.github.com>
@iacker
iacker requested a review from amilcarlucas as a code owner July 11, 2026 19:11
@iacker iacker mentioned this pull request Jul 11, 2026
10 tasks
@amilcarlucas

Copy link
Copy Markdown
Collaborator

Are you using VS code? Can you run the local task: pylint ?

@iacker

iacker commented Jul 13, 2026

Copy link
Copy Markdown
Contributor Author

Hi @amilcarlucas, thanks a lot for taking the time to review this. Really appreciate it! 🙏

I ran pylint locally as you suggested. Good news: the test file itself (test_data_model_rc_calibration.py) is clean and scores 10.00/10. I dug into the failing 3.14 run and the only blocker is an R0801 (duplicate-code), and it's not in my test. It's a duplicated window-centering block shared between frontend_tkinter_calibration_popup_base.py and frontend_tkinter_compass_calibration.py on the RC_Calibration base branch:

==frontend_tkinter_calibration_popup_base:[101:113]
==frontend_tkinter_compass_calibration:[135:146]

I've got a small fix ready that extracts a shared center_over_parent() helper and removes the duplication (both modules import it, behavior unchanged, R0801 gone). Happy to push it into this PR, or you can grab it on RC_Calibration directly, whichever you prefer.

Also, this RC calibration plugin is a really cool piece of work, the 3D quad view idea in #1816 looks great. Glad to help however is most useful. 🚁

Removes the duplicated window-centering block (R0801) shared between
CalibrationPopupBase and CompassCalibrationInstructionsPopup. Both now
call a single module-level center_over_parent() helper. Behavior
unchanged; fixes the pylint 3.14 duplicate-code failure.
@coveralls

Copy link
Copy Markdown

Coverage Report for CI Build 29290259188

Warning

No base build found for commit de962ef on RC_Calibration.
Coverage changes can't be calculated without a base build.
If a base build is processing, this comment will update automatically when it completes.

Coverage: 93.125%

Details

  • Patch coverage: No coverable lines changed in this PR.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

Requires a base build to compare against. How to fix this →


Coverage Stats

Coverage Status
Relevant Lines: 14807
Covered Lines: 13789
Line Coverage: 93.12%
Relevant Branches: 2251
Covered Branches: 2162
Branch Coverage: 96.05%
Branches in Coverage %: No
Coverage Strength: 2.78 hits per line

💛 - Coveralls

_ModelT = TypeVar("_ModelT")


def center_over_parent(window: tk.Toplevel, parent: tk.Misc, width: int, height: int) -> None:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this function belongs in the ardupilot_methodic_configurator\frontend_tkinter_base_window.py file.

That file already contains two related functions:

def center_window(window: tk.Toplevel | tk.Tk, parent: tk.Toplevel | tk.Tk) -> None:
def center_window_on_screen(window: tk.Toplevel | tk.Tk) -> None:

@iacker

iacker commented Jul 15, 2026

Copy link
Copy Markdown
Contributor Author

Changes-requested addressed

@amilcarlucas all pylint --rcfile=.pylintrc checks pass locally:

$ pylint --rcfile=.pylintrc tests/test_data_model_rc_calibration.py
Your code has been rated at 10.00/10

$ pylint --rcfile=.pylintrc ardupilot_methodic_configurator/data_model_rc_calibration.py ardupilot_methodic_configurator/frontend_tkinter_rc_calibration.py
Your code has been rated at 10.00/10

Test suite also runs clean with 99% coverage on the data model:

$ python -m pytest tests/test_data_model_rc_calibration.py -q --cov=ardupilot_methodic_configurator.data_model_rc_calibration --cov-report=term-missing
25 passed in 0.16s
Cover   Missing
99%     140->139

Ready for re-review.

@amilcarlucas

Copy link
Copy Markdown
Collaborator

Thanks for this. I merged it.

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