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
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)
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)
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)
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')
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)
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)
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)
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)
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)
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)
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)
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)
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)
def testAttributeDiff(self): """Test attribute with different value""" a = A() b = B() fd = FieldDiff(a, b, 'attribute') self.failIf(fd.same)
def testMethodDiff(self): """Test method with different value""" a = A() b = B() fd = FieldDiff(a, b, 'method') self.failIf(fd.same)