test: bring stale weather, enrichment cache and diary import tests up to date
- Weather: the tool deliberately returns one Korean sentence about now
(c522e1b), so the tests check the place, condition, rounded temperature and
feels-like, and that no forecast, Fahrenheit or degree sign is left for the
model to echo.
- Enrichment cache: the conversational fast-path skips enrichment when no
data tool is routed, so the test routes one to reach the extractor.
- Diary import: mock PyQt6, requests and psutil only when they are not
installed. The MagicMock left in sys.modules for an installed PyQt6 broke
every later GUI test file in the same run.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -7,6 +7,7 @@ import requests
|
||||
from src.jarvis.tools.builtin.weather import (
|
||||
WeatherTool,
|
||||
WMO_CODES,
|
||||
WMO_CODES_KO,
|
||||
_extract_place_from_user_text,
|
||||
_romanise_place,
|
||||
)
|
||||
@@ -92,13 +93,12 @@ class TestWeatherTool:
|
||||
|
||||
assert isinstance(result, ToolExecutionResult)
|
||||
assert result.success is True
|
||||
# One ready-to-speak sentence: place, condition, rounded temperature
|
||||
# and the feels-like temperature when it differs after rounding.
|
||||
assert "London" in result.reply_text
|
||||
assert "15.5°C" in result.reply_text
|
||||
assert "Partly cloudy" in result.reply_text # WMO code 2
|
||||
assert "65%" in result.reply_text # humidity
|
||||
# Verify forecast sections are present
|
||||
assert "Today's forecast" in result.reply_text
|
||||
assert "7-day forecast" in result.reply_text
|
||||
assert WMO_CODES_KO[2] in result.reply_text
|
||||
assert str(round(15.5)) in result.reply_text
|
||||
assert str(round(14.0)) in result.reply_text
|
||||
self.context.user_print.assert_called()
|
||||
|
||||
@patch('src.jarvis.tools.builtin.weather._romanise_place')
|
||||
@@ -383,8 +383,9 @@ class TestWeatherTool:
|
||||
assert len(WMO_CODES) >= 20
|
||||
|
||||
@patch('requests.get')
|
||||
def test_forecast_includes_hourly_and_daily(self, mock_get):
|
||||
"""Test that forecast data includes today's hourly and 7-day daily sections."""
|
||||
def test_reply_is_current_conditions_only(self, mock_get):
|
||||
"""The reply is one sentence about now: the forecast the API returns is
|
||||
left out so a small model has nothing to ramble over."""
|
||||
geo_response = Mock()
|
||||
geo_response.status_code = 200
|
||||
geo_response.json.return_value = {
|
||||
@@ -429,21 +430,16 @@ class TestWeatherTool:
|
||||
result = self.tool.run({"location": "Tbilisi"}, self.context)
|
||||
|
||||
assert result.success is True
|
||||
# Current conditions
|
||||
assert "12" in result.reply_text
|
||||
assert "Slight rain" in result.reply_text
|
||||
# Hourly forecast for remaining hours (every 3 hours after hour 10)
|
||||
assert "Today's forecast" in result.reply_text
|
||||
assert "12:00" in result.reply_text
|
||||
assert "15:00" in result.reply_text
|
||||
# Daily forecast
|
||||
assert "7-day forecast" in result.reply_text
|
||||
assert "2026-04-09" in result.reply_text
|
||||
assert "2026-04-14" in result.reply_text
|
||||
assert str(round(12.0)) in result.reply_text
|
||||
assert WMO_CODES_KO[61] in result.reply_text
|
||||
assert "\n" not in result.reply_text.strip()
|
||||
assert "15:00" not in result.reply_text
|
||||
assert "2026-04-09" not in result.reply_text
|
||||
|
||||
@patch('requests.get')
|
||||
def test_temperature_conversion(self, mock_get):
|
||||
"""Test that both Celsius and Fahrenheit are shown."""
|
||||
def test_temperature_has_no_unit_for_the_model_to_echo(self, mock_get):
|
||||
"""Only the rounded Celsius number is given, with no °C/°F or
|
||||
Fahrenheit value a model could read out as "25도 Celsius"."""
|
||||
geo_response = Mock()
|
||||
geo_response.status_code = 200
|
||||
geo_response.json.return_value = {
|
||||
@@ -477,8 +473,9 @@ class TestWeatherTool:
|
||||
result = self.tool.run(args, self.context)
|
||||
|
||||
assert result.success is True
|
||||
assert "20" in result.reply_text # Celsius
|
||||
assert "68" in result.reply_text # Fahrenheit
|
||||
assert str(round(20.0)) in result.reply_text # Celsius
|
||||
assert str(round(20.0 * 9 / 5 + 32)) not in result.reply_text # Fahrenheit
|
||||
assert "°" not in result.reply_text
|
||||
|
||||
|
||||
class TestExtractPlaceFromUserText:
|
||||
|
||||
Reference in New Issue
Block a user