Enhance app functionality with JSON input handling and improved findings rendering. Added new sample reports and updated existing ones for better testing coverage. Refactored findings display to an HTML panel for clarity.
2b7e0fd | """Tests for normalizing real-world JSON exports into the checker's schema.""" | |
| import os | |
| import sys | |
| sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) | |
| from mapping import normalize_report # noqa: E402 | |
| # A trimmed version of a real DB query export (wrapper + source field names). | |
| DB_EXPORT = { | |
| "select * from `datalog-temp` dt limit 1": [ | |
| { | |
| "VESSEL_NAME": "MARITIME EXPLORER", | |
| "REPORT_DATE": "2025-10-01 12:00:00", | |
| "OBSERVERD_DISTANCE": 312, | |
| "SPEED": 13.0, | |
| "STEAMING_TIME_HRS": 24.0, | |
| "ME_CONSUMPTION": 25.0, | |
| "AE_CONSUMPTION": 2.2, | |
| "ROB_VLSFO": 582.5, | |
| "ROB_HSFO": 10.0, | |
| "ROB_LSMGO": 161.7, | |
| "ROB_MDO": 5.0, | |
| "WINDFORCE": 7, | |
| "MERPM": 99.0, | |
| "DRAFTFWD": 7.75, | |
| "DRAFTAFT": 8.36, | |
| } | |
| ] | |
| } | |
| def test_unwraps_and_maps_core_fields(): | |
| r = normalize_report(DB_EXPORT) | |
| assert r["vessel_name"] == "MARITIME EXPLORER" | |
| assert r["distance_run"] == 312 | |
| assert r["avg_speed"] == 13.0 | |
| assert r["steaming_hours"] == 24.0 | |
| assert r["me_fo_cons"] == 25.0 | |
| assert r["ae_fo_cons"] == 2.2 | |
| assert r["rpm_avg"] == 99.0 | |
| assert r["wind_force"] == 7 | |
| assert r["draft_fwd"] == 7.75 and r["draft_aft"] == 8.36 | |
| def test_sums_grade_level_rob(): | |
| r = normalize_report(DB_EXPORT) | |
| assert r["fo_rob"] == 592.5 # VLSFO 582.5 + HSFO 10.0 | |
| assert r["do_rob"] == 166.7 # LSMGO 161.7 + MDO 5.0 | |
| def test_canonical_dict_passes_through(): | |
| canon = {"steaming_hours": 24.0, "distance_run": 300, "avg_speed": 12.5} | |
| r = normalize_report(canon) | |
| assert r["steaming_hours"] == 24.0 | |
| assert r["distance_run"] == 300 | |
| assert r["avg_speed"] == 12.5 | |
| def test_unrecognisable_returns_empty(): | |
| assert normalize_report({"foo": 1, "bar": {"baz": 2}}) == {} | |