Back to index

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