Files
meshcore-bot/tests/unit/test_wx_wind_direction.py
agessaman 55e5f0eda3 fix(wx): show NOAA's 16-point wind directions instead of truncating them
abbreviate_wind_direction matched full words (NORTHWEST, NORTH, ...), but NOAA's forecast windDirection is always an abbreviation like WNW, SSE or N. Every value fell through to the fallback, which kept the first two characters behind a generic wind emoji, so replies read '💨WN2' or '💨SS1' and even plain N and NE lost their arrow. The 16 compass abbreviations now return the nearest 8-point arrow plus the abbreviation; full words and other values behave as before. Found while pinning wx's formatting on real NOAA responses for the maintainability refactor.
2026-10-01 15:53:04 -07:00

38 lines
1.2 KiB
Python

"""wx renders NOAA's 16-point wind abbreviations with an arrow instead of truncating them."""
import configparser
from unittest.mock import Mock
import pytest
from modules.commands.wx_command import WxCommand
def _wx():
config = configparser.ConfigParser()
config.read_dict({"Weather": {"weather_provider": "noaa"}, "Wx_Command": {}})
bot = Mock()
bot.config = config
return WxCommand(bot)
@pytest.mark.parametrize(
("noaa", "shown"),
[
("N", "⬆️N"), ("NNE", "↗️NNE"), ("NE", "↗️NE"), ("ENE", "➡️ENE"),
("E", "➡️E"), ("ESE", "↘️ESE"), ("SE", "↘️SE"), ("SSE", "⬇️SSE"),
("S", "⬇️S"), ("SSW", "↙️SSW"), ("SW", "↙️SW"), ("WSW", "⬅️WSW"),
("W", "⬅️W"), ("WNW", "↖️WNW"), ("NW", "↖️NW"), ("NNW", "⬆️NNW"),
("wnw", "↖️WNW"),
],
)
def test_noaa_abbreviations_keep_their_letters_and_gain_an_arrow(noaa, shown):
assert _wx().abbreviate_wind_direction(noaa) == shown
def test_full_words_and_unknown_values_are_unchanged():
wx = _wx()
assert wx.abbreviate_wind_direction("Northwest") == "↖️NW"
assert wx.abbreviate_wind_direction("") == ""
assert wx.abbreviate_wind_direction("calm") == "💨CA"