[Zodb-checkins] CVS: Zope/lib/python/Persistence/tests - test_mapping.py:1.1

Jim Fulton jim at zope.com
Mon Dec 15 01:58:27 EST 2003


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

Added Files:
	test_mapping.py 
Log Message:
Added tests for the mapping class.


=== Added File Zope/lib/python/Persistence/tests/test_mapping.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.
#
##############################################################################
"""XXX short summary goes here.

$Id: test_mapping.py,v 1.1 2003/12/15 06:58:26 jim Exp $
"""
import unittest
from doctest import DocTestSuite
from Persistence import PersistentMapping

def test_basic_functionality():
    """
    >>> m = PersistentMapping({'x': 1}, a=2, b=3)
    >>> m['name'] = 'bob'
    >>> m['fred']
    Traceback (most recent call last):
    ...
    KeyError: 'fred'
    >>> m.get('fred')
    >>> m.get('fred', 42)
    42
    >>> m.get('name', 42)
    'bob'
    >>> m.get('name')
    'bob'
    >>> m['name']
    'bob'

    >>> keys = m.keys()
    >>> keys.sort()
    >>> keys
    ['a', 'b', 'name', 'x']

    >>> values = m.values()
    >>> values.sort()
    >>> values
    [1, 2, 3, 'bob']

    >>> items = m.items()
    >>> items.sort()
    >>> items
    [('a', 2), ('b', 3), ('name', 'bob'), ('x', 1)]

    >>> keys = list(m.iterkeys())
    >>> keys.sort()
    >>> keys
    ['a', 'b', 'name', 'x']

    >>> values = list(m.itervalues())
    >>> values.sort()
    >>> values
    [1, 2, 3, 'bob']

    >>> items = list(m.iteritems())
    >>> items.sort()
    >>> items
    [('a', 2), ('b', 3), ('name', 'bob'), ('x', 1)]

    >>> 'name' in m
    True

    """

def test_old_pickles():
    """
    >>> m = PersistentMapping()
    >>> m.__setstate__({'_container': {'x': 1, 'y': 2}})
    >>> items = m.items()
    >>> items.sort()
    >>> items
    [('x', 1), ('y', 2)]
    
    """

def test_suite():
    return unittest.TestSuite((
        DocTestSuite(),
        ))

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




More information about the Zodb-checkins mailing list