LichessStatTgWeb/tests/bot/test_i18n.py
vrubelroman a7571f13c1
All checks were successful
CI/CD Pipeline / build-and-deploy (push) Successful in 16s
v1.5.1: not-found players paused, tests in repo + CI, log-based daily summary, docs pruned
- players absent from two consecutive bulk answers (deleted/renamed on Lichess) are paused
  like closed accounts with their own notice; ❓ mark; stats service answers 404 instead
  of "0 games" for unknown users
- /getgamers table stays unmarked, a legend line under it lists closed / not-found players
- daily SUMMARY is computed from events.log (survives restarts); lichess_429 comes from the
  stats service /health, which now exposes lichess_429_24h / lichess_429_total
- admin /status reads its numbers through Database.get_admin_stats
- tests/: 36 bot + 15 service unittest cases, run_tests.sh runs them inside the real images,
  CI runs them after the build and before pushing/deploying
- docs: USER_GUIDE/about/API_DOCUMENTATION rewritten for the current code, ARCHITECTURE.md and
  two sub-READMEs removed, 7 obsolete helper scripts removed, CURRENT_STATE updated
- .claude/agents/designer.md: Telegram-aware designer role

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-21 02:48:00 +00:00

54 lines
2.1 KiB
Python

"""i18n: format_period in both languages, and the two dictionaries have the same keys."""
from tests.bot import _env # noqa: F401 (environment before bot imports)
import unittest
from i18n import TRANSLATIONS, format_period, t
class FormatPeriodTests(unittest.TestCase):
def test_table(self):
cases = [
(15, 'en', "15 minutes"),
(30, 'ru', "30 минут"),
(60, 'en', "1 hour"),
(60, 'ru', "1 час"),
(120, 'en', "2 hours"),
(120, 'ru', "2 часа"),
(180, 'ru', "3 часа"),
(360, 'ru', "6 часов"),
(720, 'ru', "12 часов"),
(1440, 'en', "24 hours"),
(1440, 'ru', "24 часа"),
(60 * 21, 'ru', "21 час"),
(60 * 11, 'ru', "11 часов"),
(60, 'xx', "1 hour"), # unknown language falls back to English
]
for minutes, lang, expected in cases:
with self.subTest(minutes=minutes, lang=lang):
self.assertEqual(expected, format_period(minutes, lang))
class KeyParityTests(unittest.TestCase):
def test_every_en_key_has_a_ru_translation(self):
missing = set(TRANSLATIONS['en']) - set(TRANSLATIONS['ru'])
self.assertEqual(set(), missing)
def test_every_ru_key_exists_in_en(self):
extra = set(TRANSLATIONS['ru']) - set(TRANSLATIONS['en'])
self.assertEqual(set(), extra)
def test_new_status_keys_format(self):
for lang in ('en', 'ru'):
self.assertIn("Magnus", t('gamer_account_not_found', lang, username="Magnus"))
self.assertIn("Magnus", t('gamer_account_closed', lang, username="Magnus"))
self.assertTrue(t('gamers_closed_legend', lang, names="A, B").startswith("⛔"))
self.assertTrue(t('gamers_not_found_legend', lang, names="A").startswith("❓"))
self.assertIn("A, B", t('gamers_closed_legend', lang, names="A, B"))
def test_unknown_key_returns_key(self):
self.assertEqual('no_such_key', t('no_such_key', 'ru'))
if __name__ == '__main__':
unittest.main()