[Zope3-checkins] CVS: Products3/z3checkins/tests - mbox_with_dupes.txt:1.1 test_message.py:1.18

Gintautas Miliauskas gintas at pov.lt
Tue Feb 10 11:20:29 EST 2004


Update of /cvs-repository/Products3/z3checkins/tests
In directory cvs.zope.org:/tmp/cvs-serv18601/tests

Modified Files:
	test_message.py 
Added Files:
	mbox_with_dupes.txt 
Log Message:
* duplicate messages are now handled (the new one is ignored)
* added sizing adapter for nice sorting
* added unit tests for name choosing and sizing adapters
* added a view for messages


=== Added File Products3/z3checkins/tests/mbox_with_dupes.txt ===
>From steve at cat-box.net  Sat Jun  1 00:31:53 2002
From: steve at cat-box.net (Steve Alexander)
Date: Fri, 31 May 2002 19:31:53 -0400
Subject: [Zope-Checkins] CVS: Zope3/lib/python/Zope/App/Security - PermissionRegistry.py:1.1.2.16.14.1
Message-ID: <200205312331.g4VNVr927566 at cvs.baymountain.com>

Update of /cvs-repository/Zope3/lib/python/Zope/App/Security
In directory cvs.zope.org:/tmp/cvs-serv27552

Modified Files:
      Tag: Zope3InWonderland-branch
        PermissionRegistry.py 
Log Message:
Permission ids must not start with a dot.


=== Zope3/lib/python/Zope/App/Security/PermissionRegistry.py 1.1.2.16 => 1.1.2.16.14.1 ===
         """Define a new permission object, register, and return it.
 
-        name is the permission name, must be globally unique
+        permission is the permission name, must be globally unique
 
         title is the permission title, human readable.
 
         description (optional) is human readable
         """
+        if permission.startswith('.'):
+            raise ValueError("permissions must not start with a '.'")
         return self.register(permission, title, description)
 
     def definedPermission(self, permission_id):




>From steve at cat-box.net  Sat Jun  1 00:31:53 2002
From: steve at cat-box.net (Steve Alexander)
Date: Fri, 31 May 2002 19:31:53 -0400
Subject: [Zope-Checkins] CVS: Zope3/lib/python/Zope/App/Security/tests - testPermissionRegistry.py:1.1.2.13.14.1
Message-ID: <200205312331.g4VNVr927566 at cvs.baymountain.com>

Update of /cvs-repository/Zope3/lib/python/Zope/App/Security/tests
In directory cvs.zope.org:/tmp/cvs-serv27552/tests

Modified Files:
      Tag: Zope3InWonderland-branch
        testPermissionRegistry.py 
Log Message:
Permission ids must not start with a dot.


=== Zope3/lib/python/Zope/App/Security/tests/testPermissionRegistry.py 1.1.2.13 => 1.1.2.13.14.1 ===
         self.assertEqual(None, permissionRegistry.getPermission('Foo'))
         self.failIf(permissionRegistry.definedPermission('Foo'))
+        
+    def testPermissionStartsWithDot(self):
+        self.assertRaises(ValueError, permissionRegistry.definePermission,
+                          '.Foo', 'dot foo title')
 
     def testPermissionIsAnIPermission(self):
         permissionRegistry.definePermission('Foo', 'foo title')
@@ -56,7 +60,7 @@
         permission = permissionRegistry.getPermission('Foo')
         eq(permission.getTitle(), 'Foo-able')
         eq(permission.getDescription(), 'A foo-worthy permission')
-    
+
 
 def test_suite():
     loader=unittest.TestLoader()




>From tim.one at comcast.net  Sat Jun  1 00:46:53 2002
From: tim.one at comcast.net (Tim Peters)
Date: Fri, 31 May 2002 19:46:53 -0400
Subject: [Zope-Checkins] CVS: Zope/lib/python/BTrees/tests - testSetOps.py:1.3
Message-ID: <200205312331.g4VNVr927566 at cvs.baymountain.com>

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

Modified Files:
        testSetOps.py 
Log Message:
testBigInput():  This spent almost all of its time building an IISet
from a sequence of ints in reverse-sorted order (a quadratic-time
proposition).  That doesn't test anything interesting in context, though.
So fiddled it to do a larger input, but it runs much faster now.


=== Zope/lib/python/BTrees/tests/testSetOps.py 1.2 => 1.3 ===
 
     def testBigInput(self):
