incubator-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rdon...@apache.org
Subject svn commit: r614647 - in /incubator/public/trunk: diff.py tests.py
Date Wed, 23 Jan 2008 20:12:13 GMT
Author: rdonkin
Date: Wed Jan 23 12:12:10 2008
New Revision: 614647

URL: http://svn.apache.org/viewvc?rev=614647&view=rev
Log:
Compare documents

Modified:
    incubator/public/trunk/diff.py
    incubator/public/trunk/tests.py

Modified: incubator/public/trunk/diff.py
URL: http://svn.apache.org/viewvc/incubator/public/trunk/diff.py?rev=614647&r1=614646&r2=614647&view=diff
==============================================================================
--- incubator/public/trunk/diff.py (original)
+++ incubator/public/trunk/diff.py Wed Jan 23 12:12:10 2008
@@ -18,6 +18,9 @@
     def __init__(self):
         self.reset()
         
+    def __str__(self):
+        return self.name + "," + self.dir
+        
     def reset(self):
         self.next = None
         self.dir = None
@@ -96,6 +99,9 @@
         self.documents = []
         self.__current = None
         
+    def append(self, document):
+        self.documents.append(document)
+        
     def load(self, document):
         self.documents = []
         self.__current = None
@@ -124,4 +130,26 @@
         
     def char_data(self, data):
         if not self.__current == None:
-            self.__current.char_data(data)
\ No newline at end of file
+            self.__current.char_data(data)
+            
+    def __iter__(self):
+        for document in self.documents:
+            yield(document)
+            
+    def isModified(self, document):
+        return document.isModified(self.documents)
+    
+    def isMissing(self, document):
+        return document.isMissing(self.documents)
+            
+    def compare(self, documents):
+        added = filter(documents.isMissing, self)
+        removed = filter(self.isMissing, documents)
+        modified = filter(documents.isModified, self)
+        return added, removed, modified
+    
+def documents(documents):
+    results = Documents()
+    for document in documents:
+        results.append(document)
+    return results
\ No newline at end of file

Modified: incubator/public/trunk/tests.py
URL: http://svn.apache.org/viewvc/incubator/public/trunk/tests.py?rev=614647&r1=614646&r2=614647&view=diff
==============================================================================
--- incubator/public/trunk/tests.py (original)
+++ incubator/public/trunk/tests.py Wed Jan 23 12:12:10 2008
@@ -74,7 +74,8 @@
     def setUp(self):
         self.documents = []
         self.documents.append(diff.document("dir", "name", "md5", "sha", "ripemd"))
-        self.documents.append(diff.document("dir", "name2", "2md5", "2sha", "2ripemd"))
+        self.document2 = diff.document("dir", "name2", "2md5", "2sha", "2ripemd")
+        self.documents.append(self.document2)
         self.documents.append(diff.document("dirA", "name", "Amd5", "Asha", "Aripemd"))
         self.documents.append(diff.document("dirA", "nameB", "Bmd5", "Bsha", "Bripemd"))
         
@@ -102,4 +103,44 @@
         document = diff.document("dir", "name", "md5", "Qsha", "ripemd")
         self.assertEquals(True, document.isModified(self.documents))
         document = diff.document("dir", "name", "md5", "sha", "Tripemd")
-        self.assertEquals(True, document.isModified(self.documents))
\ No newline at end of file
+        self.assertEquals(True, document.isModified(self.documents))
+        
+    def testCompareEmpty(self):
+        emptyDocuments = diff.Documents()
+        documents = diff.documents(self.documents)
+        added, removed, modified = documents.compare(emptyDocuments)
+        self.assert_(not added == None)
+        self.assert_(not removed == None)
+        self.assert_(not modified == None)
+        self.assertEquals(4, len(added))
+        self.assertEquals(0, len(modified))
+        self.assertEquals(0, len(removed))
+        added, removed, modified = emptyDocuments.compare(documents)
+        self.assert_(not added == None)
+        self.assert_(not removed == None)
+        self.assert_(not modified == None)
+        self.assertEquals(0, len(added))
+        self.assertEquals(0, len(modified))
+        self.assertEquals(4, len(removed))
+        
+    def testCompareDiffering(self):
+        documents = diff.documents(self.documents)
+        
+        differentsDocuments = diff.Documents()
+        modifiedDocument = diff.document("dir", "name", "NOT", "NOT", "NOT")
+        newDocument = diff.document("anotherdir", "anothername", "NOT", "NOT", "NOT")
+        differentsDocuments.append(modifiedDocument)
+        differentsDocuments.append(newDocument)
+        differentsDocuments.append(diff.document("dirA", "name", "Amd5", "Asha", "Aripemd"))
+        differentsDocuments.append(diff.document("dirA", "nameB", "Bmd5", "Bsha", "Bripemd"))
+        
+        added, removed, modified = differentsDocuments.compare(documents)
+        self.assert_(not added == None)
+        self.assert_(not removed == None)
+        self.assert_(not modified == None)
+        self.assertEquals(1, len(modified))
+        self.assertEquals(1, len(added))
+        self.assertEquals(1, len(removed))
+        self.assertEquals(modifiedDocument, modified[0])
+        self.assertEquals(newDocument, added[0])
+        self.assertEquals(self.document2, removed[0])
\ No newline at end of file



---------------------------------------------------------------------
To unsubscribe, e-mail: cvs-unsubscribe@incubator.apache.org
For additional commands, e-mail: cvs-help@incubator.apache.org


Mime
View raw message