コード例 #1
0
    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)
コード例 #2
0
ファイル: test_intercept.py プロジェクト: diopib/reahl
    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
コード例 #3
0
ファイル: test_i18n.py プロジェクト: dli7428/reahl
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