[Zope-Checkins] CVS: Zope/lib/python/ExtensionClass/tests - __init__.py:1.1.2.1 test_ec.py:1.1.2.1

Jim Fulton jim at zope.com
Sun Oct 19 17:25:43 EDT 2003


Update of /cvs-repository/Zope/lib/python/ExtensionClass/tests
In directory cvs.zope.org:/tmp/cvs-serv1926/lib/python/ExtensionClass/tests

Added Files:
      Tag: zodb33-devel-branch
	__init__.py test_ec.py 
Log Message:
New-style ExtensionClass, in C.

This is an initial cut. The next step is to start converting some of
the old EC extensions, like Acquisition and Persistent.


=== Added File Zope/lib/python/ExtensionClass/tests/__init__.py ===
#


=== Added File Zope/lib/python/ExtensionClass/tests/test_ec.py ===
##############################################################################
#
# Copyright (c) 2003 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""

$Id: test_ec.py,v 1.1.2.1 2003/10/19 21:25:42 jim Exp $
"""

from doctest import DocTestSuite
import unittest

def test_xxx():
    """
    >>> from ExtensionClass import *

    Test creating basic classes and objects and test that class_init is called

    >>> class C(Base):
    ...   def __class_init__(self):
    ...      print 'class init called'
    ...      print self.__name__
    ... 
    class init called
    C
    >>> c = C()
    >>> int(c.__class__ is C)
    1
    >>> int(c.__class__ is type(c))
    1

    Test that __of__ works

    >>> class O(Base):
    ...   def __of__(*a):
    ...      return a
    ... 
    >>> o1 = O()
    >>> o2 = O()
    >>> C.o1 = o1
    >>> c.o2 = o2
    >>> int(c.o1 == (o1, c))
    1
    >>> int(c.o2 == (o2, c))
    1

    Test inherited attribute:

    >>> class O2(O):
    ...   def __of__(*a):
    ...      return O2.inheritedAttribute('__of__')(*a), 42
    ... 
    >>> o2 = O2()
    >>> c.o2 = o2
    >>> int(c.o2 == ((o2, c), 42))
    1

    Test working with a classic class

    >>> class Classic: 
    ...   def x(self): 
    ...     return 42
    ... 
    >>> class O2(Classic, O):
    ...   def __of__(*a):
    ...      return (O2.inheritedAttribute('__of__')(*a), 
    ...              O2.inheritedAttribute('x')(a[0]))
    ... 
    >>> o2 = O2()
    >>> c.o2 = o2
    >>> int(c.o2 == ((o2, c), 42))
    1


    Test working with a ew style

    >>> class Modern(object): 
    ...   def x(self): 
    ...     return 42
    ... 
    >>> class O2(Modern, O):
    ...   def __of__(*a):
    ...      return (O2.inheritedAttribute('__of__')(*a), 
    ...              O2.inheritedAttribute('x')(a[0]))
    ... 
    >>> o2 = O2()
    >>> c.o2 = o2
    >>> int(c.o2 == ((o2, c), 42))
    1

    """


def test_suite():
    return DocTestSuite()

if __name__ == '__main__': unittest.main()




More information about the Zope-Checkins mailing list