-        input = IISet(range(50000))
-        reversed = range(50000)
-        reversed.reverse()
-        reversed = IISet(reversed)
-        output = multiunion([input, reversed] * 5)
-        self.assertEqual(len(output), 50000)
-        self.assertEqual(list(output), range(50000))
+        N = 100000
+        input = IISet(range(N))
+        output = multiunion([input] * 10)
+        self.assertEqual(len(output), N)
+        self.assertEqual(output.minKey(), 0)
+        self.assertEqual(output.maxKey(), N-1)
+        self.assertEqual(list(output), range(N))
 
     def testLotsOfLittleOnes(self):
         from random import shuffle




>From tim.one at comcast.net  Sat Jun  1 01:49:19 2002
From: tim.one at comcast.net (Tim Peters)
Date: Fri, 31 May 2002 20:49:19 -0400
Subject: [Zope-Checkins] CVS: Zope/lib/python/BTrees - SetOpTemplate.c:1.16
Message-ID: <200206010049.g510nJR14723 at cvs.baymountain.com>

Update of /cvs-repository/Zope/lib/python/BTrees
In directory cvs.zope.org:/tmp/cvs-serv14639

Modified Files:
        SetOpTemplate.c 
Log Message:
multiunion():  For an input that's IIBucket-based (IIBucket and IISet),
this now copies the keys into the work area in one gulp via memcpy,
instead of iterating over them one at a time.  Yields a nice speedup when
it applies (and it usually should apply!).


