mirror of
https://github.com/agessaman/meshcore-bot.git
synced 2026-11-03 11:32:37 +00:00
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.
38 lines
1.2 KiB
Python
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"
|