home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyo (Python 2.5)
-
- from unittest import TestSuite, TestCase, makeSuite
- from protocols import adapt, advise, Interface, Attribute, declareAdapter
- from protocols import AbstractBase, AdaptationFailure
-
- class APITests(TestCase):
-
- def checkAdaptTrapsTypeErrorsOnConform(self):
-
- class Conformer:
-
- def __conform__(self, ob):
- return []
-
-
-
-
- def checkAdaptHandlesIsInstance(self):
- pass
-
-
- def checkAdviseFailsInCallContext(self):
-
- try:
- advise()
- except SyntaxError:
- pass
-
- raise AssertionError("Should've got SyntaxError for advise() in function")
-
-
- def checkAdviseClassKeywordsValidated(self):
-
- try:
-
- class X:
- advise(moduleProvides = list)
-
- except TypeError:
- v = None
-
- raise AssertionError("Should've caught invalid keyword")
-
-
- def checkAdviseClassKeywordsValidated(self):
-
- try:
-
- class X:
- advise(moduleProvides = list)
-
- except TypeError:
- v = None
-
- raise AssertionError("Should've caught invalid keyword")
-
-
- def checkAdviseModuleKeywordsValidated(self):
-
- try:
- exec 'advise(instancesProvide=[IProtocol1])' in globals(), globals()
- except TypeError:
- v = None
-
- raise AssertionError("Should've caught invalid keyword")
-
-
- def checkAdviseInClassExec(self):
- d = {
- 'advise': advise,
- 'IProtocol1': IProtocol1 }
- exec 'class Foo: advise(instancesProvide=[IProtocol1])' in d
-
-
- def checkSimpleAdaptation(self):
-
- class Conformer:
-
- def __conform__(self, protocol):
- if protocol == 42:
- return ('hitchhiker', self)
-
-
-
-
- class AdaptingProtocol:
-
- def __adapt__(klass, ob):
- return ('adapted', ob)
-
- __adapt__ = classmethod(__adapt__)
-
- c = Conformer()
-
-
- def checkAdaptFiltersTypeErrors(self):
-
- class Nonconformist:
-
- def __conform__(self, ob):
- raise TypeError('You got me!')
-
-
-
- class Unadaptive:
-
- def __adapt__(self, ob):
- raise TypeError('You got me!')
-
-
- self.assertTypeErrorPassed(None, Unadaptive(), None)
- self.assertTypeErrorPassed(Nonconformist(), None, None)
- self.assertRaises(AdaptationFailure, adapt, None, None)
-
-
- def assertTypeErrorPassed(self, *args):
-
- try:
- adapt(*args)
- except TypeError:
- v = None
-
- raise AssertionError("Should've passed TypeError through")
-
-
- def checkImplicationBug(self):
-
- class I1(Interface):
- pass
-
-
- class I2(I1):
- pass
-
- declareAdapter((lambda o: o), provides = [
- I1], forProtocols = [
- I2])
-
-
- def checkAttribute(self):
- for Abstract in range(10) + [
- None]:
- i = None
- ob = Abstract()
- for j in range(10):
- ob.value = j
-
-
-
-
- def checkStickyAdapter(self):
-
- class T:
- pass
-
- t = T()
-
- class I(Interface):
- pass
-
- StickyAdapter = StickyAdapter
- import protocols.adapters
-
- class A('A', (StickyAdapter,)):
- attachForProtocols = (I,)
- advise(instancesProvide = [
- I], asAdapterForTypes = [
- T])
-
- a = I(t)
- n = T()
- a2 = I(n)
-
-
- from protocols import protocolForType, protocolForURI, sequenceOf, advise
- from protocols import declareImplementation, Variation
- from UserDict import UserDict
- IGetSetMapping = protocolForType(dict, [
- '__getitem__',
- '__setitem__'])
- IGetMapping = protocolForType(dict, [
- '__getitem__'])
- ISimpleReadFile = protocolForType(file, [
- 'read'])
- IImplicitRead = protocolForType(file, [
- 'read'], implicit = True)
- IProtocol1 = protocolForURI('http://peak.telecommunity.com/PyProtocols')
- multimap = sequenceOf(IGetMapping)
- declareImplementation(UserDict, [
- IGetSetMapping])
- IMyUnusualMapping = Variation(IGetSetMapping)
-
- class MyUserMapping(object):
- pass
-
- declareImplementation(MyUserMapping, [
- IMyUnusualMapping])
-
- class GenerationTests(TestCase):
-
- def checkTypeSubset(self):
- d = { }
-
-
- def checkImplications(self):
- d = UserDict()
-
-
- def checkWeak(self):
- StringIO = StringIO
- import cStringIO
- s = StringIO('foo')
-
-
- def checkURI(self):
- p = protocolForURI('http://www.python.org/')
- p = protocolForURI('http://peak.telecommunity.com/PyProtocols')
-
-
- def checkSequence(self):
- d1 = { }
- d2 = { }
- seq = multimap([
- d1,
- d2])
-
- class ISequenceLike(Interface):
- advise(protocolIsSubsetOf = [
- multimap])
-
- ISequenceLike([
- d1,
- d2])
-
-
- def checkVariation(self):
- d = { }
- d = MyUserMapping()
- self.assertEqual(repr(IMyUnusualMapping), "Variation(TypeSubset(<type 'dict'>,('__getitem__', '__setitem__')))")
- self.assertEqual(repr(Variation(Interface, 42)), "Variation(<class 'protocols.interfaces.Interface'>,42)")
-
-
-
- def test_suite():
- test_advice = test_advice
- test_direct = test_direct
- test_classes = test_classes
- import protocols.tests
- tests = [
- test_advice.test_suite(),
- test_classes.test_suite(),
- test_direct.test_suite(),
- makeSuite(APITests, 'check'),
- makeSuite(GenerationTests, 'check')]
-
- try:
- import zope.interface as zope
- except ImportError:
- pass
-
- test_zope = test_zope
- import protocols.tests
- tests.append(test_zope.test_suite())
-
- try:
- Interface = Interface
- import twisted.python.components
- except (ImportError, SystemError):
- pass
-
- test_twisted = test_twisted
- import protocols.tests
- tests.append(test_twisted.test_suite())
- return TestSuite(tests)
-
-