=== Zope/lib/python/BTrees/SetOpTemplate.c 1.15 => 1.16 ===
        set.  At this point, we ignore the possibility of duplicates. */
     for (i = 0; i < n; ++i) {
-        SetIteration setiter = {0, 0, 0};
-        int merge;  /* dummy needed for initSetIteration */
-
         set = PySequence_GetItem(seq, i);
         if (set == NULL)
             goto Error;
 
-        /* XXX TODO: If set is a bucket, do a straight resize+memcpy instead.
-        */
-        if (initSetIteration(&setiter, set, 1, &merge) < 0)
-            goto Error;
-        if (setiter.next(&setiter) < 0)
-            goto Error;
-        while (setiter.position >= 0) {
-            if (result->len >= result->size && Bucket_grow(result, -1, 1) < 0)
+        /* If set is a bucket, do a straight resize + memcpy. */
+        if (set->ob_type == (PyTypeObject*)&SetType ||
+            set->ob_type == (PyTypeObject*)&BucketType) {
+            const int setsize = SIZED(set)->len;
+            int size_desired = result->len + setsize;
+            /* If there are more to come, overallocate by 25% (arbitrary). */
+            if (i < n-1)
+                size_desired += size_desired >> 2;
+            if (size_desired && size_desired > result->size) {
+                if (Bucket_grow(result, size_desired, 1) < 0)
+                    goto Error;
+            }
+            memcpy(result->keys + result->len,
+                   BUCKET(set)->keys,
+                   setsize * sizeof(KEY_TYPE));
+            result->len += setsize;
+        }
+        else {
+            /* No cheap way:  iterate over set's elements one at a time. */
+            SetIteration setiter = {0, 0, 0};
+            int merge;  /* dummy needed for initSetIteration */
+            
+            if (initSetIteration(&setiter, set, 1, &merge) < 0)
                 goto Error;
-            COPY_KEY(result->keys[result->len], setiter.key);
-            ++result->len;
-            /* We know the key is an int, so no need to incref it. */
             if (setiter.next(&setiter) < 0)
                 goto Error;
+            while (setiter.position >= 0) {
+                if (result->len >= result->size && Bucket_grow(result, -1, 1) < 0)
+                    goto Error;
+                COPY_KEY(result->keys[result->len], setiter.key);
+                ++result->len;
+                /* We know the key is an int, so no need to incref it. */
+                if (setiter.next(&setiter) < 0)
+                    goto Error;
+            }
         }
         Py_DECREF(set);
         set = NULL;


=== Products3/z3checkins/tests/test_message.py 1.17 => 1.18 ===
--- Products3/z3checkins/tests/test_message.py:1.17	Tue Feb 10 09:23:29 2004
+++ Products3/z3checkins/tests/test_message.py	Tue Feb 10 11:20:29 2004
@@ -17,6 +17,7 @@
 from zope.interface.verify import verifyObject
 from zope.context import getWrapperContext, getWrapperData
 from zope.context import Wrapper
+from zope.exceptions import DuplicationError
 
 from zopeproducts.z3checkins.interfaces import IMessage, IMessageContained, \
         ICheckinMessage, IBookmark, IMessageParser, IMessageArchive
@@ -342,7 +343,13 @@
             full_text = data.read()
         else:
             full_text = data
-        return MessageStub(data=full_text)
+
+        message_id = "message at id"
+        id_lines = filter(lambda s: s.lower().startswith("message-id: "),
+                full_text.splitlines())
+        if len(id_lines) == 1:
+            message_id = id_lines[0][len("message-id: "):]
+        return MessageStub(data=full_text, message_id=message_id)
 
 class AddingStub:
 
@@ -350,6 +357,11 @@
         self.added = []
 
     def add(self, obj):
+        # ignore duplicates happening with default messages
+        if obj.message_id != "message at id":
+            for message in self.added:
+                if message.message_id == obj.message_id:
+                    raise DuplicationError()
         self.added.append(obj)
 
 class TestMessageUpload(PlacelessSetup, unittest.TestCase):
@@ -384,13 +396,26 @@
         self.assertEquals(len(added), 4)
         for message in added:
             self.assertEquals(message.__class__, MessageStub)
-            self.assertEquals(message.message_id, "message at id")
-
         self.assertEquals(added[0].data.count("Steve Alexander"), 1)
         self.assertEquals(added[1].data.count("Steve Alexander"), 1)
         self.assertEquals(added[2].data.count("Tim Peters"), 1)
         self.assertEquals(added[3].data.count("Tim Peters"), 1)
 
+    def test_createAndAdd_mbox_with_dupes(self):
+        from zopeproducts.z3checkins.message import MessageUpload
+        view = MessageUpload()
+        view.context = AddingStub()
+        view.add = view.context.add
+        added = view.context.added
+        data = open_test_data('mbox_with_dupes.txt').read()
+        self.assertEquals(len(added), 0)
+        view.createAndAdd({'data': data})
+        self.assertEquals(len(added), 2)
+        for message in added:
+            self.assertEquals(message.__class__, MessageStub)
+        self.assertEquals(added[0].data.count("Steve Alexander"), 1)
+        self.assertEquals(added[1].data.count("Tim Peters"), 1)
+
 
 class IUnitTestPresentation(Interface):
     pass
@@ -1026,6 +1051,51 @@
         self.assertEquals(view.previous(), m3)
 
 
+class TestMessageNameChooser(unittest.TestCase):
+
+    def test_chooseName(self):
+        from zopeproducts.z3checkins.folder import MessageNameChooser
+        msg = MessageStub(message_id="msg at id")
+        chooser = MessageNameChooser(None)
+        self.assertEquals(chooser.chooseName(None, msg), msg.message_id)
+        msg2 = MessageStub(message_id="foo at bar")
+        self.assertEquals(chooser.chooseName(None, msg2), msg2.message_id)
+
+    def test_checkName(self):
+        from zopeproducts.z3checkins.folder import MessageNameChooser
+        msg = MessageStub(message_id="msg at id")
+        chooser = MessageNameChooser(None)
+        self.assertEquals(chooser.checkName("msg at id", msg), True)
+
+
+class TestMessageSized(unittest.TestCase):
+
+    def test_interface(self):
+        from zopeproducts.z3checkins.folder import MessageSized
+        from zope.app.interfaces.size import ISized
+        self.assert_(ISized.isImplementedBy(MessageSized(MessageStub())))
+
+    def test_sizeForSorting(self):
+        from zopeproducts.z3checkins.folder import MessageSized
+        msg = MessageStub()
+        sized = MessageSized(msg)
+        msg.full_text = '*' * 42;
+        self.assertEquals(sized.sizeForSorting(), 42)
+        msg.full_text = '*' * 32768;
+        self.assertEquals(sized.sizeForSorting(), 32768)
+
+    def test_sizeForDisplay(self):
+        from zopeproducts.z3checkins.folder import MessageSized
+        msg = MessageStub()
+        sized = MessageSized(msg)
+        msg.full_text = '*' * 42;
+        self.assertEquals(sized.sizeForDisplay(), u"42 bytes")
+        msg.full_text = '*' * 32767;
+        self.assertEquals(sized.sizeForDisplay(), u"31 KB")
+        msg.full_text = '*' * 32768;
+        self.assertEquals(sized.sizeForDisplay(), u"32 KB")
+    
+
 def open_test_data(filename):
     """Open a file relative to the location of this module."""
     base = os.path.dirname(__file__)
@@ -1043,6 +1113,8 @@
     suite.addTest(unittest.makeSuite(TestMessageUpload))
     suite.addTest(unittest.makeSuite(TestContainerView))
     suite.addTest(unittest.makeSuite(TestCheckinMessageView))
+    suite.addTest(unittest.makeSuite(TestMessageNameChooser))
+    suite.addTest(unittest.makeSuite(TestMessageSized))
     return suite
 
 




More information about the Zope3-Checkins mailing list