[Checkins] SVN: persistent/trunk/ Convert doctests to unittests.

Tres Seaver cvs-admin at zope.org
Thu Jun 28 22:49:39 UTC 2012


Log message for revision 127153:
  Convert doctests to unittests.

Changed:
  _U  persistent/trunk/
  D   persistent/trunk/persistent/tests/test_persistent.py
  U   persistent/trunk/persistent/tests/test_pyPersistence.py

-=-
Deleted: persistent/trunk/persistent/tests/test_persistent.py
===================================================================
--- persistent/trunk/persistent/tests/test_persistent.py	2012-06-28 22:49:32 UTC (rev 127152)
+++ persistent/trunk/persistent/tests/test_persistent.py	2012-06-28 22:49:36 UTC (rev 127153)
@@ -1,57 +0,0 @@
-##############################################################################
-#
-# 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(),
-    ))

Modified: persistent/trunk/persistent/tests/test_pyPersistence.py
===================================================================
--- persistent/trunk/persistent/tests/test_pyPersistence.py	2012-06-28 22:49:32 UTC (rev 127152)
+++ persistent/trunk/persistent/tests/test_pyPersistence.py	2012-06-28 22:49:36 UTC (rev 127153)
@@ -1118,7 +1118,8 @@
 
     def _clearMRU(self, jar):
         jar._cache._mru[:] = []
-        
+ 
+_add_to_suite = [PyPersistentTests]
 
 try:
     from persistent import cPersistence
@@ -1140,3 +1141,23 @@
         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)



More information about the checkins mailing list