def test_ValidEnglishLangNamesAreReturned(self): """Smoke tests `languageHandler.englishLanguageNameFromNVDALocale` with some known locale names""" self.assertEqual(languageHandler.englishLanguageNameFromNVDALocale("en"), "English") self.assertEqual(languageHandler.englishLanguageNameFromNVDALocale("de"), "German") self.assertEqual(languageHandler.englishLanguageNameFromNVDALocale("ne"), "Nepali") self.assertEqual(languageHandler.englishLanguageNameFromNVDALocale("pt-BR"), "Portuguese") self.assertEqual(languageHandler.englishLanguageNameFromNVDALocale("de_CH"), "German")
def test_noLangNameFromUnknownLocale(self): """Smoke tests `languageHandler.englishLanguageNameFromNVDALocale` with locale names unknown to Windows""" self.assertIsNone( languageHandler.englishLanguageNameFromNVDALocale("an")) self.assertIsNone( languageHandler.englishLanguageNameFromNVDALocale("kmr"))
def test_englishLanguageNameFromNVDALocaleNonASCIILangNames(self): """Ensures that `languageHandler.englishLanguageNameFromNVDALocale` can deal with non ASCII language names returned from Windows.""" self.assertEqual( languageHandler.englishLanguageNameFromNVDALocale("nb"), "Norwegian") self.assertEqual( languageHandler.englishLanguageNameFromNVDALocale("nb_NO"), "Norwegian")
def test_NVDASupportedAndPythonSupportedLocale_LanguageCodeMatches(self): """ Tests all the translatable languages that NVDA shows in the user preferences excludes the locales that python doesn't support, as the expected behaviour is different. """ for localeName in TRANSLATABLE_LANGS - UNSUPPORTED_WIN_LANGUAGES: with self.subTest(localeName=localeName): languageHandler.setLocale(localeName) current_locale = locale.setlocale(locale.LC_ALL) # check that the language codes are correctly set for python # They can be set to the exact locale that was requested, to the locale gotten # from the language name if language_country cannot be set # or just to English name of the language. lang_country = languageHandler.localeStringFromLocaleCode(localeName) possibleVariants = {lang_country} if "65001" in lang_country: # Python normalizes Unicode Windows code page to 'utf8' possibleVariants.add(lang_country.replace("65001", "utf8")) if "_" in lang_country: possibleVariants.add(languageHandler.localeStringFromLocaleCode(localeName.split("_")[0])) possibleVariants.add(languageHandler.englishLanguageNameFromNVDALocale(localeName)) self.assertIn( current_locale, possibleVariants, f"full values: {localeName} {current_locale}", )
def test_NVDASupportedLanguages_LanguageIsSetCorrectly(self): """ Tests languageHandler.setLanguage, using all NVDA supported languages, which should do the following: - set the translation service and languageHandler.curLang - set the windows locale for the thread (fallback to system default) - set the python locale for the thread (match the translation service, fallback to system default) """ for localeName in TRANSLATABLE_LANGS: with self.subTest(localeName=localeName): langOnly = localeName.split("_")[0] languageHandler.setLanguage(localeName) # check curLang/translation service is set self.assertEqual(languageHandler.curLang, localeName) # check Windows thread is set threadLocale = ctypes.windll.kernel32.GetThreadLocale() threadLocaleName = languageHandler.windowsLCIDToLocaleName( threadLocale) threadLocaleLang = threadLocaleName.split("_")[0] if localeName in UNSUPPORTED_WIN_LANGUAGES: # our translatable locale isn't supported by windows # check that the system locale is unchanged self.assertEqual(self._defaultThreadLocaleName, threadLocaleName) else: # check that the language codes are correctly set for the thread self.assertEqual( langOnly, threadLocaleLang, f"full values: {localeName} {threadLocaleName}", ) # check that the python locale is set python_locale = locale.setlocale(locale.LC_ALL) if localeName in UNSUPPORTED_WIN_LANGUAGES: # our translatable locale isn't supported by python # check that the system locale is unchanged self.assertEqual(self._defaultPythonLocale, python_locale) else: # check that the language codes are correctly set for python # They can be set to the exact locale that was requested, to the locale gotten # from the language name if language_country cannot be set # or just to English name of the language. lang_country = languageHandler.localeStringFromLocaleCode( localeName) possibleVariants = {lang_country} if "65001" in lang_country: # Python normalizes Unicode Windows code page to 'utf8' possibleVariants.add( lang_country.replace("65001", "utf8")) if "_" in lang_country: possibleVariants.add( languageHandler.localeStringFromLocaleCode( localeName.split("_")[0])) possibleVariants.add( languageHandler.englishLanguageNameFromNVDALocale( localeName)) self.assertIn( locale.setlocale(locale.LC_ALL), possibleVariants, f"full values: {localeName} {python_locale}")