Skip to content

Commit

Permalink
Merge pull request #75 from seequent/#74-fix-adaption-of-interface-only
Browse files Browse the repository at this point in the history
Fix adaption error
  • Loading branch information
tim-mitchell authored May 20, 2020
2 parents 0bcff01 + 789746b commit ee34aed
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 2 additions & 0 deletions pure_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,8 @@ def interface_only(cls, implementation):
def adapt(cls, obj, allow_implicit=False, interface_only=None):
if interface_only is None:
interface_only = is_development
if isinstance(obj, _ImplementationWrapper):
obj = obj._ImplementationWrapper__impl
if InterfaceType.provided_by(cls, obj, allow_implicit=allow_implicit):
adapter = no_adaption
else:
Expand Down
16 changes: 15 additions & 1 deletion tests/test_adaption.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
import mock


class ITalker(pure_interface.Interface):
def talk(self):
pass


class ISpeaker(pure_interface.Interface):
def speak(self, volume):
pass
Expand All @@ -24,7 +29,7 @@ def speak(self, volume):
return 'speak'


class Talker(object):
class Talker(ITalker, object):
def talk(self):
return 'talk'

Expand Down Expand Up @@ -326,3 +331,12 @@ def test_optional_adapt(self):
adapt.assert_called_once_with(ISpeaker, a_speaker, allow_implicit=allow, interface_only=interface_only)
self.assertIs(s, adapt.return_value)
self.assertIsNone(none, 'optional_adapt(None) did not return None')

def test_adapt_interface_only(self):
talker = Talker()
talker_only = ITalker.adapt(talker)
self.assertIsInstance(talker_only, pure_interface._ImplementationWrapper)
try:
ISpeaker.adapt(talker_only)
except:
self.fail('adaption of interface only failed.')

0 comments on commit ee34aed

Please sign in to comment.