Example #1
0
    def assertInterfacesImplemented(self, cls):
        "Given a class, assert that the zope.interface.Interfaces are implemented to specification."

        # see if this version of zope.interface is too old to run these tests
        zi_vers = pkg_resources.working_set.find(
            pkg_resources.Requirement.parse('zope.interface')).version
        if pkg_resources.parse_version(zi_vers) < pkg_resources.parse_version('4.1.1'):
            raise unittest.SkipTest("zope.interfaces is too old to run this test")

        import zope.interface.interface
        for interface in zope.interface.implementedBy(cls):
            for attr, template_argspec in interface.namesAndDescriptions():
                if not hasattr(cls, attr):
                    msg = "Expected: %r; to implement: %s as specified in %r" % (
                        cls, attr,
                        interface)
                    self.fail(msg)
                actual_argspec = getattr(cls, attr)
                while hasattr(actual_argspec, 'func_original'):
                    actual_argspec = actual_argspec.func_original
                actual_argspec = zope.interface.interface.fromMethod(actual_argspec)

                if actual_argspec.getSignatureInfo() != template_argspec.getSignatureInfo():
                    msg = "%s: expected: %s; got: %s" % (
                        attr,
                        template_argspec.getSignatureString(),
                        actual_argspec.getSignatureString())
                    self.fail(msg)
Example #2
0
    def assertInterfacesImplemented(self, cls):
        "Given a class, assert that the zope.interface.Interfaces are implemented to specification."

        # see if this version of zope.interface is too old to run these tests
        zi_vers = pkg_resources.working_set.find(
            pkg_resources.Requirement.parse('zope.interface')).version
        if pkg_resources.parse_version(zi_vers) < pkg_resources.parse_version(
                '4.1.1'):
            raise unittest.SkipTest(
                "zope.interfaces is too old to run this test")

        for interface in zope.interface.implementedBy(cls):
            for attr, template_argspec in interface.namesAndDescriptions():
                if not hasattr(cls, attr):
                    msg = "Expected: %r; to implement: %s as specified in %r" % (
                        cls, attr, interface)
                    self.fail(msg)
                actual_argspec = getattr(cls, attr)
                if isinstance(template_argspec, Attribute):
                    continue
                # else check method signatures
                while hasattr(actual_argspec, '__wrapped__'):
                    actual_argspec = actual_argspec.__wrapped__
                actual_argspec = zope.interface.interface.fromMethod(
                    actual_argspec)

                if actual_argspec.getSignatureInfo(
                ) != template_argspec.getSignatureInfo():
                    msg = "%s: expected: %s; got: %s" % (
                        attr, template_argspec.getSignatureString(),
                        actual_argspec.getSignatureString())
                    self.fail(msg)
Example #3
0
    def assertInterfacesImplemented(self, cls):
        "Given a class, assert that the zope.interface.Interfaces are implemented to specification."
        import zope.interface.interface
        for interface in zope.interface.implementedBy(cls):
            for attr, template_argspec in interface.namesAndDescriptions():
                if not hasattr(cls, attr):
                    msg = "Expected: %r; to implement: %s as specified in %r" % (
                        cls, attr,
                        interface)
                    self.fail(msg)
                actual_argspec = getattr(cls, attr)
                while hasattr(actual_argspec, 'func_original'):
                    actual_argspec = actual_argspec.func_original
                actual_argspec = zope.interface.interface.fromMethod(actual_argspec)

                if actual_argspec.getSignatureInfo() != template_argspec.getSignatureInfo():
                    msg = "%s: expected: %s; got: %s" % (
                        attr,
                        template_argspec.getSignatureString(),
                        actual_argspec.getSignatureString())
                    self.fail(msg)
Example #4
0
    def assertInterfacesImplemented(self, cls):
        "Given a class, assert that the zope.interface.Interfaces are implemented to specification."
        import zope.interface.interface
        for interface in zope.interface.implementedBy(cls):
            for attr, template_argspec in interface.namesAndDescriptions():
                if not hasattr(cls, attr):
                    msg = "Expected: %r; to implement: %s as specified in %r" % (
                        cls, attr, interface)
                    self.fail(msg)
                actual_argspec = getattr(cls, attr)
                while hasattr(actual_argspec, 'func_original'):
                    actual_argspec = actual_argspec.func_original
                actual_argspec = zope.interface.interface.fromMethod(
                    actual_argspec)

                if actual_argspec.getSignatureInfo(
                ) != template_argspec.getSignatureInfo():
                    msg = "%s: expected: %s; got: %s" % (
                        attr, template_argspec.getSignatureString(),
                        actual_argspec.getSignatureString())
                    self.fail(msg)