def translator_singleton(self, fixture): """Only one SystemwideTranslator is ever present per process.""" SystemWideTranslator.instance = None # To "reset" the singleton, else its __init__ will NEVER be called in this test with InitMonitor(SystemWideTranslator) as monitor: _ = Translator('reahl-component') _2 = Translator('reahl-component') _('test string') _.ngettext('thing', 'things', 1) _.ngettext('thing', 'things', 2) _2('test string') vassert(monitor.times_called == 1)
def test_init_monitor(self): """An InitMonitor can monitor calls to __init__.""" class SomethingElse(object): def __init__(self): self.initialised = True original_method = SomethingElse.__init__ with InitMonitor(SomethingElse) as monitor: s = SomethingElse() assert isinstance(s, SomethingElse) assert s.initialised == True assert SomethingElse.__init__ == original_method assert monitor.times_called == 1 assert monitor.calls[0].args == () assert monitor.calls[0].return_value is s
def test_translator_singleton(): """Only one SystemWideCatalogue is ever present per process.""" SystemWideCatalogue.instance = None # To "reset" the singleton, else its __init__ will NEVER be called in this test with InitMonitor(SystemWideCatalogue) as monitor: _ = Catalogue('reahl-component') _2 = Catalogue('reahl-component') context = LocaleContextStub().install() _('test string') _.ngettext('thing', 'things', 1) _.ngettext('thing', 'things', 2) _2('test string') assert monitor.times_called == 1