Python zope.interface.implementer() Examples
The following are 30
code examples of zope.interface.implementer().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
zope.interface
, or try the search function
.
Example #1
Source File: test_verify.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 8 votes |
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)
Example #2
Source File: test_agent.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 6 votes |
def test_alternateTrustRoot(self): """ L{BrowserLikePolicyForHTTPS.creatorForNetloc} returns an L{IOpenSSLClientConnectionCreator} provider which will add certificates from the given trust root. """ @implementer(IOpenSSLTrustRoot) class CustomOpenSSLTrustRoot(object): called = False context = None def _addCACertsToContext(self, context): self.called = True self.context = context trustRoot = CustomOpenSSLTrustRoot() policy = BrowserLikePolicyForHTTPS(trustRoot=trustRoot) creator = policy.creatorForNetloc(b"thingy", 4321) self.assertTrue(trustRoot.called) connection = creator.clientConnectionForTLS(None) self.assertIs(trustRoot.context, connection.get_context())
Example #3
Source File: test_verify.py From learn_python3_spider with MIT License | 6 votes |
def test_method_takes_required_kwargs(self): from zope.interface import Interface from zope.interface import implementer class ICurrent(Interface): def method(**kwargs): pass @implementer(ICurrent) class Current(object): def method(self, **kw): raise NotImplementedError() self._callFUT(ICurrent, Current)
Example #4
Source File: test_verify.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 6 votes |
def test_method_doesnt_take_required_starargs(self): from zope.interface import Interface from zope.interface import implementer from zope.interface.exceptions import BrokenMethodImplementation class ICurrent(Interface): def method(*args): pass @implementer(ICurrent) class Current(object): def method(self): pass self.assertRaises(BrokenMethodImplementation, self._callFUT, ICurrent, Current)
Example #5
Source File: test_verify.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 6 votes |
def test_method_doesnt_take_required_only_kwargs(self): from zope.interface import Interface from zope.interface import implementer from zope.interface.exceptions import BrokenMethodImplementation class ICurrent(Interface): def method(**kw): pass @implementer(ICurrent) class Current(object): def method(self): pass self.assertRaises(BrokenMethodImplementation, self._callFUT, ICurrent, Current)
Example #6
Source File: test_verify.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 6 votes |
def test_method_takes_extra_arg_with_default(self): from zope.interface import Interface from zope.interface import implementer class ICurrent(Interface): def method(a): pass @implementer(ICurrent) class Current(object): def method(self, a, b=None): pass self._callFUT(ICurrent, Current)
Example #7
Source File: test_verify.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 6 votes |
def test_method_takes_only_positional_args(self): from zope.interface import Interface from zope.interface import implementer class ICurrent(Interface): def method(a): pass @implementer(ICurrent) class Current(object): def method(self, *args): pass self._callFUT(ICurrent, Current)
Example #8
Source File: test_verify.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 6 votes |
def test_method_takes_only_kwargs(self): from zope.interface import Interface from zope.interface import implementer from zope.interface.exceptions import BrokenMethodImplementation class ICurrent(Interface): def method(a): pass @implementer(ICurrent) class Current(object): def method(self, **kw): pass self.assertRaises(BrokenMethodImplementation, self._callFUT, ICurrent, Current)
Example #9
Source File: test_verify.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 6 votes |
def test_method_takes_not_enough_args(self): from zope.interface import Interface from zope.interface import implementer from zope.interface.exceptions import BrokenMethodImplementation class ICurrent(Interface): def method(a): pass @implementer(ICurrent) class Current(object): def method(self): pass self.assertRaises(BrokenMethodImplementation, self._callFUT, ICurrent, Current)
Example #10
Source File: test_verify.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 6 votes |
def test_w_callable_non_func_method(self): from zope.interface.interface import Method from zope.interface import Interface from zope.interface import implementer class QuasiMethod(Method): def __call__(self, *args, **kw): pass class QuasiCallable(object): def __call__(self, *args, **kw): pass class ICurrent(Interface): attr = QuasiMethod('This is callable') @implementer(ICurrent) class Current: attr = QuasiCallable() self._callFUT(ICurrent, Current)
Example #11
Source File: test_odd_declarations.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 6 votes |
def test_classImplements(self): @implementer(I3) class A(Odd): pass @implementer(I4) class B(Odd): pass class C(A, B): pass classImplements(C, I1, I2) self.assertEqual([i.getName() for i in implementedBy(C)], ['I1', 'I2', 'I3', 'I4']) classImplements(C, I5) self.assertEqual([i.getName() for i in implementedBy(C)], ['I1', 'I2', 'I5', 'I3', 'I4'])
Example #12
Source File: test_verify.py From learn_python3_spider with MIT License | 6 votes |
def test_method_takes_extra_starargs(self): from zope.interface import Interface from zope.interface import implementer class ICurrent(Interface): def method(a): pass @implementer(ICurrent) class Current(object): def method(self, a, *args): raise NotImplementedError() self._callFUT(ICurrent, Current)
Example #13
Source File: test_verify.py From learn_python3_spider with MIT License | 6 votes |
def test_method_takes_only_kwargs(self): from zope.interface import Interface from zope.interface import implementer from zope.interface.exceptions import BrokenMethodImplementation class ICurrent(Interface): def method(a): pass @implementer(ICurrent) class Current(object): def method(self, **kw): raise NotImplementedError() self.assertRaises(BrokenMethodImplementation, self._callFUT, ICurrent, Current)
Example #14
Source File: test_verify.py From learn_python3_spider with MIT License | 6 votes |
def test_method_takes_only_positional_args(self): from zope.interface import Interface from zope.interface import implementer class ICurrent(Interface): def method(a): pass @implementer(ICurrent) class Current(object): def method(self, *args): raise NotImplementedError() self._callFUT(ICurrent, Current)
Example #15
Source File: test_verify.py From learn_python3_spider with MIT License | 6 votes |
def test_method_takes_extra_arg_with_default(self): from zope.interface import Interface from zope.interface import implementer class ICurrent(Interface): def method(a): pass @implementer(ICurrent) class Current(object): def method(self, a, b=None): raise NotImplementedError() self._callFUT(ICurrent, Current)
Example #16
Source File: test_flatten.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 6 votes |
def test_renderable(self): """ If a L{FlattenerError} is created with an L{IRenderable} provider root, the repr of that object is included in the string representation of the exception. """ @implementer(IRenderable) class Renderable(object): def __repr__(self): return "renderable repr" self.assertEqual( str(FlattenerError( RuntimeError("reason"), [Renderable()], [])), "Exception while flattening:\n" " renderable repr\n" "RuntimeError: reason\n")
Example #17
Source File: test_verify.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 6 votes |
def test_w_decorated_method(self): from zope.interface import Interface from zope.interface import implementer def decorator(func): # this is, in fact, zope.proxy.non_overridable return property(lambda self: func.__get__(self)) class ICurrent(Interface): def method(a): pass @implementer(ICurrent) class Current(object): @decorator def method(self, a): pass self._callFUT(ICurrent, Current)
Example #18
Source File: test_agent.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 6 votes |
def integrationTest(self, hostName, expectedAddress, addressType): """ Wrap L{AgentTestsMixin.integrationTest} with TLS. """ authority, server = certificatesForAuthorityAndServer(hostName .decode('ascii')) def tlsify(serverFactory): return TLSMemoryBIOFactory(server.options(), False, serverFactory) def tlsagent(reactor): from twisted.web.iweb import IPolicyForHTTPS from zope.interface import implementer @implementer(IPolicyForHTTPS) class Policy(object): def creatorForNetloc(self, hostname, port): return optionsForClientTLS(hostname.decode("ascii"), trustRoot=authority) return client.Agent(reactor, contextFactory=Policy()) (super(AgentHTTPSTests, self) .integrationTest(hostName, expectedAddress, addressType, serverWrapper=tlsify, createAgent=tlsagent, scheme=b'https'))
Example #19
Source File: test_tcp.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 6 votes |
def test_startedListeningLogMessage(self): """ When a port starts, a message including a description of the associated factory is logged. """ loggedMessages = self.observe() reactor = self.buildReactor() @implementer(ILoggingContext) class SomeFactory(ServerFactory): def logPrefix(self): return "Crazy Factory" factory = SomeFactory() p = self.getListeningPort(reactor, factory) expectedMessage = self.getExpectedStartListeningLogMessage( p, "Crazy Factory") self.assertEqual((expectedMessage,), loggedMessages[0]['message'])
Example #20
Source File: test_tcp.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 6 votes |
def test_doubleHalfClose(self): """ If one side half-closes its connection, and then the other side of the connection calls C{loseWriteConnection}, and then C{loseConnection} in {writeConnectionLost}, the connection is closed correctly. This rather obscure case used to fail (see ticket #3037). """ @implementer(IHalfCloseableProtocol) class ListenerProtocol(ConnectableProtocol): def readConnectionLost(self): self.transport.loseWriteConnection() def writeConnectionLost(self): self.transport.loseConnection() class Client(ConnectableProtocol): def connectionMade(self): self.transport.loseConnection() # If test fails, reactor won't stop and we'll hit timeout: runProtocolsWithReactor( self, ListenerProtocol(), Client(), TCPCreator())
Example #21
Source File: test_verify.py From learn_python3_spider with MIT License | 6 votes |
def test_method_doesnt_take_required_only_kwargs(self): from zope.interface import Interface from zope.interface import implementer from zope.interface.exceptions import BrokenMethodImplementation class ICurrent(Interface): def method(**kw): pass @implementer(ICurrent) class Current(object): def method(self): raise NotImplementedError() self.assertRaises(BrokenMethodImplementation, self._callFUT, ICurrent, Current)
Example #22
Source File: test_udp.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 6 votes |
def test_startedListeningLogMessage(self): """ When a port starts, a message including a description of the associated protocol is logged. """ loggedMessages = self.observe() reactor = self.buildReactor() @implementer(ILoggingContext) class SomeProtocol(DatagramProtocol): def logPrefix(self): return "Crazy Protocol" protocol = SomeProtocol() p = self.getListeningPort(reactor, protocol) expectedMessage = "Crazy Protocol starting on %d" % (p.getHost().port,) self.assertEqual((expectedMessage,), loggedMessages[0]['message'])
Example #23
Source File: test_verify.py From learn_python3_spider with MIT License | 6 votes |
def test_method_doesnt_take_required_starargs(self): from zope.interface import Interface from zope.interface import implementer from zope.interface.exceptions import BrokenMethodImplementation class ICurrent(Interface): def method(*args): pass @implementer(ICurrent) class Current(object): def method(self): raise NotImplementedError() self.assertRaises(BrokenMethodImplementation, self._callFUT, ICurrent, Current)
Example #24
Source File: test_verify.py From learn_python3_spider with MIT License | 6 votes |
def test_method_takes_not_enough_args(self): from zope.interface import Interface from zope.interface import implementer from zope.interface.exceptions import BrokenMethodImplementation class ICurrent(Interface): def method(a): pass @implementer(ICurrent) class Current(object): def method(self): raise NotImplementedError() self.assertRaises(BrokenMethodImplementation, self._callFUT, ICurrent, Current)
Example #25
Source File: test_verify.py From learn_python3_spider with MIT License | 6 votes |
def test_method_takes_wrong_arg_names_but_OK(self): # We no longer require names to match. from zope.interface import Interface from zope.interface import implementer class ICurrent(Interface): def method(a): pass @implementer(ICurrent) class Current(object): def method(self, b): raise NotImplementedError() self._callFUT(ICurrent, Current)
Example #26
Source File: test_verify.py From learn_python3_spider with MIT License | 6 votes |
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): raise NotImplementedError() self._callFUT(IDerived, Current)
Example #27
Source File: test_twisted.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 6 votes |
def test_zope35(self): """ Version 3.5 of L{zope.interface} has a C{implementer} method which cannot be used as a class decorator. """ with SetAsideModule("zope"): self.install((3, 5)) from zope.interface import Interface, implementer class IDummy(Interface): pass try: @implementer(IDummy) class Dummy(object): pass except TypeError as exc: self.assertEqual( "Can't use implementer with classes. " "Use one of the class-declaration functions instead.", str(exc))
Example #28
Source File: test_internet.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 6 votes |
def test_interfacesForTransport(self): """ If the protocol objects returned by the factory given to L{ClientService} provide special "marker" interfaces for their transport - L{IHalfCloseableProtocol} or L{IFileDescriptorReceiver} - those interfaces will be provided by the protocol objects passed on to the reactor. """ @implementer(IHalfCloseableProtocol, IFileDescriptorReceiver) class FancyProtocol(Protocol, object): """ Provider of various interfaces. """ cq, service = self.makeReconnector(protocolType=FancyProtocol) reactorFacing = cq.constructedProtocols[0] self.assertTrue(IFileDescriptorReceiver.providedBy(reactorFacing)) self.assertTrue(IHalfCloseableProtocol.providedBy(reactorFacing))
Example #29
Source File: test_util.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 6 votes |
def test_cleanReactorKillsProcesses(self): """ The Janitor will kill processes during reactor cleanup. """ @implementer(IProcessTransport) class StubProcessTransport(object): """ A stub L{IProcessTransport} provider which records signals. @ivar signals: The signals passed to L{signalProcess}. """ def __init__(self): self.signals = [] def signalProcess(self, signal): """ Append C{signal} to C{self.signals}. """ self.signals.append(signal) pt = StubProcessTransport() reactor = StubReactor([], [pt]) jan = _Janitor(None, None, reactor=reactor) jan._cleanReactor() self.assertEqual(pt.signals, ["KILL"])
Example #30
Source File: test_loopback.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 6 votes |
def test_pullProducer(self): """ Test a pull producer registered against a loopback transport. """ @implementer(IPullProducer) class PullProducer(object): def __init__(self, toProduce): self.toProduce = toProduce def start(self, consumer): self.consumer = consumer self.consumer.registerProducer(self, False) def resumeProducing(self): self.consumer.write(self.toProduce.pop(0)) if not self.toProduce: self.consumer.unregisterProducer() return self._producertest(PullProducer)