LichessStatTgWeb/tests/bot/test_i18n.py
vrubelroman df6b582376 iteration 1: report with game table, /getgamers state screen, silent-30-days prompt, /today as one message, stats port bound to localhost
- periodic report rebuilt in HTML: title with games count, mode lines, one <pre>
  table (± · colour · accuracy · opponent rating · opponent accuracy), 10-row cap,
  span note after catch-up; stats service returns tracked_rating_diff per game
- /getgamers shows player state from the DB (played today / N days quiet /
  closed / not found, report period) without Lichess calls; ratings on a button
- "player silent 30 days — keep?" prompt with keep/delete buttons, repeat 90 days
- /today, /yesterday, /week: one message edited into the result, nav buttons
- /year localised; active-gamer leftovers and N/A removed; one period wording
- docker-compose.prod.yml: stats port 8002 bound to 127.0.0.1
- product review docs: user journeys, concepts, Mini App feasibility, proposal

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

96 lines
4.9 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""i18n: format_period / format_count / format_day 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 datetime import date
from i18n import TRANSLATIONS, format_count, format_day, format_day_range, format_period, t
class FormatPeriodTests(unittest.TestCase):
def test_table(self):
cases = [
(0, 'ru', "🔕 отчёты выключены"),
(0, 'en', "🔕 reports off"),
(15, 'en', "every 15 min"),
(30, 'ru', "раз в 30 мин"),
(60, 'en', "every hour"),
(60, 'ru', "раз в час"),
(120, 'en', "every 2 h"),
(120, 'ru', "раз в 2 ч"),
(180, 'ru', "раз в 3 ч"),
(360, 'ru', "раз в 6 ч"),
(720, 'ru', "раз в 12 ч"),
(1440, 'en', "every day"),
(1440, 'ru', "раз в день"),
(2880, 'ru', "раз в 2 дн"),
(2880, 'en', "every 2 d"),
(90, 'ru', "раз в 90 мин"), # not a whole number of hours
(60, 'xx', "every 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 FormatCountTests(unittest.TestCase):
def test_games_days_hours(self):
cases = [
(1, 'games', 'ru', "1 партия"), (2, 'games', 'ru', "2 партии"), (5, 'games', 'ru', "5 партий"),
(11, 'games', 'ru', "11 партий"), (14, 'games', 'ru', "14 партий"), (21, 'games', 'ru', "21 партия"),
(22, 'games', 'ru', "22 партии"), (111, 'games', 'ru', "111 партий"),
(1, 'games', 'en', "1 game"), (2, 'games', 'en', "2 games"),
(1, 'days', 'ru', "1 день"), (3, 'days', 'ru', "3 дня"), (12, 'days', 'ru', "12 дней"), (31, 'days', 'ru', "31 день"),
(30, 'days', 'en', "30 days"), (1, 'days', 'en', "1 day"),
(1, 'hours', 'ru', "1 час"), (6, 'hours', 'ru', "6 часов"), (23, 'hours', 'ru', "23 часа"),
(6, 'hours', 'en', "6 hours"),
]
for n, what, lang, expected in cases:
with self.subTest(n=n, what=what, lang=lang):
self.assertEqual(expected, format_count(n, what, lang))
class FormatDayTests(unittest.TestCase):
TODAY = date(2026, 10, 21)
def test_day_and_range(self):
self.assertEqual("21 октября", format_day(self.TODAY, 'ru', self.TODAY))
self.assertEqual("21 October", format_day(self.TODAY, 'en', self.TODAY))
self.assertEqual("21 сентября", format_day(date(2026, 9, 21), 'ru', self.TODAY))
self.assertEqual("21 сентября 2025", format_day(date(2025, 9, 21), 'ru', self.TODAY)) # another year
self.assertEqual("15–21 октября", format_day_range(date(2026, 10, 15), self.TODAY, 'ru', self.TODAY))
self.assertEqual("28 сентября – 4 октября", format_day_range(date(2026, 9, 28), date(2026, 10, 4), 'ru', self.TODAY))
self.assertEqual("15–21 October", format_day_range(date(2026, 10, 15), self.TODAY, 'en', self.TODAY))
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"))
def test_removed_keys_are_gone(self):
for key in ('period_notification_title', 'game_type_header', 'game_rows_heading', 'period_puzzles_section',
'stat_label_rating', 'stat_label_wins', 'stat_label_losses', 'stat_label_draws',
'period_1_minute', 'period_2_3_4_minutes', 'period_minutes_text', 'period_hours_text',
'period_days_text', 'active_gamer_deleted', 'active_gamer_set', 'select_active_gamer',
'loading_ratings', 'gamers_closed_legend', 'gamers_not_found_legend', 'period_minutes_suffix',
'puzzles_section', 'stats_player_processing', 'period_set', 'period_minutes',
'period_label_minutes', 'period_label_hour', 'period_label_hours'):
self.assertNotIn(key, TRANSLATIONS['en'], key)
self.assertNotIn(key, TRANSLATIONS['ru'], key)
def test_unknown_key_returns_key(self):
self.assertEqual('no_such_key', t('no_such_key', 'ru'))
if __name__ == '__main__':
unittest.main()