home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2009 June / maximum-cd-2009-06.iso / DiscContents / digsby_setup.exe / lib / protocols / tests / test_direct.pyo (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2009-02-26  |  5.8 KB  |  146 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.5)
  3.  
  4. from unittest import TestCase, makeSuite, TestSuite
  5. from protocols import *
  6. from checks import ProviderChecks, AdaptiveChecks, ClassProvidesChecks
  7. from checks import makeClassProvidesTests, makeInstanceTests
  8. from checks import makeMetaClassProvidesTests
  9.  
  10. class IA(Interface):
  11.     pass
  12.  
  13.  
  14. class IB(IA):
  15.     pass
  16.  
  17.  
  18. class IPure(Interface):
  19.     pass
  20.  
  21.  
  22. class BasicChecks(AdaptiveChecks, ProviderChecks):
  23.     IA = IA
  24.     IB = IB
  25.     Interface = Interface
  26.     IPure = IPure
  27.     
  28.     def checkCircularRegister(self):
  29.         P1 = Protocol()
  30.         P2 = Protocol()
  31.         declareAdapter(NO_ADAPTER_NEEDED, provides = [
  32.             P2], forProtocols = [
  33.             P1])
  34.         declareAdapter(NO_ADAPTER_NEEDED, provides = [
  35.             P1], forProtocols = [
  36.             P2])
  37.         self.declareObImplements([
  38.             P1])
  39.  
  40.  
  41.  
  42. class ClassChecks(ClassProvidesChecks, BasicChecks):
  43.     pass
  44.  
  45.  
  46. class InstanceConformChecks:
  47.     
  48.     def checkBadConform(self):
  49.         
  50.         def __conform__(proto):
  51.             pass
  52.  
  53.         self.ob.__conform__ = __conform__
  54.         self.assertBadConform(self.ob, [
  55.             self.IA], __conform__)
  56.  
  57.     
  58.     def assertBadConform(self, ob, protocols, conform):
  59.         
  60.         try:
  61.             adviseObject(ob, provides = protocols)
  62.         except TypeError:
  63.             v = None
  64.  
  65.         raise AssertionError("Should've detected invalid __conform__")
  66.  
  67.  
  68.  
  69. class ClassConformChecks(InstanceConformChecks):
  70.     
  71.     def checkInheritedConform(self):
  72.         
  73.         class Base(self.ob):
  74.             
  75.             def __conform__(self, protocol):
  76.                 pass
  77.  
  78.  
  79.         
  80.         class Sub(Base):
  81.             pass
  82.  
  83.         self.assertBadConform(Sub, [
  84.             self.IA], Base.__conform__.im_func)
  85.  
  86.     
  87.     def checkInstanceConform(self):
  88.         
  89.         class Base(self.ob):
  90.             
  91.             def __conform__(self, protocol):
  92.                 pass
  93.  
  94.  
  95.         b = Base()
  96.         self.assertBadConform(b, [
  97.             self.IA], b.__conform__)
  98.  
  99.  
  100.  
  101. class AdviseMixinInstance(BasicChecks):
  102.     
  103.     def setUp(self):
  104.         self.ob = ProviderMixin()
  105.  
  106.  
  107.  
  108. class AdviseMixinMultiMeta1(BasicChecks):
  109.     
  110.     def setUp(self):
  111.         
  112.         class Meta(ProviderMixin, type):
  113.             pass
  114.  
  115.         
  116.         class Test((ProviderMixin, object)):
  117.             __metaclass__ = Meta
  118.  
  119.         self.ob = Test()
  120.  
  121.  
  122.  
  123. class InstanceTestsBase(BasicChecks, InstanceConformChecks):
  124.     pass
  125.  
  126.  
  127. class ClassTestsBase(ClassChecks, ClassConformChecks):
  128.     pass
  129.  
  130.  
  131. class Picklable:
  132.     pass
  133.  
  134.  
  135. class NewStyle(object):
  136.     pass
  137.  
  138. TestClasses = (AdviseMixinInstance, AdviseMixinMultiMeta1)
  139. TestClasses += makeMetaClassProvidesTests(ClassChecks)
  140. TestClasses += makeClassProvidesTests(ClassTestsBase)
  141. TestClasses += makeInstanceTests(InstanceTestsBase, Picklable, NewStyle)
  142.  
  143. def test_suite():
  144.     return []([ makeSuite(t, 'check') for t in TestClasses ])
  145.  
  146.