Beispiel #1
0
 def test_eq(self):
     self.assertEqual(multiparent.ParentText(1, 2, 3, 4),
                      multiparent.ParentText(1, 2, 3, 4))
     self.assertFalse(multiparent.ParentText(1, 2, 3, 4) ==
                      multiparent.ParentText(2, 2, 3, 4))
     self.assertFalse(multiparent.ParentText(1, 2, 3, 4) ==
                      Mock(parent=1, parent_pos=2, child_pos=3,
                           num_lines=4))
Beispiel #2
0
 def test_compare_two_parents_blocks(self):
     matcher = patiencediff.PatienceSequenceMatcher(None, LINES_2, LINES_1)
     blocks = matcher.get_matching_blocks()
     diff = multiparent.MultiParent.from_lines(LINES_1, [LINES_2, LINES_3],
                                               left_blocks=blocks)
     self.assertEqual([multiparent.ParentText(1, 0, 0, 4),
                       multiparent.ParentText(0, 3, 4, 1)],
                      diff.hunks)
Beispiel #3
0
 def test_from_patch(self):
     self.assertEqual(multiparent.MultiParent(
         [multiparent.NewText(['a\n']),
          multiparent.ParentText(0, 1, 2, 3)]),
          multiparent.MultiParent.from_patch('i 1\na\n\nc 0 1 2 3'))
     self.assertEqual(multiparent.MultiParent(
         [multiparent.NewText(['a']),
          multiparent.ParentText(0, 1, 2, 3)]),
          multiparent.MultiParent.from_patch('i 1\na\nc 0 1 2 3\n'))
Beispiel #4
0
    def test_compare_one_parent(self):
        diff = multiparent.MultiParent.from_lines(LINES_1, [LINES_2])
        self.assertEqual([multiparent.ParentText(0, 0, 0, 1),
                          multiparent.NewText(['b\n']),
                          multiparent.ParentText(0, 1, 2, 3)],
                         diff.hunks)

        diff = multiparent.MultiParent.from_lines(LINES_2, [LINES_1])
        self.assertEqual([multiparent.ParentText(0, 0, 0, 1),
                          multiparent.ParentText(0, 2, 1, 3)],
                         diff.hunks)
Beispiel #5
0
 def test_eq(self):
     diff = multiparent.MultiParent.from_lines(LINES_1)
     diff2 = multiparent.MultiParent.from_lines(LINES_1)
     self.assertEqual(diff, diff2)
     diff3 = multiparent.MultiParent.from_lines(LINES_2)
     self.assertFalse(diff == diff3)
     self.assertFalse(diff == Mock(hunks=[multiparent.NewText(LINES_1)]))
     self.assertEqual(multiparent.MultiParent(
                      [multiparent.NewText(LINES_1),
                       multiparent.ParentText(0, 1, 2, 3)]),
                      multiparent.MultiParent(
                      [multiparent.NewText(LINES_1),
                       multiparent.ParentText(0, 1, 2, 3)]))
Beispiel #6
0
 def test_to_patch(self):
     self.assertEqual(['i 1\n', 'a\n', '\n', 'c 0 1 2 3\n'],
                      list(
                          multiparent.MultiParent([
                              multiparent.NewText(['a\n']),
                              multiparent.ParentText(0, 1, 2, 3)
                          ]).to_patch()))
Beispiel #7
0
 def test_num_lines(self):
     mp = multiparent.MultiParent([multiparent.NewText(['a\n'])])
     self.assertEqual(1, mp.num_lines())
     mp.hunks.append(multiparent.NewText(['b\n', 'c\n']))
     self.assertEqual(3, mp.num_lines())
     mp.hunks.append(multiparent.ParentText(0, 0, 3, 2))
     self.assertEqual(5, mp.num_lines())
     mp.hunks.append(multiparent.NewText(['f\n', 'g\n']))
     self.assertEqual(7, mp.num_lines())
Beispiel #8
0
 def test_compute_diffs(self):
     vf = self.make_three_vf()
     # The content is in the order requested, even if it isn't topological
     gen = versionedfile._MPDiffGenerator(vf, [('two', ), ('three', ),
                                               ('one', )])
     diffs = gen.compute_diffs()
     expected_diffs = [
         multiparent.MultiParent([
             multiparent.ParentText(0, 0, 0, 1),
             multiparent.NewText(['second\n'])
         ]),
         multiparent.MultiParent([
             multiparent.ParentText(1, 0, 0, 2),
             multiparent.NewText(['third\n'])
         ]),
         multiparent.MultiParent([multiparent.NewText(['first\n'])]),
     ]
     self.assertEqual(expected_diffs, diffs)
Beispiel #9
0
 def test_compare_two_parents(self):
     diff = multiparent.MultiParent.from_lines(LINES_1, [LINES_2, LINES_3])
     self.assertEqual([multiparent.ParentText(1, 0, 0, 4),
                       multiparent.ParentText(0, 3, 4, 1)],
                      diff.hunks)
Beispiel #10
0
 def test_to_patch(self):
     self.assertEqual(['c 0 1 2 3\n'],
                      list(multiparent.ParentText(0, 1, 2, 3).to_patch()))