##// END OF EJS Templates
fix: use templater to substitute values in command string...
fix: use templater to substitute values in command string bytes.format() isn't supported on Python 3. Luckily, our template syntax is similar so we can reuse it. We need a hack to disable \-escapes as '\' is a directory separator on Windows.

File last commit:

r37653:cc8c0683 default
r37792:d6970628 default
Show More
test-check-interfaces.py
160 lines | 5.1 KiB | text/x-python | PythonLexer
/ tests / test-check-interfaces.py
Gregory Szorc
tests: verify that peer instances only expose interface members...
r33806 # Test that certain objects conform to well-defined interfaces.
from __future__ import absolute_import, print_function
Gregory Szorc
repository: define interface for local repositories...
r37198 import os
from mercurial.thirdparty.zope import (
interface as zi,
)
from mercurial.thirdparty.zope.interface import (
verify as ziverify,
)
Gregory Szorc
tests: verify that peer instances only expose interface members...
r33806 from mercurial import (
Gregory Szorc
tests: add interface checks for bundle, statichttp, and union peers...
r34308 bundlerepo,
Gregory Szorc
filelog: declare that filelog implements a storage interface...
r37459 filelog,
Gregory Szorc
tests: verify that peer instances only expose interface members...
r33806 httppeer,
localrepo,
Gregory Szorc
repository: define interface for local repositories...
r37198 repository,
Gregory Szorc
tests: verify that peer instances only expose interface members...
r33806 sshpeer,
Gregory Szorc
tests: add interface checks for bundle, statichttp, and union peers...
r34308 statichttprepo,
Gregory Szorc
tests: verify that peer instances only expose interface members...
r33806 ui as uimod,
Gregory Szorc
tests: add interface checks for bundle, statichttp, and union peers...
r34308 unionrepo,
Gregory Szorc
filelog: declare that filelog implements a storage interface...
r37459 vfs as vfsmod,
Gregory Szorc
wireproto: port protocol handler to zope.interface...
r37312 wireprotoserver,
wireprototypes,
Gregory Szorc
wireproto: implement command executor interface for version 1 peers...
r37648 wireprotov1peer,
Gregory Szorc
wireproto: extract HTTP version 2 code to own module...
r37563 wireprotov2server,
Gregory Szorc
tests: verify that peer instances only expose interface members...
r33806 )
Gregory Szorc
repository: define interface for local repositories...
r37198 rootdir = os.path.normpath(os.path.join(os.path.dirname(__file__), '..'))
Gregory Szorc
filelog: declare that filelog implements a storage interface...
r37459 def checkzobject(o, allowextra=False):
Gregory Szorc
repository: define interface for local repositories...
r37198 """Verify an object with a zope interface."""
ifaces = zi.providedBy(o)
if not ifaces:
print('%r does not provide any zope interfaces' % o)
return
# Run zope.interface's built-in verification routine. This verifies that
# everything that is supposed to be present is present.
for iface in ifaces:
ziverify.verifyObject(iface, o)
Gregory Szorc
filelog: declare that filelog implements a storage interface...
r37459 if allowextra:
return
Gregory Szorc
repository: define interface for local repositories...
r37198 # Now verify that the object provides no extra public attributes that
# aren't declared as part of interfaces.
allowed = set()
for iface in ifaces:
allowed |= set(iface.names(all=True))
public = {a for a in dir(o) if not a.startswith('_')}
for attr in sorted(public - allowed):
print('public attribute not declared in interfaces: %s.%s' % (
o.__class__.__name__, attr))
Gregory Szorc
tests: verify that peer instances only expose interface members...
r33806 # Facilitates testing localpeer.
class dummyrepo(object):
def __init__(self):
self.ui = uimod.ui()
def filtered(self, name):
pass
def _restrictcapabilities(self, caps):
pass
Gregory Szorc
httppeer: refactor how httppeer is created (API)...
r37024 class dummyopener(object):
handlers = []
Gregory Szorc
httppeer: perform capabilities request in makepeer()...
r37570 # Facilitates testing sshpeer without requiring a server.
Gregory Szorc
tests: verify that peer instances only expose interface members...
r33806 class badpeer(httppeer.httppeer):
def __init__(self):
Gregory Szorc
httppeer: perform capabilities request in makepeer()...
r37570 super(badpeer, self).__init__(None, None, None, dummyopener(), None,
None)
Gregory Szorc
tests: verify that peer instances only expose interface members...
r33806 self.badattribute = True
def badmethod(self):
pass
Gregory Szorc
sshpeer: defer pipe buffering and stderr sidechannel binding...
r36388 class dummypipe(object):
def close(self):
pass
Gregory Szorc
tests: verify that peer instances only expose interface members...
r33806 def main():
ui = uimod.ui()
Gregory Szorc
repository: define interface for local repositories...
r37198 # Needed so we can open a local repo with obsstore without a warning.
ui.setconfig('experimental', 'evolution.createmarkers', True)
Gregory Szorc
tests: verify that peer instances only expose interface members...
r33806
Gregory Szorc
repository: port peer interfaces to zope.interface...
r37336 checkzobject(badpeer())
Gregory Szorc
wireproto: convert legacy commands to command executor...
r37653 ziverify.verifyClass(repository.ipeerbase, httppeer.httppeer)
Gregory Szorc
httppeer: perform capabilities request in makepeer()...
r37570 checkzobject(httppeer.httppeer(None, None, None, dummyopener(), None, None))
Gregory Szorc
repository: port peer interfaces to zope.interface...
r37336
Gregory Szorc
httppeer: implement ipeerconnection...
r37627 ziverify.verifyClass(repository.ipeerconnection,
httppeer.httpv2peer)
Gregory Szorc
httppeer: basic implementation of capabilities interface...
r37629 ziverify.verifyClass(repository.ipeercapabilities,
httppeer.httpv2peer)
Gregory Szorc
httppeer: implement ipeerconnection...
r37627 checkzobject(httppeer.httpv2peer(None, '', None, None, None, None))
Gregory Szorc
repository: port peer interfaces to zope.interface...
r37336 ziverify.verifyClass(repository.ipeerbase,
localrepo.localpeer)
checkzobject(localrepo.localpeer(dummyrepo()))
Gregory Szorc
wireproto: implement command executor interface for version 1 peers...
r37648 ziverify.verifyClass(repository.ipeercommandexecutor,
localrepo.localcommandexecutor)
checkzobject(localrepo.localcommandexecutor(None))
ziverify.verifyClass(repository.ipeercommandexecutor,
wireprotov1peer.peerexecutor)
checkzobject(wireprotov1peer.peerexecutor(None))
Gregory Szorc
wireproto: convert legacy commands to command executor...
r37653 ziverify.verifyClass(repository.ipeerbase, sshpeer.sshv1peer)
Gregory Szorc
repository: port peer interfaces to zope.interface...
r37336 checkzobject(sshpeer.sshv1peer(ui, 'ssh://localhost/foo', None, dummypipe(),
dummypipe(), None, None))
Gregory Szorc
wireproto: convert legacy commands to command executor...
r37653 ziverify.verifyClass(repository.ipeerbase, sshpeer.sshv2peer)
Gregory Szorc
repository: port peer interfaces to zope.interface...
r37336 checkzobject(sshpeer.sshv2peer(ui, 'ssh://localhost/foo', None, dummypipe(),
dummypipe(), None, None))
ziverify.verifyClass(repository.ipeerbase, bundlerepo.bundlepeer)
checkzobject(bundlerepo.bundlepeer(dummyrepo()))
ziverify.verifyClass(repository.ipeerbase, statichttprepo.statichttppeer)
checkzobject(statichttprepo.statichttppeer(dummyrepo()))
ziverify.verifyClass(repository.ipeerbase, unionrepo.unionpeer)
checkzobject(unionrepo.unionpeer(dummyrepo()))
Gregory Szorc
tests: verify that peer instances only expose interface members...
r33806
Gregory Szorc
repository: define interface for local repositories...
r37198 ziverify.verifyClass(repository.completelocalrepository,
localrepo.localrepository)
repo = localrepo.localrepository(ui, rootdir)
checkzobject(repo)
Gregory Szorc
wireproto: port protocol handler to zope.interface...
r37312 ziverify.verifyClass(wireprototypes.baseprotocolhandler,
wireprotoserver.sshv1protocolhandler)
ziverify.verifyClass(wireprototypes.baseprotocolhandler,
wireprotoserver.sshv2protocolhandler)
ziverify.verifyClass(wireprototypes.baseprotocolhandler,
wireprotoserver.httpv1protocolhandler)
ziverify.verifyClass(wireprototypes.baseprotocolhandler,
Gregory Szorc
wireproto: extract HTTP version 2 code to own module...
r37563 wireprotov2server.httpv2protocolhandler)
Gregory Szorc
wireproto: port protocol handler to zope.interface...
r37312
sshv1 = wireprotoserver.sshv1protocolhandler(None, None, None)
checkzobject(sshv1)
sshv2 = wireprotoserver.sshv2protocolhandler(None, None, None)
checkzobject(sshv2)
httpv1 = wireprotoserver.httpv1protocolhandler(None, None, None)
checkzobject(httpv1)
Gregory Szorc
wireproto: extract HTTP version 2 code to own module...
r37563 httpv2 = wireprotov2server.httpv2protocolhandler(None, None)
Gregory Szorc
wireproto: port protocol handler to zope.interface...
r37312 checkzobject(httpv2)
Gregory Szorc
filelog: declare that filelog implements a storage interface...
r37459 ziverify.verifyClass(repository.ifilestorage, filelog.filelog)
vfs = vfsmod.vfs('.')
fl = filelog.filelog(vfs, 'dummy.i')
checkzobject(fl, allowextra=True)
Gregory Szorc
tests: verify that peer instances only expose interface members...
r33806 main()