Commit 69b5b252 authored by Tres Seaver's avatar Tres Seaver

Convert doctests to unittests.

parent 13ad544d
##############################################################################
#
# Copyright (c) Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (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.
#
##############################################################################
import unittest
try:
from persistent import simple_new
except ImportError:
simple_new = None
def cpersistent_setstate_pointer_sanity():
"""
>>> from persistent import Persistent
>>> class P(Persistent):
... def __init__(self):
... self.x = 0
... def inc(self):
... self.x += 1
>>>
>>> Persistent().__setstate__({})
Traceback (most recent call last):
...
TypeError: this object has no instance dictionary
>>> class C(Persistent): __slots__ = 'x', 'y'
>>> C().__setstate__(({}, {}))
Traceback (most recent call last):
...
TypeError: this object has no instance dictionary
"""
if simple_new is not None:
def cpersistent_simple_new_invalid_argument():
"""
>>> simple_new('')
Traceback (most recent call last):
...
TypeError: simple_new argument must be a type object.
"""
def test_suite():
import doctest
return unittest.TestSuite((
doctest.DocFileSuite("persistent.txt"),
doctest.DocTestSuite(),
))
......@@ -1118,7 +1118,8 @@ class PyPersistentTests(unittest.TestCase, _Persistent_Base):
def _clearMRU(self, jar):
jar._cache._mru[:] = []
_add_to_suite = [PyPersistentTests]
try:
from persistent import cPersistence
......@@ -1140,3 +1141,23 @@ else:
def _makeCache(self, jar):
from persistent.cPickleCache import PickleCache
return PickleCache(jar)
_add_to_suite.append(CPersistentTests)
class Test_simple_new(unittest.TestCase):
def _callFUT(self, x):
from persistent.cPersistence import simple_new
return simple_new(x)
def test_w_non_type(self):
self.assertRaises(TypeError, self._callFUT, '')
def test_w_type(self):
for typ in (type, list, dict, tuple, object):
self.assertTrue(isinstance(self._callFUT(typ), typ))
_add_to_suite.append(Test_simple_new)
def test_suite():
return unittest.TestSuite(_add_to_suite)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment