def test_gathered_list(): provider_test = Provider() with pytest.raises(TypeError): GatheredList() provider_test = Provider() gl = GatheredList(provider_test) members = [ [2, 3, 4], [3, 4, 5], [4, 4, 7], ["foo", "bar"], None] memberlist = [] [memberlist.extend(member) for member in members if member] [gl.add_result(None, member) for member in members] assert list(gl) == memberlist assert [x for x in gl] == memberlist assert all((k in gl) for k in memberlist) newlist = [] newlist.extend(gl) assert newlist == memberlist
def test_provider_handle_bad_providers(): provider_test = Provider() @provider(provider_test) def provider_for_test(sender, *args, **kwargs): return dict(result1=1) @provider(provider_test) def provider_for_test_2(sender, *args, **kwargs): return 3 @provider(provider_test) def provider_for_test_3(sender, *args, **kwargs): return [] @provider(provider_test) def provider_for_test_4(sender, *args, **kwargs): return dict(result4=4) results = provider_test.gather() assert isinstance(results, GatheredDict) assert results["result1"] == 1 assert "result2" not in results assert "result3" not in results assert results["result4"] == 4
def test_no_providers(): provider_test = Provider(providing_args=["foo"]) results = provider_test.gather() assert isinstance(results, GatheredDict) assert results.keys() == []
def test_provider_caching(): provider_test = Provider(use_caching=True) @provider(provider_test) def provider_for_test(sender, *args, **kwargs): return dict(foo="bar") assert provider_test.gather()["foo"] == "bar" assert provider_test.gather()["foo"] == "bar"
def test_provider(): provider_test = Provider(providing_args=["foo"]) @provider(provider_test) def provider_for_test(*args, **kwargs): return dict(result=2) results = provider_test.gather() assert isinstance(results, GatheredDict) assert results["result"] == 2
def test_provider_with_sender(): provider_test = Provider(providing_args=["foo"]) @provider(provider_test, sender=str) def provider_for_test(sender, *args, **kwargs): return dict(result=kwargs["foo"]) results = provider_test.gather(str, foo="BOOM") assert isinstance(results, GatheredDict) assert results["result"] == "BOOM"
def test_provider_with_sender_int(): provider_test = Provider(providing_args=["foo"]) @provider(provider_test) def provider_for_test(*args, **kwargs): return dict(result=kwargs["foo"] * 7) results = provider_test.gather(int, foo=3) assert isinstance(results, GatheredDict) assert results["result"] == 21
def test_provider_caching_sender(): class Sender(object): pass provider_test = Provider(use_caching=True) @provider(provider_test, sender=Sender) def provider_for_test(sender, *args, **kwargs): return dict(foo="bar") assert provider_test.gather(Sender)["foo"] == "bar" assert provider_test.gather(Sender)["foo"] == "bar"
def test_provider_subclass(): class ParentClass(object): pass class ChildClass(ParentClass): pass provider_test = Provider() @provider(provider_test, sender=ParentClass) def provider_for_test(sender, *args, **kwargs): return dict(foo="bar") assert provider_test.gather(ChildClass)["foo"] == "bar"
def test_provider_list_results(): provider_test = Provider(result_class=GatheredList) @provider(provider_test) def provider_for_test(sender, *args, **kwargs): return [1, 2, 3] @provider(provider_test) def provider_for_test_2(sender, *args, **kwargs): return [2, 3, 4] results = provider_test.gather() assert isinstance(results, GatheredList) assert [r for r in results] == [1, 2, 3, 2, 3, 4]
def test_provider_handle_multi_providers(): provider_test = Provider() @provider(provider_test) def provider_for_test(sender, *args, **kwargs): return dict(result1=1) @provider(provider_test) def provider_for_test_2(sender, *args, **kwargs): return dict(result2=2) results = provider_test.gather() assert isinstance(results, GatheredDict) assert results["result1"] == 1 assert results["result2"] == 2
def test_provider_with_sender_multi(): provider_test = Provider(providing_args=["foo"]) @provider(provider_test) def provider_for_test(sender, *args, **kwargs): if sender is str: return dict(result=int(kwargs["foo"]) * 7) return dict(result=kwargs["foo"] * 7) results = provider_test.gather(str, foo="3") assert isinstance(results, GatheredDict) assert results["result"] == 21 results = provider_test.gather(int, foo=3) assert isinstance(results, GatheredDict) assert results["result"] == 21
def test_provider_caching_no_receiver(): class Sender(object): pass provider_test = Provider(use_caching=True) assert provider_test.gather(Sender).keys() == [] assert provider_test.gather(Sender).keys() == [] class NotSender(object): pass @provider(provider_test, sender=Sender) def provider_for_test(sender, *args, **kwargs): return dict(foo="bar") assert provider_test.gather(NotSender).keys() == [] assert provider_test.gather(NotSender).keys() == []
def test_provider_handle_stop_providing(): provider_test = Provider() @provider(provider_test) def provider_for_test(sender, *args, **kwargs): return dict(result1=1) @provider(provider_test) def provider_for_test_2(sender, *args, **kwargs): raise StopProviding(result=dict(result2=2)) @provider(provider_test) def provider_for_test_3(sender, *args, **kwargs): return dict(result3=3) results = provider_test.gather() assert isinstance(results, GatheredDict) assert results["result1"] == 1 assert results["result2"] == 2 assert "result3" not in results
def test_provider_handle_null_provider(): provider_test = Provider() @provider(provider_test) def provider_for_test(sender, *args, **kwargs): return dict(result1=1) @provider(provider_test) def provider_for_test_2(sender, *args, **kwargs): return None @provider(provider_test) def provider_for_test_3(sender, *args, **kwargs): return dict(result3=3) results = provider_test.gather() assert isinstance(results, GatheredDict) assert results["result1"] == 1 assert "result2" not in results assert results["result3"] == 3
def test_gathered_dict_update(): provider_test = Provider() members = (("foo3", "bar1"), ("foo2", "bar2"), ("foo1", "bar3")) memberdict = OrderedDict(members) gd = GatheredDict(provider_test) [gd.add_result(None, dict((member, ))) for member in members] # None results are ignored gd.add_result(None, None) newdict = dict() newdict.update(gd) assert all((k in newdict) for k in memberdict.keys()) assert all((newdict[k] == v) for k, v in memberdict.items()) assert len(newdict) == len(memberdict)
def suppress_provider(provider): _orig_gather = provider.gather _orig_connect = provider.connect temp_provider = Provider() def suppressed_gather(self, *args, **kwargs): return temp_provider.gather(*args, **kwargs) def suppressed_connect(self, func, *args, **kwargs): return temp_provider.connect(func, *args, **kwargs) provider.gather = types.MethodType(suppressed_gather, provider) provider.connect = types.MethodType(suppressed_connect, provider) try: yield finally: provider.gather = _orig_gather provider.connect = _orig_connect
def test_gathered_dict(): provider_test = Provider() with pytest.raises(TypeError): GatheredDict() members = (("foo3", "bar1"), ("foo2", "bar2"), ("foo1", "bar3")) memberdict = OrderedDict(members) gd = GatheredDict(provider_test) [gd.add_result(None, dict((member, ))) for member in members] assert gd.keys() == memberdict.keys() assert gd.values() == memberdict.values() assert gd.items() == memberdict.items() assert [x for x in gd] == memberdict.keys() assert all((k in gd) for k in memberdict.keys()) assert all((gd.get(k) == gd[k]) for k in memberdict.keys()) assert gd.get("DOES_NOT_EXIST") is None assert gd.get("DOES_NOT_EXIST", "DEFAULT") == "DEFAULT"
def test_provider_handle_multi_decorators(): provider_test = Provider(providing_args=["foo"]) provider_test_2 = Provider(providing_args=["foo"]) @provider([provider_test, provider_test_2], sender=str) def provider_for_test(sender, *args, **kwargs): return dict(result="BOOM: %s" % kwargs["foo"]) results = provider_test.gather(str, foo="1") assert isinstance(results, GatheredDict) assert results["result"] == "BOOM: 1" results = provider_test_2.gather(str, foo="2") assert isinstance(results, GatheredDict) assert results["result"] == "BOOM: 2"
# This file is a part of the Pootle project. It is distributed under the GPL3 # or later license. See the LICENSE file for a copy of the license and the # AUTHORS file for copyright and authorship information. from pootle.core.plugin.delegate import Getter, Provider config = Getter(providing_args=["instance"]) search_backend = Getter(providing_args=["instance"]) lang_mapper = Getter(providing_args=["instance"]) state = Getter() response = Getter() contributors = Getter() formats = Getter() format_registration = Provider() format_classes = Provider() format_diffs = Provider() format_updaters = Provider() format_syncers = Provider() filetype_tool = Getter() tp_tool = Getter() data_tool = Getter() data_updater = Getter() serializers = Provider(providing_args=["instance"]) deserializers = Provider(providing_args=["instance"]) subcommands = Provider() url_patterns = Provider() # view.context_data
# -*- coding: utf-8 -*- # # Copyright (C) Pootle contributors. # # This file is a part of the Pootle project. It is distributed under the GPL3 # or later license. See the LICENSE file for a copy of the license and the # AUTHORS file for copyright and authorship information. from pootle.core.plugin.delegate import Getter, Provider config = Getter(providing_args=["instance"]) search_backend = Getter(providing_args=["instance"]) lang_mapper = Getter(providing_args=["instance"]) state = Getter() response = Getter() serializers = Provider(providing_args=["instance"]) deserializers = Provider(providing_args=["instance"]) subcommands = Provider()
# -*- coding: utf-8 -*- # # Copyright (C) Pootle contributors. # # This file is a part of the Pootle project. It is distributed under the GPL3 # or later license. See the LICENSE file for a copy of the license and the # AUTHORS file for copyright and authorship information. from pootle.core.plugin.delegate import Getter, Provider config = Getter(providing_args=["instance"]) search_backend = Getter(providing_args=["instance"]) lang_mapper = Getter(providing_args=["instance"]) state = Getter() response = Getter() serializers = Provider(providing_args=["instance"]) deserializers = Provider(providing_args=["instance"])
# -*- coding: utf-8 -*- # # Copyright (C) Pootle contributors. # # This file is a part of the Pootle project. It is distributed under the GPL3 # or later license. See the LICENSE file for a copy of the license and the # AUTHORS file for copyright and authorship information. from pootle.core.plugin.delegate import Getter, Provider fs_file = Getter() fs_finder = Getter() fs_matcher = Getter() fs_resources = Getter() fs_translation_mapping_validator = Getter() fs_url_validator = Getter() # File system plugins such as git/mercurial/localfs fs_plugins = Provider() fs_pre_pull_handlers = Provider() fs_post_pull_handlers = Provider() fs_pre_push_handlers = Provider() fs_post_push_handlers = Provider()
# -*- coding: utf-8 -*- # # Copyright (C) Pootle contributors. # Copyright (C) Zing contributors. # # This file is a part of the Zing project. It is distributed under the GPL3 # or later license. See the LICENSE file for a copy of the license and the # AUTHORS file for copyright and authorship information. from pootle.core.plugin.delegate import Getter, Provider search_backend = Getter(providing_args=["instance"]) contributors = Getter() # view.context_data context_data = Provider(providing_args=["view", "context"])
# or later license. See the LICENSE file for a copy of the license and the # AUTHORS file for copyright and authorship information. from pootle.core.plugin.delegate import Getter, Provider config = Getter(providing_args=["instance"]) search_backend = Getter(providing_args=["instance"]) lang_mapper = Getter(providing_args=["instance"]) state = Getter() response = Getter() check_updater = Getter() comparable_event = Getter() contributors = Getter() crud = Getter() display = Getter() event_score = Provider() event_formatters = Provider() formats = Getter() format_registration = Provider() format_classes = Provider() format_diffs = Provider() format_updaters = Provider() format_syncers = Provider() frozen = Getter() filetype_tool = Getter() grouped_events = Getter() lifecycle = Getter() log = Getter() stemmer = Getter() site_languages = Getter() terminology = Getter()
# -*- coding: utf-8 -*- # # Copyright (C) Pootle contributors. # # This file is a part of the Pootle project. It is distributed under the GPL3 # or later license. See the LICENSE file for a copy of the license and the # AUTHORS file for copyright and authorship information. from pootle.core.plugin.delegate import Getter, Provider config = Getter(providing_args=["instance"]) search_backend = Getter(providing_args=["instance"]) lang_mapper = Getter(providing_args=["instance"]) state = Getter() response = Getter() serializers = Provider(providing_args=["instance"]) deserializers = Provider(providing_args=["instance"]) subcommands = Provider() # view.context_data context_data = Provider(providing_args=["view", "context"])