diff --git a/tests/test_diary_import.py b/tests/test_diary_import.py index 84b5881..8f967db 100644 --- a/tests/test_diary_import.py +++ b/tests/test_diary_import.py @@ -5,6 +5,7 @@ Covers: - /api/graph/import-diary streaming endpoint (requires flask) """ +import importlib.util import json import sqlite3 import sys @@ -21,8 +22,17 @@ _MOCK_MODULES = [ "requests", "requests.exceptions", "psutil", ] +def _is_installed(name): + # Mock only what is missing: a MagicMock left in sys.modules for an + # installed PyQt6 breaks every later test file that imports the real one. + try: + return importlib.util.find_spec(name) is not None + except (ImportError, ValueError): + return False + + for _mod in _MOCK_MODULES: - if _mod not in sys.modules: + if _mod not in sys.modules and not _is_installed(_mod): sys.modules[_mod] = MagicMock() # Ensure requests.exceptions.Timeout is a proper exception class diff --git a/tests/test_engine_hot_window_caches.py b/tests/test_engine_hot_window_caches.py index 0f211ba..0fe51ac 100644 --- a/tests/test_engine_hot_window_caches.py +++ b/tests/test_engine_hot_window_caches.py @@ -139,7 +139,7 @@ def test_router_fallback_to_all_tools_is_not_cached( @patch("src.jarvis.memory.graph_ops.format_warm_profile_block", return_value="") @patch("src.jarvis.memory.graph_ops.build_warm_profile", return_value={"user": "", "directives": ""}) @patch("src.jarvis.memory.graph.GraphMemoryStore") -@patch("src.jarvis.reply.engine.select_tools", return_value=[]) +@patch("src.jarvis.reply.engine.select_tools", return_value=["webSearch"]) @patch("src.jarvis.reply.engine.plan_query", return_value=[]) @patch("src.jarvis.reply.engine.extract_search_params_for_memory", return_value={"keywords": ["x"], "questions": []}) @patch("src.jarvis.memory.conversation.search_conversation_memory_by_keywords", return_value=[]) @@ -154,7 +154,8 @@ def test_memory_extractor_cached_across_turns( The recall gate would also fire on a tool-grounded follow-up, so we keep the dialogue free of tool messages here to exercise the extractor - path on both turns. + path on both turns. The router routes a data tool, because a turn with + no data tool takes the conversational fast-path and skips enrichment. """ mock_chat.side_effect = [ {"message": {"content": "first"}}, diff --git a/tests/tools/builtin/test_weather.py b/tests/tools/builtin/test_weather.py index 4c5c2e7..32f3daf 100644 --- a/tests/tools/builtin/test_weather.py +++ b/tests/tools/builtin/test_weather.py @@ -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: