From 7c6102dc468a04edee8852ea54aa633090ee5ae4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A1=82=E9=A9=AC?= Date: Thu, 11 Jun 2026 13:41:57 +0800 Subject: [PATCH] Stabilize update checker version tests --- .../i18n/locales/de/LC_MESSAGES/messages.po | 2 +- .../i18n/locales/es/LC_MESSAGES/messages.po | 2 +- .../i18n/locales/fr/LC_MESSAGES/messages.po | 2 +- .../i18n/locales/ja/LC_MESSAGES/messages.po | 2 +- .../i18n/locales/pt/LC_MESSAGES/messages.po | 2 +- .../i18n/locales/zh/LC_MESSAGES/messages.po | 2 +- tests/services/test_update_checker.py | 53 ++++++++++++++++--- 7 files changed, 53 insertions(+), 12 deletions(-) diff --git a/src/iac_code/i18n/locales/de/LC_MESSAGES/messages.po b/src/iac_code/i18n/locales/de/LC_MESSAGES/messages.po index ffe90e6..46930d5 100644 --- a/src/iac_code/i18n/locales/de/LC_MESSAGES/messages.po +++ b/src/iac_code/i18n/locales/de/LC_MESSAGES/messages.po @@ -4,7 +4,7 @@ # msgid "" msgstr "" -"Project-Id-Version: iac-code 0.4.1\n" +"Project-Id-Version: iac-code 0.5.0\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2026-06-04 15:58+0800\n" "PO-Revision-Date: 2026-05-13 00:00+0000\n" diff --git a/src/iac_code/i18n/locales/es/LC_MESSAGES/messages.po b/src/iac_code/i18n/locales/es/LC_MESSAGES/messages.po index 25b55f6..9514cf5 100644 --- a/src/iac_code/i18n/locales/es/LC_MESSAGES/messages.po +++ b/src/iac_code/i18n/locales/es/LC_MESSAGES/messages.po @@ -4,7 +4,7 @@ # msgid "" msgstr "" -"Project-Id-Version: iac-code 0.4.1\n" +"Project-Id-Version: iac-code 0.5.0\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2026-06-04 15:58+0800\n" "PO-Revision-Date: 2026-05-13 00:00+0000\n" diff --git a/src/iac_code/i18n/locales/fr/LC_MESSAGES/messages.po b/src/iac_code/i18n/locales/fr/LC_MESSAGES/messages.po index d77cda0..7e92fbf 100644 --- a/src/iac_code/i18n/locales/fr/LC_MESSAGES/messages.po +++ b/src/iac_code/i18n/locales/fr/LC_MESSAGES/messages.po @@ -4,7 +4,7 @@ # msgid "" msgstr "" -"Project-Id-Version: iac-code 0.4.1\n" +"Project-Id-Version: iac-code 0.5.0\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2026-06-04 15:58+0800\n" "PO-Revision-Date: 2026-05-13 00:00+0000\n" diff --git a/src/iac_code/i18n/locales/ja/LC_MESSAGES/messages.po b/src/iac_code/i18n/locales/ja/LC_MESSAGES/messages.po index 45dc11f..832346e 100644 --- a/src/iac_code/i18n/locales/ja/LC_MESSAGES/messages.po +++ b/src/iac_code/i18n/locales/ja/LC_MESSAGES/messages.po @@ -4,7 +4,7 @@ # msgid "" msgstr "" -"Project-Id-Version: iac-code 0.4.1\n" +"Project-Id-Version: iac-code 0.5.0\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2026-06-04 15:58+0800\n" "PO-Revision-Date: 2026-05-13 00:00+0000\n" diff --git a/src/iac_code/i18n/locales/pt/LC_MESSAGES/messages.po b/src/iac_code/i18n/locales/pt/LC_MESSAGES/messages.po index b25e38a..ebd9b19 100644 --- a/src/iac_code/i18n/locales/pt/LC_MESSAGES/messages.po +++ b/src/iac_code/i18n/locales/pt/LC_MESSAGES/messages.po @@ -4,7 +4,7 @@ # msgid "" msgstr "" -"Project-Id-Version: iac-code 0.4.1\n" +"Project-Id-Version: iac-code 0.5.0\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2026-06-04 15:58+0800\n" "PO-Revision-Date: 2026-05-13 00:00+0000\n" diff --git a/src/iac_code/i18n/locales/zh/LC_MESSAGES/messages.po b/src/iac_code/i18n/locales/zh/LC_MESSAGES/messages.po index 98fd845..fa757a1 100644 --- a/src/iac_code/i18n/locales/zh/LC_MESSAGES/messages.po +++ b/src/iac_code/i18n/locales/zh/LC_MESSAGES/messages.po @@ -4,7 +4,7 @@ # msgid "" msgstr "" -"Project-Id-Version: iac-code 0.4.1\n" +"Project-Id-Version: iac-code 0.5.0\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2026-06-04 15:58+0800\n" "PO-Revision-Date: 2026-04-02 00:00+0000\n" diff --git a/tests/services/test_update_checker.py b/tests/services/test_update_checker.py index 60232fd..f280d4a 100644 --- a/tests/services/test_update_checker.py +++ b/tests/services/test_update_checker.py @@ -6,6 +6,7 @@ from threading import Event import httpx +import pytest import yaml from iac_code.services import update_checker @@ -24,11 +25,14 @@ suppress_version, ) +TEST_CURRENT_VERSION = "0.3.0" +SENTINEL_RUNNING_VERSION = "9999.0.0" + def _pending_update_data() -> dict[str, object]: return { "version": "0.4.0", - "current_version": "0.3.0", + "current_version": TEST_CURRENT_VERSION, "source": "official_pypi", "checked_at": 100.0, "update_command": ["/python", "-m", "pip", "install", "--upgrade", "iac-code"], @@ -55,6 +59,13 @@ def get(self, url: str) -> httpx.Response: return result +@pytest.fixture(autouse=True) +def _isolate_running_version(monkeypatch): + import iac_code + + monkeypatch.setattr(iac_code, "__version__", SENTINEL_RUNNING_VERSION) + + def _json_response(url: str, payload: object, status_code: int = 200) -> httpx.Response: return httpx.Response(status_code, json=payload, request=httpx.Request("GET", url)) @@ -800,7 +811,13 @@ def fail_run(*args, **kwargs): monkeypatch.setattr(update_checker.subprocess, "run", fail_run) - state = check_for_updates_once(path=path, http_client=http_client, now=1000.0, python_executable="/python") + state = check_for_updates_once( + path=path, + current_version=TEST_CURRENT_VERSION, + http_client=http_client, + now=1000.0, + python_executable="/python", + ) assert state.pending is not None assert state.pending.version == "0.5.0" @@ -836,7 +853,13 @@ def fail_run(*args, **kwargs): monkeypatch.setattr(update_checker.subprocess, "run", fail_run) - state = check_for_updates_once(path=path, http_client=http_client, now=1000.0, python_executable="/python") + state = check_for_updates_once( + path=path, + current_version=TEST_CURRENT_VERSION, + http_client=http_client, + now=1000.0, + python_executable="/python", + ) assert state.pending is not None assert state.pending.version == "0.5.0" @@ -915,7 +938,13 @@ def fail_run(*args, **kwargs): monkeypatch.setattr(update_checker.subprocess, "run", fail_run) - state = check_for_updates_once(path=path, http_client=http_client, now=1000.0, python_executable="/python") + state = check_for_updates_once( + path=path, + current_version=TEST_CURRENT_VERSION, + http_client=http_client, + now=1000.0, + python_executable="/python", + ) assert state.pending is not None assert state.pending.version == "0.5.0" @@ -987,7 +1016,13 @@ def fake_run(*args, **kwargs): monkeypatch.setattr(update_checker.subprocess, "run", fake_run) - state = check_for_updates_once(path=path, http_client=http_client, now=1000.0, python_executable="/python") + state = check_for_updates_once( + path=path, + current_version=TEST_CURRENT_VERSION, + http_client=http_client, + now=1000.0, + python_executable="/python", + ) assert state.pending is not None assert state.pending.version == "100.0.0" @@ -1186,7 +1221,13 @@ def fake_run(*args, **kwargs): monkeypatch.setattr(update_checker.subprocess, "run", fake_run) - state = check_for_updates_once(path=path, http_client=http_client, now=1000.0, python_executable="/python") + state = check_for_updates_once( + path=path, + current_version=TEST_CURRENT_VERSION, + http_client=http_client, + now=1000.0, + python_executable="/python", + ) assert state.pending is None assert state.last_successful_check_at == 1000.0