Skip to content

Commit

Permalink
100% branch coverage for 'zope.interface.interface'.
Browse files Browse the repository at this point in the history
  • Loading branch information
tseaver committed Dec 8, 2014
1 parent 409173e commit 74e1d92
Showing 1 changed file with 45 additions and 23 deletions.
68 changes: 45 additions & 23 deletions src/zope/interface/tests/test_interface.py
Expand Up @@ -353,6 +353,44 @@ class I(Interface):
self.failUnless(getattr(spec, '_v_attrs', self) is self)
self.failIf(I in spec._implied)

def test_interfaces_skips_already_seen(self):
from zope.interface.interface import Interface
class IFoo(Interface):
pass
spec = self._makeOne([IFoo, IFoo])
self.assertEqual(list(spec.interfaces()), [IFoo])

def test_extends_strict_wo_self(self):
from zope.interface.interface import Interface
class IFoo(Interface):
pass
spec = self._makeOne(IFoo)
self.assertFalse(spec.extends(IFoo, strict=True))

def test_extends_strict_w_self(self):
spec = self._makeOne()
self.assertFalse(spec.extends(spec, strict=True))

def test_extends_non_strict_w_self(self):
spec = self._makeOne()
self.assertTrue(spec.extends(spec, strict=False))

def test_get_hit_w__v_attrs(self):
spec = self._makeOne()
foo = object()
spec._v_attrs = {'foo': foo}
self.assertTrue(spec.get('foo') is foo)

def test_get_hit_from_base_wo__v_attrs(self):
from zope.interface.interface import Attribute
from zope.interface.interface import Interface
class IFoo(Interface):
foo = Attribute('foo')
class IBar(Interface):
bar = Attribute('bar')
spec = self._makeOne([IFoo, IBar])
self.assertTrue(spec.get('foo') is IFoo.get('foo'))
self.assertTrue(spec.get('bar') is IBar.get('bar'))

class InterfaceClassTests(_SilencePy3Deprecations):

Expand Down Expand Up @@ -410,12 +448,18 @@ def test_ctor_attrs_w__decorator_non_return(self):
self.assertEqual(inst.__bases__, ())
self.assertEqual(list(inst.names()), [])

def test_ctor_attrs_w_invalide_attr_type(self):
def test_ctor_attrs_w_invalid_attr_type(self):
from zope.interface.exceptions import InvalidInterface
ATTRS = {'invalid': object()}
klass = self._getTargetClass()
self.assertRaises(InvalidInterface, klass, 'ITesting', attrs=ATTRS)

def test_ctor_w_explicit___doc__(self):
ATTRS = {'__doc__': 'ATTR'}
klass = self._getTargetClass()
inst = klass('ITesting', attrs=ATTRS, __doc__='EXPLICIT')
self.assertEqual(inst.__doc__, 'EXPLICIT')

def test_interfaces(self):
iface = self._makeOne()
self.assertEqual(list(iface.interfaces()), [iface])
Expand Down Expand Up @@ -666,12 +710,6 @@ def test_queryDescriptionFor_hit(self):
iface = self._makeOne(attrs=ATTRS)
self.assertEqual(iface.queryDescriptionFor('attr'), ATTRS['attr'])


#TODO (or not: 'deferred' looks like a fossil to me.
#def test_deferred_cache_hit(self):
#def test_deferred_cache_miss(self):
#def test_deferred_cache_miss_w_bases(self):

def test_validateInvariants_pass(self):
_called_with = []
def _passable(*args, **kw):
Expand Down Expand Up @@ -734,7 +772,6 @@ def _fail(*args, **kw):
self.assertEqual(_passable_called_with, [((obj,), {})])
self.assertEqual(_fail_called_with, [((obj,), {})])

#TODO
def test_validateInvariants_fail_in_base_w_errors_passed(self):
from zope.interface.exceptions import Invalid
_errors = []
Expand Down Expand Up @@ -1007,21 +1044,6 @@ class Mixed(Left, Right):
self.failIf(IRight in providedBy(mixed))
self.failUnless(IOther in providedBy(mixed))

def test_interface_deferred_class_method_broken(self):
from zope.interface import Interface
from zope.interface.exceptions import BrokenImplementation

class IDeferring(Interface):
def method():
pass

class Deferring(IDeferring.deferred()):
__implemented__ = IDeferring

deferring = Deferring()

self.assertRaises(BrokenImplementation, deferring.method)

def testInterfaceExtendsInterface(self):
from zope.interface import Interface

Expand Down

0 comments on commit 74e1d92

Please sign in to comment.