Back to index

plone3  3.1.7
testListDiff.py
Go to the documentation of this file.
00001 #
00002 # CMFDiffTool tests
00003 #
00004 
00005 from Testing import ZopeTestCase
00006 from Products.CMFDiffTool.ListDiff import ListDiff
00007         
00008 _marker = []
00009 
00010 class A:
00011     attribute = [1, 2, 3]
00012 
00013 class B:
00014     attribute = [1, 2, 3, 4]
00015 
00016 class TestListDiff(ZopeTestCase.ZopeTestCase):
00017     """Test the ListDiff class"""
00018 
00019     def testInterface(self):
00020         """Ensure that tool instances implement the portal_diff interface"""
00021         from Products.CMFDiffTool.interfaces.portal_diff import IDifference
00022         self.failUnless(IDifference.isImplementedByInstancesOf(ListDiff))
00023     
00024     def testAttributeSame(self):
00025         """Test attribute with same value"""
00026         a = A()
00027         diff = ListDiff(a, a, 'attribute')
00028         self.failUnless(diff.same)
00029 
00030     def testAttributeDiff(self):
00031         """Test attribute with different value"""
00032         a = A()
00033         b = B()
00034         diff = ListDiff(a, b, 'attribute')
00035         self.failIf(diff.same)
00036 
00037     def testGetLineDiffsSame(self):
00038         """test getLineDiffs() method with same value"""
00039         a = A()
00040         diff = ListDiff(a, a, 'attribute')
00041         expected = [('equal', 0, 3, 0, 3)]
00042         self.assertEqual(diff.getLineDiffs(), expected)
00043 
00044     def testGetLineDiffsDifferent(self):
00045         """test getLineDiffs() method with different value"""
00046         a = A()
00047         b = B()
00048         diff = ListDiff(a, b, 'attribute')
00049         expected = [('equal', 0, 3, 0, 3) ,('insert', 3, 3, 3, 4)]
00050         self.assertEqual(diff.getLineDiffs(), expected)
00051         
00052     def testSameText(self):
00053         """Test text diff output with no diff"""
00054         a = A()
00055         diff = ListDiff(a, a, 'attribute')
00056         expected = "  1\n  2\n  3"
00057         self.assertEqual(diff.ndiff(), expected)
00058 
00059     def testDiffText(self):
00060         """Test text diff output with no diff"""
00061         a = A()
00062         b = B()
00063         expected = "  1\n  2\n  3\n+ 4"
00064         diff = ListDiff(a, b, 'attribute')
00065         self.assertEqual(diff.ndiff(), expected)
00066 
00067         # FIXME: need tests for other kinds of diffs
00068 
00069 
00070 def test_suite():
00071     import unittest
00072     suite = unittest.TestSuite()
00073     suite.addTest(unittest.makeSuite(TestListDiff))
00074     return suite
00075