本文整理匯總了Python中zope.interface.Interface方法的典型用法代碼示例。如果您正苦於以下問題:Python interface.Interface方法的具體用法?Python interface.Interface怎麽用?Python interface.Interface使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類zope.interface
的用法示例。
在下文中一共展示了interface.Interface方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_class_has_required_method_derived
# 需要導入模塊: from zope import interface [as 別名]
# 或者: from zope.interface import Interface [as 別名]
def test_class_has_required_method_derived(self):
from zope.interface import Interface
from zope.interface import implementer
class IBase(Interface):
def method():
pass
class IDerived(IBase):
pass
@implementer(IDerived)
class Current(object):
def method(self):
pass
self._callFUT(IDerived, Current)
示例2: test_add_explorer_view
# 需要導入模塊: from zope import interface [as 別名]
# 或者: from zope.interface import Interface [as 別名]
def test_add_explorer_view() -> None:
"""Test registration of a view serving the Swagger UI."""
with testConfig() as config:
config.include("pyramid_openapi3")
with tempfile.NamedTemporaryFile() as document:
document.write(MINIMAL_DOCUMENT)
document.seek(0)
config.pyramid_openapi3_spec(
document.name, route="/foo.yaml", route_name="foo_api_spec"
)
config.pyramid_openapi3_add_explorer()
request = config.registry.queryUtility(
IRouteRequest, name="pyramid_openapi3.explorer"
)
view = config.registry.adapters.registered(
(IViewClassifier, request, Interface), IView, name=""
)
response = view(request=DummyRequest(config=config), context=None)
assert b"<title>Swagger UI</title>" in response.body
示例3: test_explorer_view_missing_spec
# 需要導入模塊: from zope import interface [as 別名]
# 或者: from zope.interface import Interface [as 別名]
def test_explorer_view_missing_spec() -> None:
"""Test graceful failure if explorer view is not registered."""
with testConfig() as config:
config.include("pyramid_openapi3")
config.pyramid_openapi3_add_explorer()
request = config.registry.queryUtility(
IRouteRequest, name="pyramid_openapi3.explorer"
)
view = config.registry.adapters.registered(
(IViewClassifier, request, Interface), IView, name=""
)
with pytest.raises(
ConfigurationError,
match="You need to call config.pyramid_openapi3_spec for explorer to work.",
):
view(request=DummyRequest(config=config), context=None)
示例4: test_asStructuredText_empty_with_multiline_docstring
# 需要導入模塊: from zope import interface [as 別名]
# 或者: from zope.interface import Interface [as 別名]
def test_asStructuredText_empty_with_multiline_docstring(self):
from zope.interface import Interface
EXPECTED = '\n'.join([
"IEmpty",
"",
" This is an empty interface.",
" ",
(" It can be used to annotate any class or object, "
"because it promises"),
" nothing.",
"",
" Attributes:",
"",
" Methods:",
"",
""
])
class IEmpty(Interface):
""" This is an empty interface.
It can be used to annotate any class or object, because it promises
nothing.
"""
self.assertEqual(self._callFUT(IEmpty), EXPECTED)
示例5: test_asStructuredText_with_attribute_no_docstring
# 需要導入模塊: from zope import interface [as 別名]
# 或者: from zope.interface import Interface [as 別名]
def test_asStructuredText_with_attribute_no_docstring(self):
from zope.interface import Attribute
from zope.interface import Interface
EXPECTED = '\n\n'.join([
"IHasAttribute",
" This interface has an attribute.",
" Attributes:",
" an_attribute -- no documentation",
" Methods:",
""
])
class IHasAttribute(Interface):
""" This interface has an attribute.
"""
an_attribute = Attribute('an_attribute')
self.assertEqual(self._callFUT(IHasAttribute), EXPECTED)
示例6: test_asStructuredText_with_attribute_with_docstring
# 需要導入模塊: from zope import interface [as 別名]
# 或者: from zope.interface import Interface [as 別名]
def test_asStructuredText_with_attribute_with_docstring(self):
from zope.interface import Attribute
from zope.interface import Interface
EXPECTED = '\n\n'.join([
"IHasAttribute",
" This interface has an attribute.",
" Attributes:",
" an_attribute -- This attribute is documented.",
" Methods:",
""
])
class IHasAttribute(Interface):
""" This interface has an attribute.
"""
an_attribute = Attribute('an_attribute',
'This attribute is documented.')
self.assertEqual(self._callFUT(IHasAttribute), EXPECTED)
示例7: test_asStructuredText_with_method_positional_args_no_docstring
# 需要導入模塊: from zope import interface [as 別名]
# 或者: from zope.interface import Interface [as 別名]
def test_asStructuredText_with_method_positional_args_no_docstring(self):
from zope.interface import Interface
EXPECTED = '\n\n'.join([
"IHasMethod",
" This interface has a method.",
" Attributes:",
" Methods:",
" aMethod(first, second) -- no documentation",
""
])
class IHasMethod(Interface):
""" This interface has a method.
"""
def aMethod(first, second):
pass
self.assertEqual(self._callFUT(IHasMethod), EXPECTED)
示例8: test_asStructuredText_with_method_starargs_no_docstring
# 需要導入模塊: from zope import interface [as 別名]
# 或者: from zope.interface import Interface [as 別名]
def test_asStructuredText_with_method_starargs_no_docstring(self):
from zope.interface import Interface
EXPECTED = '\n\n'.join([
"IHasMethod",
" This interface has a method.",
" Attributes:",
" Methods:",
" aMethod(first, second, *rest) -- no documentation",
""
])
class IHasMethod(Interface):
""" This interface has a method.
"""
def aMethod(first, second, *rest):
pass
self.assertEqual(self._callFUT(IHasMethod), EXPECTED)
示例9: test_asStructuredText_with_method_kwargs_no_docstring
# 需要導入模塊: from zope import interface [as 別名]
# 或者: from zope.interface import Interface [as 別名]
def test_asStructuredText_with_method_kwargs_no_docstring(self):
from zope.interface import Interface
EXPECTED = '\n\n'.join([
"IHasMethod",
" This interface has a method.",
" Attributes:",
" Methods:",
" aMethod(first, second, **kw) -- no documentation",
""
])
class IHasMethod(Interface):
""" This interface has a method.
"""
def aMethod(first, second, **kw):
pass
self.assertEqual(self._callFUT(IHasMethod), EXPECTED)
示例10: test_asStructuredText_with_method_with_docstring
# 需要導入模塊: from zope import interface [as 別名]
# 或者: from zope.interface import Interface [as 別名]
def test_asStructuredText_with_method_with_docstring(self):
from zope.interface import Interface
EXPECTED = '\n\n'.join([
"IHasMethod",
" This interface has a method.",
" Attributes:",
" Methods:",
" aMethod() -- This method is documented.",
""
])
class IHasMethod(Interface):
""" This interface has a method.
"""
def aMethod():
"""This method is documented.
"""
self.assertEqual(self._callFUT(IHasMethod), EXPECTED)
示例11: test_asReStructuredText_empty_with_multiline_docstring
# 需要導入模塊: from zope import interface [as 別名]
# 或者: from zope.interface import Interface [as 別名]
def test_asReStructuredText_empty_with_multiline_docstring(self):
from zope.interface import Interface
EXPECTED = '\n'.join([
"``IEmpty``",
"",
" This is an empty interface.",
" ",
(" It can be used to annotate any class or object, "
"because it promises"),
" nothing.",
"",
" Attributes:",
"",
" Methods:",
"",
""
])
class IEmpty(Interface):
""" This is an empty interface.
It can be used to annotate any class or object, because it promises
nothing.
"""
self.assertEqual(self._callFUT(IEmpty), EXPECTED)
示例12: test_asReStructuredText_with_attribute_no_docstring
# 需要導入模塊: from zope import interface [as 別名]
# 或者: from zope.interface import Interface [as 別名]
def test_asReStructuredText_with_attribute_no_docstring(self):
from zope.interface import Attribute
from zope.interface import Interface
EXPECTED = '\n\n'.join([
"``IHasAttribute``",
" This interface has an attribute.",
" Attributes:",
" ``an_attribute`` -- no documentation",
" Methods:",
""
])
class IHasAttribute(Interface):
""" This interface has an attribute.
"""
an_attribute = Attribute('an_attribute')
self.assertEqual(self._callFUT(IHasAttribute), EXPECTED)
示例13: test_asReStructuredText_with_attribute_with_docstring
# 需要導入模塊: from zope import interface [as 別名]
# 或者: from zope.interface import Interface [as 別名]
def test_asReStructuredText_with_attribute_with_docstring(self):
from zope.interface import Attribute
from zope.interface import Interface
EXPECTED = '\n\n'.join([
"``IHasAttribute``",
" This interface has an attribute.",
" Attributes:",
" ``an_attribute`` -- This attribute is documented.",
" Methods:",
""
])
class IHasAttribute(Interface):
""" This interface has an attribute.
"""
an_attribute = Attribute('an_attribute',
'This attribute is documented.')
self.assertEqual(self._callFUT(IHasAttribute), EXPECTED)
示例14: test_asReStructuredText_with_method_no_args_no_docstring
# 需要導入模塊: from zope import interface [as 別名]
# 或者: from zope.interface import Interface [as 別名]
def test_asReStructuredText_with_method_no_args_no_docstring(self):
from zope.interface import Interface
EXPECTED = '\n\n'.join([
"``IHasMethod``",
" This interface has a method.",
" Attributes:",
" Methods:",
" ``aMethod()`` -- no documentation",
""
])
class IHasMethod(Interface):
""" This interface has a method.
"""
def aMethod():
pass
self.assertEqual(self._callFUT(IHasMethod), EXPECTED)
示例15: test_asReStructuredText_with_method_starargs_no_docstring
# 需要導入模塊: from zope import interface [as 別名]
# 或者: from zope.interface import Interface [as 別名]
def test_asReStructuredText_with_method_starargs_no_docstring(self):
from zope.interface import Interface
EXPECTED = '\n\n'.join([
"``IHasMethod``",
" This interface has a method.",
" Attributes:",
" Methods:",
" ``aMethod(first, second, *rest)`` -- no documentation",
""
])
class IHasMethod(Interface):
""" This interface has a method.
"""
def aMethod(first, second, *rest):
pass
self.assertEqual(self._callFUT(IHasMethod), EXPECTED)