def translator_singleton_thread_safety(self, fixture): """The SystemwideTranslator.get_instance() is this thread-safe.""" SystemWideTranslator.instance = None # To "reset" the singleton, else its __init__ will NEVER be called in this test SystemWideTranslator.get_instance().map_lock.acquire() self.lock_released = False def release_lock(): SystemWideTranslator.get_instance().map_lock.release() self.lock_released = True timer = Timer(.1, release_lock) timer.start() _ = Translator('reahl-component') _.gettext('test string') timer.cancel() vassert(self.lock_released)
def basic_usage(self, fixture): """A Translator for a particular component can translate messages for that component into the interface_locale on its current ExecutionContext.""" _ = Translator( 'reahl-component' ) # Will find its translations in the compiled messages of reahl-component with LocaleContextStub() as context: context.test_locale = 'en_gb' vassert(_('test string') == 'test string') vassert(_.gettext('test string') == 'test string') vassert(_.ngettext('thing', 'things', 1) == 'thing') vassert(_.ngettext('thing', 'things', 3) == 'things') context.test_locale = 'af' vassert(_('test string') == 'toets string') vassert(_.gettext('test string') == 'toets string') vassert(_.ngettext('thing', 'things', 1) == 'ding') vassert(_.ngettext('thing', 'things', 3) == 'goeters')