diff tests/test-check-interfaces.py @ 37320:39f7d4ee8bcd

repository: port peer interfaces to zope.interface zope.interface is superior. Let's switch to it. Unlike abc, which defines interfaces through a base class, zope.interface uses different types for interfaces and for implementations. So, we had to invent some new types to hold the interfaces in order to separate the interface from its default implementation. The names here could probably be better. I've been wanting to overhaul the peer interface for a while. And wire protocol version 2 will force that work. So anticipate a refactoring of these interfaces in later commits. With this commit, we no longer test abc interfaces in test-check-interfaces.py, so code for that has been removed. Differential Revision: https://phab.mercurial-scm.org/D3068 # no-check-commit because of stream_out()
author Gregory Szorc <gregory.szorc@gmail.com>
date Fri, 30 Mar 2018 18:53:17 -0700
parents 78103e4138b1
children a3202fa83aff
line wrap: on
line diff
--- a/tests/test-check-interfaces.py	Fri Mar 30 14:52:32 2018 -0700
+++ b/tests/test-check-interfaces.py	Fri Mar 30 18:53:17 2018 -0700
@@ -25,35 +25,6 @@
 
 rootdir = os.path.normpath(os.path.join(os.path.dirname(__file__), '..'))
 
-def checkobject(o):
-    """Verify a constructed object conforms to interface rules.
-
-    An object must have __abstractmethods__ defined.
-
-    All "public" attributes of the object (attributes not prefixed with
-    an underscore) must be in __abstractmethods__ or appear on a base class
-    with __abstractmethods__.
-    """
-    name = o.__class__.__name__
-
-    allowed = set()
-    for cls in o.__class__.__mro__:
-        if not getattr(cls, '__abstractmethods__', set()):
-            continue
-
-        allowed |= cls.__abstractmethods__
-        allowed |= {a for a in dir(cls) if not a.startswith('_')}
-
-    if not allowed:
-        print('%s does not have abstract methods' % name)
-        return
-
-    public = {a for a in dir(o) if not a.startswith('_')}
-
-    for attr in sorted(public - allowed):
-        print('public attributes not in abstract interface: %s.%s' % (
-            name, attr))
-
 def checkzobject(o):
     """Verify an object with a zope interface."""
     ifaces = zi.providedBy(o)
@@ -108,16 +79,34 @@
     # Needed so we can open a local repo with obsstore without a warning.
     ui.setconfig('experimental', 'evolution.createmarkers', True)
 
-    checkobject(badpeer())
-    checkobject(httppeer.httppeer(None, None, None, dummyopener()))
-    checkobject(localrepo.localpeer(dummyrepo()))
-    checkobject(sshpeer.sshv1peer(ui, 'ssh://localhost/foo', None, dummypipe(),
-                                  dummypipe(), None, None))
-    checkobject(sshpeer.sshv2peer(ui, 'ssh://localhost/foo', None, dummypipe(),
-                                  dummypipe(), None, None))
-    checkobject(bundlerepo.bundlepeer(dummyrepo()))
-    checkobject(statichttprepo.statichttppeer(dummyrepo()))
-    checkobject(unionrepo.unionpeer(dummyrepo()))
+    checkzobject(badpeer())
+
+    ziverify.verifyClass(repository.ipeerbaselegacycommands,
+                         httppeer.httppeer)
+    checkzobject(httppeer.httppeer(None, None, None, dummyopener()))
+
+    ziverify.verifyClass(repository.ipeerbase,
+                         localrepo.localpeer)
+    checkzobject(localrepo.localpeer(dummyrepo()))
+
+    ziverify.verifyClass(repository.ipeerbaselegacycommands,
+                         sshpeer.sshv1peer)
+    checkzobject(sshpeer.sshv1peer(ui, 'ssh://localhost/foo', None, dummypipe(),
+                                   dummypipe(), None, None))
+
+    ziverify.verifyClass(repository.ipeerbaselegacycommands,
+                         sshpeer.sshv2peer)
+    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()))
 
     ziverify.verifyClass(repository.completelocalrepository,
                          localrepo.localrepository)