예제 #1
0
    def __init__(self,
                 obj1,
                 obj2,
                 field,
                 id1=None,
                 id2=None,
                 field_name=None,
                 field_label=None,
                 schemata=None):
        FieldDiff.__init__(self, obj1, obj2, field, id1, id2, field_name,
                           field_label, schemata)
        self._vocabulary = None

        # Tries to find a vocabulary. First we need to find an object and
        # the field instance.
        obj = obj1 if (obj1 is not None) else obj2
        field_name = field_name or field
        if obj and field_name and IDexterityContent.providedBy(obj):
            field_instance = get_field_object(obj, field_name)
            if field_instance is not None:
                # Binding the field to an object will construct the vocabulary
                # using a factory if necessary.
                try:
                    self._vocabulary = field_instance.value_type.bind(obj).\
                        vocabulary
                except Exception:
                    pass
예제 #2
0
 def testGetLineDiffsDifferent(self):
     """test getLineDiffs() method with different value"""
     a = A()
     b = B()
     fd = FieldDiff(a, b, 'attribute')
     expected = [('replace', 0, 1, 0, 1)]
     self.assertEqual(fd.getLineDiffs(), expected)
예제 #3
0
 def testDiffText(self):
     """Test text diff output with different value"""
     a = A()
     b = B()
     expected = "- value%s+ different value" % linesep
     fd = FieldDiff(a, b, 'attribute')
     self.assertEqual(fd.ndiff(), expected)
예제 #4
0
 def testGetLineDiffsDifferent(self):
     """test getLineDiffs() method with different value"""
     a = A()
     b = B()
     fd = FieldDiff(a, b, 'attribute')
     expected = [('replace', 0, 1, 0, 1)]
     self.assertEqual(fd.getLineDiffs(), expected)
예제 #5
0
 def testDiffText(self):
     """Test text diff output with different value"""
     a = A()
     b = B()
     expected = "- value\n+ different value"
     fd = FieldDiff(a, b, 'attribute')
     self.assertEqual(fd.ndiff(), expected)
예제 #6
0
 def testSameText(self):
     """Test text diff output with same value"""
     a = A()
     fd = FieldDiff(a, a, 'attribute')
     self.assertEqual(fd.ndiff(), '  value')
     uu = U()
     fd = FieldDiff(uu, uu, 'attribute')
     self.assertEqual(fd.ndiff(), u'  \xfcnicode value')
예제 #7
0
 def testMethodSame(self):
     """Test method with same value"""
     a = A()
     fd = FieldDiff(a, a, 'method')
     self.assertTrue(fd.same)
     uu = U()
     fd = FieldDiff(uu, uu, 'method')
     self.assertTrue(fd.same)
예제 #8
0
 def testMethodSame(self):
     """Test method with same value"""
     a = A()
     fd = FieldDiff(a, a, 'method')
     self.failUnless(fd.same)
     uu = U()
     fd = FieldDiff(uu, uu, 'method')
     self.failUnless(fd.same)
예제 #9
0
 def testAttributeSame(self):
     """Test attribute with same value"""
     a = A()
     fd = FieldDiff(a, a, 'attribute')
     self.failUnless(fd.same)
     uu = U()
     fd = FieldDiff(uu, uu, 'attribute')
     self.failUnless(fd.same)
예제 #10
0
 def testAttributeSame(self):
     """Test attribute with same value"""
     a = A()
     fd = FieldDiff(a, a, 'attribute')
     self.assertTrue(fd.same)
     uu = U()
     fd = FieldDiff(uu, uu, 'attribute')
     self.assertTrue(fd.same)
예제 #11
0
 def testAttributeDiff(self):
     """Test attribute with different value"""
     a = A()
     b = B()
     uu = U()
     fd = FieldDiff(a, b, 'attribute')
     self.assertFalse(fd.same)
     fd = FieldDiff(a, uu, 'attribute')
     self.assertFalse(fd.same)
예제 #12
0
 def testMethodDiff(self):
     """Test method with different value"""
     a = A()
     b = B()
     uu = U()
     fd = FieldDiff(a, b, 'method')
     self.assertFalse(fd.same)
     fd = FieldDiff(a, uu, 'method')
     self.assertFalse(fd.same)
예제 #13
0
 def testGetLineDiffsSame(self):
     """test getLineDiffs() method with same value"""
     a = A()
     fd = FieldDiff(a, a, 'attribute')
     expected = [('equal', 0, 1, 0, 1)]
     self.assertEqual(fd.getLineDiffs(), expected)
     uu = U()
     fd = FieldDiff(uu, uu, 'attribute')
     expected = [('equal', 0, 1, 0, 1)]
     self.assertEqual(fd.getLineDiffs(), expected)
예제 #14
0
 def testDiffText(self):
     """Test text diff output with different value"""
     a = A()
     b = B()
     uu = U()
     expected = "- value%s+ different value" % linesep
     fd = FieldDiff(a, b, 'attribute')
     self.assertEqual(fd.ndiff(), expected)
     expected = u"- value%s+ \xfcnicode value" % linesep
     fd = FieldDiff(a, uu, 'attribute')
     self.assertEqual(fd.ndiff(), expected)
예제 #15
0
    def __init__(self, obj1, obj2, field, id1=None, id2=None, field_name=None,
                 field_label=None, schemata=None):
        FieldDiff.__init__(self, obj1, obj2, field, id1, id2, field_name,
                           field_label, schemata)
        self._vocabulary = None

        # Tries to find a vocabulary. First we need to find an object and
        # the field instance.
        obj = obj1 if (obj1 is not None) else obj2
        field_name = field_name or field
        if obj and field_name and IDexterityContent.providedBy(obj):
            field_instance = get_field_object(obj, field_name)
            if field_instance is not None:
                # Binding the field to an object will construct the vocabulary
                # using a factory if necessary.
                try:
                    self._vocabulary = field_instance.value_type.bind(obj).\
                        vocabulary
                except Exception:
                    pass
예제 #16
0
 def testSameText(self):
     """Test text diff output with same value"""
     a = A()
     fd = FieldDiff(a, a, 'attribute')
     self.assertEqual(fd.ndiff(), '  value')
     uu = U()
     fd = FieldDiff(uu, uu, 'attribute')
     self.assertEqual(fd.ndiff(), u'  \xfcnicode value')
예제 #17
0
 def testGetLineDiffsSame(self):
     """test getLineDiffs() method with same value"""
     a = A()
     fd = FieldDiff(a, a, 'attribute')
     expected = [('equal', 0, 1, 0, 1)]
     self.assertEqual(fd.getLineDiffs(), expected)
     uu = U()
     fd = FieldDiff(uu, uu, 'attribute')
     expected = [('equal', 0, 1, 0, 1)]
     self.assertEqual(fd.getLineDiffs(), expected)
예제 #18
0
 def testDiffText(self):
     """Test text diff output with different value"""
     a = A()
     b = B()
     uu = U()
     expected = '- value%s+ different value' % linesep
     fd = FieldDiff(a, b, 'attribute')
     self.assertEqual(fd.ndiff(), expected)
     expected = u'- value%s+ \xfcnicode value' % linesep
     fd = FieldDiff(a, uu, 'attribute')
     self.assertEqual(fd.ndiff(), expected)
예제 #19
0
 def testAttributeDiff(self):
     """Test attribute with different value"""
     a = A()
     b = B()
     fd = FieldDiff(a, b, 'attribute')
     self.failIf(fd.same)
예제 #20
0
 def testMethodDiff(self):
     """Test method with different value"""
     a = A()
     b = B()
     fd = FieldDiff(a, b, 'method')
     self.failIf(fd.same)