"""Prevent non-Russian, non-English help falling back to English again.""" from __future__ import annotations import json import unittest from pathlib import Path from app.core.help_content import HELP, get_help_sections ROOT = Path(__file__).resolve().parents[1] LANGUAGES = ('de', 'fr', 'it', 'es', 'pl') class HelpTranslationTests(unittest.TestCase): def test_all_five_help_dictionaries_loaded(self): original = get_help_sections('en') for language in LANGUAGES: with self.subTest(language=language): file = ROOT/'app/core/help_locales'/f'{language}.json' self.assertTrue(file.is_file()) data = json.loads(file.read_text(encoding='utf8')) self.assertEqual(data, get_help_sections(language)) self.assertEqual(len(data),len(original)) self.assertEqual([s['id'] for s in data], [s['id'] for s in original]) self.assertNotEqual(data[0]['title'], original[0]['title']) self.assertNotEqual(data[0]['topics'][0]['paragraphs'][0],original[0]['topics'][0]['paragraphs'][0]) for section, ref_section in zip(data, original): self.assertTrue(section['title'].strip()) self.assertTrue(section['intro'].strip()) self.assertEqual(len(section['topics']),len(ref_section['topics'])) for topic, reference in zip(section['topics'],ref_section['topics']): self.assertTrue(topic['title'].strip()) self.assertTrue(all(x.strip() for x in topic['paragraphs'])) self.assertEqual(bool(topic['example_lines']),bool(reference['example_lines'])) self.assertEqual(bool(topic['warning']),bool(reference['warning'])) # Common technical terms such as Diagnostics can legitimately match English. self.assertNotEqual(topic['paragraphs'][0],reference['paragraphs'][0],"untranslated help paragraph") self.assertTrue(all(x.strip() for x in topic['bullets'])) def test_unknown_language_defaults_to_english(self): self.assertEqual(get_help_sections('non-existent-language'), HELP['en']) def test_version(self): self.assertEqual((ROOT/'VERSION').read_text().strip(),'1.0.2') if __name__ == '__main__': unittest.main()