1 # Licensed to the Apache Software Foundation (ASF) under one or more
2 # contributor license agreements. See the NOTICE file distributed with
3 # this work for additional information regarding copyright ownership.
4 # The ASF licenses this file to You under the Apache License, Version 2.0
5 # (the "License"); you may not use this file except in compliance with
6 # the License. You may obtain a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
18 from aria import extension
20 # #pylint: disable=no-member,no-method-argument,unused-variable
23 class TestRegistrar(object):
25 def test_list_based_registrar_with_single_element_registration(self):
26 class ExtensionRegistration(extension._ExtensionRegistration):
28 def list_based_registrar(*_):
30 extension_registration = ExtensionRegistration()
32 @extension_registration
33 class Extension(object):
34 def list_based_registrar(self):
37 assert extension_registration.list_based_registrar() == []
38 extension_registration.init()
39 assert extension_registration.list_based_registrar() == [True]
41 def test_list_based_registrar_with_sequence_element_registration(self):
42 class ExtensionRegistration(extension._ExtensionRegistration):
44 def list_based_registrar1(*_):
48 def list_based_registrar2(*_):
52 def list_based_registrar3(*_):
54 extension_registration = ExtensionRegistration()
56 @extension_registration
57 class Extension(object):
58 def list_based_registrar1(*_):
61 def list_based_registrar2(*_):
64 def list_based_registrar3(*_):
67 extension_registration.init()
68 assert extension_registration.list_based_registrar1() == [True, True]
69 assert extension_registration.list_based_registrar2() == [True, True]
70 assert extension_registration.list_based_registrar3() == [True]
72 def test_dict_based_registrar(self):
73 class ExtensionRegistration(extension._ExtensionRegistration):
75 def dict_based_registrar(*_):
77 extension_registration = ExtensionRegistration()
79 @extension_registration
80 class Extension1(object):
81 def dict_based_registrar(self):
87 @extension_registration
88 class Extension2(object):
89 def dict_based_registrar(self):
95 assert extension_registration.dict_based_registrar() == {}
96 extension_registration.init()
97 assert extension_registration.dict_based_registrar() == {
104 def test_invalid_duplicate_key_dict_based_registrar(self):
105 class ExtensionRegistration(extension._ExtensionRegistration):
106 @extension._registrar
107 def dict_based_registrar(*_):
109 extension_registration = ExtensionRegistration()
111 @extension_registration
112 class Extension1(object):
113 def dict_based_registrar(self):
118 @extension_registration
119 class Extension2(object):
120 def dict_based_registrar(self):
125 with pytest.raises(RuntimeError):
126 extension_registration.init()
128 def test_unsupported_registrar(self):
129 with pytest.raises(RuntimeError):
130 class ExtensionRegistration(extension._ExtensionRegistration):
131 @extension._registrar
132 def unsupported_registrar(*_):
134 extension_registration = ExtensionRegistration()
136 @extension_registration
137 class Extension(object):
138 def unsupported_registrar(self):
141 extension_registration.init()
143 def test_unimplemented_registration(self):
144 class ExtensionRegistration(extension._ExtensionRegistration):
145 @extension._registrar
146 def list_based_registrar(*_):
148 extension_registration = ExtensionRegistration()
150 @extension_registration
151 class Extension(object):
154 assert extension_registration.list_based_registrar() == []
155 extension_registration.init()
156 assert extension_registration.list_based_registrar() == []