Merge "Fix issubclass() hook behavior in PluginInterface"
This commit is contained in:
commit
c6a567a3e5
@ -51,6 +51,10 @@ class PluginInterface(object):
|
|||||||
marked with the abstractmethod decorator is
|
marked with the abstractmethod decorator is
|
||||||
provided by the plugin class.
|
provided by the plugin class.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
if not cls.__abstractmethods__:
|
||||||
|
return NotImplemented
|
||||||
|
|
||||||
for method in cls.__abstractmethods__:
|
for method in cls.__abstractmethods__:
|
||||||
if any(method in base.__dict__ for base in klass.__mro__):
|
if any(method in base.__dict__ for base in klass.__mro__):
|
||||||
continue
|
continue
|
||||||
|
@ -15,6 +15,8 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
import abc
|
||||||
|
|
||||||
import mock
|
import mock
|
||||||
import routes
|
import routes
|
||||||
import webob
|
import webob
|
||||||
@ -57,6 +59,47 @@ class FakePluginWithExtension(db_base_plugin_v2.NeutronDbPluginV2):
|
|||||||
self._log("method_to_support_foxnsox_extension", context)
|
self._log("method_to_support_foxnsox_extension", context)
|
||||||
|
|
||||||
|
|
||||||
|
class PluginInterfaceTest(base.BaseTestCase):
|
||||||
|
def test_issubclass_hook(self):
|
||||||
|
class A(object):
|
||||||
|
def f(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
class B(extensions.PluginInterface):
|
||||||
|
@abc.abstractmethod
|
||||||
|
def f(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
self.assertTrue(issubclass(A, B))
|
||||||
|
|
||||||
|
def test_issubclass_hook_class_without_abstract_methods(self):
|
||||||
|
class A(object):
|
||||||
|
def f(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
class B(extensions.PluginInterface):
|
||||||
|
def f(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
self.assertFalse(issubclass(A, B))
|
||||||
|
|
||||||
|
def test_issubclass_hook_not_all_methods_implemented(self):
|
||||||
|
class A(object):
|
||||||
|
def f(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
class B(extensions.PluginInterface):
|
||||||
|
@abc.abstractmethod
|
||||||
|
def f(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
@abc.abstractmethod
|
||||||
|
def g(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
self.assertFalse(issubclass(A, B))
|
||||||
|
|
||||||
|
|
||||||
class ResourceExtensionTest(base.BaseTestCase):
|
class ResourceExtensionTest(base.BaseTestCase):
|
||||||
|
|
||||||
class ResourceExtensionController(wsgi.Controller):
|
class ResourceExtensionController(wsgi.Controller):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user