def test_gettext_translations(mock_gettext_trans): """ API: Apprise() Gettext translations """ mock_gettext_trans.side_effect = IOError() # This throws internally but we handle it gracefully al = AppriseLocale.AppriseLocale() with al.lang_at('en'): # functions still behave as normal pass # This throws internally but we handle it gracefully AppriseLocale.AppriseLocale(language="fr")
def test_detect_language_defaultlocale(mock_getlocale): """ API: Apprise() Default locale detection """ # Handle case where getdefaultlocale() can't be detected mock_getlocale.return_value = None assert AppriseLocale.AppriseLocale.detect_language() is None # if detect_language and windows env fail us, then we don't # set up a default language on first load AppriseLocale.AppriseLocale()
def test_gettext_installs(mock_gettext_trans): """ API: Apprise() Gettext install """ mock_lang = mock.Mock() mock_lang.install.return_value = True mock_gettext_trans.return_value = mock_lang # This throws internally but we handle it gracefully al = AppriseLocale.AppriseLocale() with al.lang_at('en'): # functions still behave as normal pass # This throws internally but we handle it gracefully AppriseLocale.AppriseLocale(language="fr") # Force a few different languages al._gtobjs['en'] = mock_lang al._gtobjs['es'] = mock_lang al.lang = 'en' with al.lang_at('en'): # functions still behave as normal pass with al.lang_at('es'): # functions still behave as normal pass with al.lang_at('fr'): # functions still behave as normal pass
def test_gettext_init(mock_gettext_install): """ API: Mock Gettext init """ mock_gettext_install.side_effect = ImportError() # Test our fall back to not supporting translations reload(AppriseLocale) # Objects can still be created al = AppriseLocale.AppriseLocale() with al.lang_at('en'): # functions still behave as normal pass # restore the object mock_gettext_install.side_effect = None reload(AppriseLocale)
def test_apprise_locale(mock_gettext_install): """ API: Test apprise locale object """ lazytrans = AppriseLocale.LazyTranslation('Token') assert str(lazytrans) == 'Token'