Files
meshcore-bot/tests/unit/test_weather_location_logging.py
agessaman 5601a126dd refactor(weather): port the behavior-neutral weather refactor from refactor/maintainability
This brings the weather slices of my long-running refactor branch to dev ahead of converging wx and gwx, so the convergence PRs build on one copy of the code instead of rewriting it twice.

- `modules/weather_common.py` (WeatherCommandMixin): code wx and gwx shared by copy (MQTT and WXSIM source lookup, multi-day sending, high/low formatting, the forecast-option parser, the Open-Meteo model loader).
- `modules/nws_alerts.py`: one NWS alert entry parser for wx and the weather service, keeping each caller's own Special Weather Statement rules.
- `modules/http_retry.py`: one retrying session builder for the weather HTTP clients.
- wx: get_noaa_weather, the hourly, tomorrow and multi-day formatters, _add_period_details and the extract_* readers broken up or made table-driven; NOAA fetches go through `_noaa_fetch`.
- gwx: one fetch path; `_open_meteo_current` and `_open_meteo_daily_tail` split out of get_open_meteo_weather.
- solarforecast: `_format_forecast` built from one timestamp parser and one day builder (418 → 155 lines).
- aurora, rain, wx, gwx: companion and bot location lookups through `modules.location` (which gains optional logging arguments).

The changes outside these files that the refactor branch made (the base command's enabled_attr hook, the service base's run_periodic and _cancel_tasks) stay out: aurora and rain keep their can_execute overrides and the weather service its own loops, exactly as on dev.

Tests: characterization goldens over real captured NOAA, NWS, Open-Meteo and forecast.solar responses (tests/characterization, fixtures in tests/fixtures), 50 tests and several hundred cases, all of which also pass against dev's unmodified weather code. Each refactor step was additionally checked on the branch with an old-vs-new differential run (tens of thousands of generated inputs, including log calls and exceptions) and reviewed by codex.
2026-10-01 21:11:23 -07:00

24 lines
875 B
Python

"""wx and gwx keep logging companion-location lookup failures at WARNING."""
from unittest.mock import MagicMock
import pytest
from modules.models import MeshMessage
@pytest.mark.parametrize("which", ["wx", "gwx"])
def test_companion_lookup_error_is_a_warning(which):
if which == "wx":
from modules.commands.wx_command import WxCommand as cls
else:
from modules.commands.alternatives.wx_international import GlobalWxCommand as cls
cmd = object.__new__(cls)
cmd.bot = MagicMock()
cmd.bot.db_manager.execute_query.side_effect = RuntimeError("database is locked")
cmd.logger = MagicMock()
msg = MeshMessage(content="wx", sender_id="Ann", sender_pubkey="ab" * 32)
assert cmd._get_companion_location(msg) is None
cmd.logger.warning.assert_called_once()
assert "database is locked" in cmd.logger.warning.call_args[0][0]