##// END OF EJS Templates
errors: name arguments to CommandError constructor...
errors: name arguments to CommandError constructor Because readability counts. Differential Revision: https://phab.mercurial-scm.org/D9164

File last commit:

r45155:8c66a680 default
r46270:bd2df583 default
Show More
test-check-interfaces.py
283 lines | 7.6 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
interfaceutil: module to stub out zope.interface...
r37828 from mercurial import encoding
Augie Fackler
formatting: blacken the codebase...
r43346
Gregory Szorc
interfaceutil: module to stub out zope.interface...
r37828 encoding.environ[b'HGREALINTERFACES'] = b'1'
Gregory Szorc
repository: define interface for local repositories...
r37198 import os
Martin von Zweigbergk
tests: mark test-check-interfaces.py as requiring a repo...
r37832 import subprocess
import sys
# Only run if tests are run in a repo
Augie Fackler
formatting: blacken the codebase...
r43346 if subprocess.call(
['python', '%s/hghave' % os.environ['TESTDIR'], 'test-repo']
):
Martin von Zweigbergk
tests: mark test-check-interfaces.py as requiring a repo...
r37832 sys.exit(80)
Gregory Szorc
repository: define interface for local repositories...
r37198
Pulkit Goyal
interfaces: create a new folder for interfaces and move repository.py in it...
r43078 from mercurial.interfaces import (
Augie Fackler
interfaces: introduce an interface for dirstate implementations...
r43197 dirstate as intdirstate,
Pulkit Goyal
interfaces: create a new folder for interfaces and move repository.py in it...
r43078 repository,
)
Augie Fackler
formatting: blacken the codebase...
r43346 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,
Augie Fackler
interfaces: introduce an interface for dirstate implementations...
r43197 dirstate,
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 manifest interfaces...
r38549 manifest,
Augie Fackler
tests: make test-check-interfaces.py work on Python 3...
r37887 pycompat,
Gregory Szorc
repository: establish API for emitting revision deltas...
r39267 revlog,
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 )
Augie Fackler
tests: add simplestorerepo to test-check-interfaces.py...
r41194 testdir = os.path.dirname(__file__)
rootdir = pycompat.fsencode(os.path.normpath(os.path.join(testdir, '..')))
sys.path[0:0] = [testdir]
import simplestorerepo
Augie Fackler
formatting: blacken the codebase...
r43346
Augie Fackler
tests: add simplestorerepo to test-check-interfaces.py...
r41194 del sys.path[0]
Gregory Szorc
repository: define interface for local repositories...
r37198
Augie Fackler
formatting: blacken the codebase...
r43346
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):
Augie Fackler
formatting: blacken the codebase...
r43346 print(
'public attribute not declared in interfaces: %s.%s'
% (o.__class__.__name__, attr)
)
Gregory Szorc
repository: define interface for local repositories...
r37198
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()
Augie Fackler
formatting: blacken the codebase...
r43346
Gregory Szorc
tests: verify that peer instances only expose interface members...
r33806 def filtered(self, name):
pass
Augie Fackler
formatting: blacken the codebase...
r43346
Gregory Szorc
tests: verify that peer instances only expose interface members...
r33806 def _restrictcapabilities(self, caps):
pass
Augie Fackler
formatting: blacken the codebase...
r43346
Gregory Szorc
httppeer: refactor how httppeer is created (API)...
r37024 class dummyopener(object):
handlers = []
Augie Fackler
formatting: blacken the codebase...
r43346
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):
Augie Fackler
formatting: blacken the codebase...
r43346 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
Augie Fackler
formatting: blacken the codebase...
r43346
Gregory Szorc
sshpeer: defer pipe buffering and stderr sidechannel binding...
r36388 class dummypipe(object):
def close(self):
pass
Augie Fackler
formatting: blacken the codebase...
r43346
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.
Gregory Szorc
py3: use b'' in test-check-interfaces.py...
r40189 ui.setconfig(b'experimental', b'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: expose API descriptor on httpv2peer...
r40207 ziverify.verifyClass(repository.ipeerv2, httppeer.httpv2peer)
Augie Fackler
tests: make test-check-interfaces.py work on Python 3...
r37887 checkzobject(httppeer.httpv2peer(None, b'', b'', None, None, None))
Gregory Szorc
httppeer: implement ipeerconnection...
r37627
Augie Fackler
formatting: blacken the codebase...
r43346 ziverify.verifyClass(repository.ipeerbase, localrepo.localpeer)
Gregory Szorc
repository: port peer interfaces to zope.interface...
r37336 checkzobject(localrepo.localpeer(dummyrepo()))
Augie Fackler
formatting: blacken the codebase...
r43346 ziverify.verifyClass(
repository.ipeercommandexecutor, localrepo.localcommandexecutor
)
Gregory Szorc
wireproto: implement command executor interface for version 1 peers...
r37648 checkzobject(localrepo.localcommandexecutor(None))
Augie Fackler
formatting: blacken the codebase...
r43346 ziverify.verifyClass(
repository.ipeercommandexecutor, wireprotov1peer.peerexecutor
)
Gregory Szorc
wireproto: implement command executor interface for version 1 peers...
r37648 checkzobject(wireprotov1peer.peerexecutor(None))
Gregory Szorc
wireproto: convert legacy commands to command executor...
r37653 ziverify.verifyClass(repository.ipeerbase, sshpeer.sshv1peer)
Augie Fackler
formatting: blacken the codebase...
r43346 checkzobject(
sshpeer.sshv1peer(
ui,
b'ssh://localhost/foo',
b'',
dummypipe(),
dummypipe(),
None,
None,
)
)
Gregory Szorc
repository: port peer interfaces to zope.interface...
r37336
Gregory Szorc
wireproto: convert legacy commands to command executor...
r37653 ziverify.verifyClass(repository.ipeerbase, sshpeer.sshv2peer)
Augie Fackler
formatting: blacken the codebase...
r43346 checkzobject(
sshpeer.sshv2peer(
ui,
b'ssh://localhost/foo',
b'',
dummypipe(),
dummypipe(),
None,
None,
)
)
Gregory Szorc
repository: port peer interfaces to zope.interface...
r37336
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
Augie Fackler
formatting: blacken the codebase...
r43346 ziverify.verifyClass(
repository.ilocalrepositorymain, localrepo.localrepository
)
ziverify.verifyClass(
repository.ilocalrepositoryfilestorage, localrepo.revlogfilestorage
)
Gregory Szorc
localrepo: create new function for instantiating a local repo object...
r39723 repo = localrepo.makelocalrepository(ui, rootdir)
Gregory Szorc
repository: define interface for local repositories...
r37198 checkzobject(repo)
Augie Fackler
formatting: blacken the codebase...
r43346 ziverify.verifyClass(
wireprototypes.baseprotocolhandler, wireprotoserver.sshv1protocolhandler
)
ziverify.verifyClass(
wireprototypes.baseprotocolhandler, wireprotoserver.sshv2protocolhandler
)
ziverify.verifyClass(
wireprototypes.baseprotocolhandler,
wireprotoserver.httpv1protocolhandler,
)
ziverify.verifyClass(
wireprototypes.baseprotocolhandler,
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)
Gregory Szorc
repository: define manifest interfaces...
r38549 ziverify.verifyClass(repository.imanifestdict, manifest.manifestdict)
Augie Fackler
manifest: also declare treemanifest as implementing imanifestdict...
r45155 ziverify.verifyClass(repository.imanifestdict, manifest.treemanifest)
Augie Fackler
formatting: blacken the codebase...
r43346 ziverify.verifyClass(
repository.imanifestrevisionstored, manifest.manifestctx
)
ziverify.verifyClass(
repository.imanifestrevisionwritable, manifest.memmanifestctx
)
ziverify.verifyClass(
repository.imanifestrevisionstored, manifest.treemanifestctx
)
ziverify.verifyClass(
repository.imanifestrevisionwritable, manifest.memtreemanifestctx
)
Gregory Szorc
repository: define manifest interfaces...
r38549 ziverify.verifyClass(repository.imanifestlog, manifest.manifestlog)
Gregory Szorc
manifest: proxy to revlog instance instead of inheriting...
r39350 ziverify.verifyClass(repository.imanifeststorage, manifest.manifestrevlog)
Gregory Szorc
filelog: declare that filelog implements a storage interface...
r37459
Augie Fackler
formatting: blacken the codebase...
r43346 ziverify.verifyClass(
repository.irevisiondelta, simplestorerepo.simplestorerevisiondelta
)
Augie Fackler
tests: add simplestorerepo to test-check-interfaces.py...
r41194 ziverify.verifyClass(repository.ifilestorage, simplestorerepo.filestorage)
Augie Fackler
formatting: blacken the codebase...
r43346 ziverify.verifyClass(
repository.iverifyproblem, simplestorerepo.simplefilestoreproblem
)
Augie Fackler
tests: add simplestorerepo to test-check-interfaces.py...
r41194
Augie Fackler
interfaces: introduce an interface for dirstate implementations...
r43197 ziverify.verifyClass(intdirstate.idirstate, dirstate.dirstate)
Augie Fackler
tests: make test-check-interfaces.py work on Python 3...
r37887 vfs = vfsmod.vfs(b'.')
fl = filelog.filelog(vfs, b'dummy.i')
Gregory Szorc
filelog: declare that filelog implements a storage interface...
r37459 checkzobject(fl, allowextra=True)
Gregory Szorc
repository: define manifest interfaces...
r38549 # Conforms to imanifestlog.
Augie Fackler
formatting: blacken the codebase...
r43346 ml = manifest.manifestlog(
vfs, repo, manifest.manifestrevlog(repo.svfs), repo.narrowmatch()
)
Gregory Szorc
repository: define manifest interfaces...
r38549 checkzobject(ml)
checkzobject(repo.manifestlog)
# Conforms to imanifestrevision.
mctx = ml[repo[0].manifestnode()]
checkzobject(mctx)
# Conforms to imanifestrevisionwritable.
checkzobject(mctx.copy())
# Conforms to imanifestdict.
checkzobject(mctx.read())
Gregory Szorc
manifest: proxy to revlog instance instead of inheriting...
r39350 mrl = manifest.manifestrevlog(vfs)
checkzobject(mrl)
Augie Fackler
formatting: blacken the codebase...
r43346 ziverify.verifyClass(repository.irevisiondelta, revlog.revlogrevisiondelta)
Gregory Szorc
repository: formalize interfaces for revision deltas and requests...
r39266
Gregory Szorc
repository: establish API for emitting revision deltas...
r39267 rd = revlog.revlogrevisiondelta(
Gregory Szorc
repository: formalize interfaces for revision deltas and requests...
r39266 node=b'',
p1node=b'',
p2node=b'',
basenode=b'',
linknode=b'',
flags=b'',
baserevisionsize=None,
revision=b'',
Augie Fackler
formatting: blacken the codebase...
r43346 delta=None,
)
Gregory Szorc
repository: formalize interfaces for revision deltas and requests...
r39266 checkzobject(rd)
Augie Fackler
formatting: blacken the codebase...
r43346 ziverify.verifyClass(repository.iverifyproblem, revlog.revlogproblem)
Gregory Szorc
verify: start to abstract file verification...
r39878 checkzobject(revlog.revlogproblem())
Augie Fackler
formatting: blacken the codebase...
r43346
Gregory Szorc
tests: verify that peer instances only expose interface members...
r33806 main()