D3492: tests: port test-simplemerge.py to Python 3

durin42 (Augie Fackler) phabricator at mercurial-scm.org
Tue May 8 09:37:34 EDT 2018


durin42 created this revision.
Herald added a reviewer: pulkit.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  1. skip-blame just b prefixes

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D3492

AFFECTED FILES
  contrib/python3-whitelist
  tests/test-simplemerge.py

CHANGE DETAILS

diff --git a/tests/test-simplemerge.py b/tests/test-simplemerge.py
--- a/tests/test-simplemerge.py
+++ b/tests/test-simplemerge.py
@@ -35,12 +35,12 @@
     incorporating the changes from both BASE->OTHER and BASE->THIS.
     All three will typically be sequences of lines."""
     def __init__(self, base, a, b):
-        basetext = '\n'.join([i.strip('\n') for i in base] + [''])
-        atext = '\n'.join([i.strip('\n') for i in a] + [''])
-        btext = '\n'.join([i.strip('\n') for i in b] + [''])
+        basetext = b'\n'.join([i.strip(b'\n') for i in base] + [b''])
+        atext = b'\n'.join([i.strip(b'\n') for i in a] + [b''])
+        btext = b'\n'.join([i.strip(b'\n') for i in b] + [b''])
         if (stringutil.binary(basetext) or stringutil.binary(atext)
             or stringutil.binary(btext)):
-            raise error.Abort("don't know how to merge binary files")
+            raise error.Abort(b"don't know how to merge binary files")
         simplemerge.Merge3Text.__init__(self, basetext, atext, btext,
                                         base, a, b)
 
@@ -52,7 +52,7 @@
 ############################################################
 # test case data from the gnu diffutils manual
 # common base
-TZU = split_lines("""     The Nameless is the origin of Heaven and Earth;
+TZU = split_lines(b"""     The Nameless is the origin of Heaven and Earth;
      The named is the mother of all things.
 
      Therefore let there always be non-being,
@@ -67,7 +67,7 @@
      The door of all subtleties!
 """)
 
-LAO = split_lines("""     The Way that can be told of is not the eternal Way;
+LAO = split_lines(b"""     The Way that can be told of is not the eternal Way;
      The name that can be named is not the eternal name.
      The Nameless is the origin of Heaven and Earth;
      The Named is the mother of all things.
@@ -81,7 +81,7 @@
 """)
 
 
-TAO = split_lines("""     The Way that can be told of is not the eternal Way;
+TAO = split_lines(b"""     The Way that can be told of is not the eternal Way;
      The name that can be named is not the eternal name.
      The Nameless is the origin of Heaven and Earth;
      The named is the mother of all things.
@@ -98,7 +98,7 @@
 
 """)
 
-MERGED_RESULT = split_lines("""\
+MERGED_RESULT = split_lines(b"""\
      The Way that can be told of is not the eternal Way;
      The name that can be named is not the eternal name.
      The Nameless is the origin of Heaven and Earth;
@@ -124,9 +124,9 @@
 
     def test_no_changes(self):
         """No conflicts because nothing changed"""
-        m3 = Merge3(['aaa', 'bbb'],
-                    ['aaa', 'bbb'],
-                    ['aaa', 'bbb'])
+        m3 = Merge3([b'aaa', b'bbb'],
+                    [b'aaa', b'bbb'],
+                    [b'aaa', b'bbb'])
 
         self.assertEqual(m3.find_unconflicted(),
                          [(0, 2)])
@@ -138,50 +138,50 @@
                           (2, 2,  2, 2,  2, 2)])
 
         self.assertEqual(list(m3.merge_regions()),
-                         [('unchanged', 0, 2)])
+                         [(b'unchanged', 0, 2)])
 
         self.assertEqual(list(m3.merge_groups()),
-                         [('unchanged', ['aaa', 'bbb'])])
+                         [(b'unchanged', [b'aaa', b'bbb'])])
 
     def test_front_insert(self):
-        m3 = Merge3(['zz'],
-                    ['aaa', 'bbb', 'zz'],
-                    ['zz'])
+        m3 = Merge3([b'zz'],
+                    [b'aaa', b'bbb', b'zz'],
+                    [b'zz'])
 
         # todo: should use a sentinel at end as from get_matching_blocks
         # to match without zz
         self.assertEqual(list(m3.find_sync_regions()),
                          [(0, 1,  2, 3,  0, 1),
                           (1, 1,  3, 3,  1, 1)])
 
         self.assertEqual(list(m3.merge_regions()),
-                         [('a', 0, 2),
-                          ('unchanged', 0, 1)])
+                         [(b'a', 0, 2),
+                          (b'unchanged', 0, 1)])
 
         self.assertEqual(list(m3.merge_groups()),
-                         [('a', ['aaa', 'bbb']),
-                          ('unchanged', ['zz'])])
+                         [(b'a', [b'aaa', b'bbb']),
+                          (b'unchanged', [b'zz'])])
 
     def test_null_insert(self):
         m3 = Merge3([],
-                    ['aaa', 'bbb'],
+                    [b'aaa', b'bbb'],
                     [])
         # todo: should use a sentinel at end as from get_matching_blocks
         # to match without zz
         self.assertEqual(list(m3.find_sync_regions()),
                          [(0, 0,  2, 2,  0, 0)])
 
         self.assertEqual(list(m3.merge_regions()),
-                         [('a', 0, 2)])
+                         [(b'a', 0, 2)])
 
         self.assertEqual(list(m3.merge_lines()),
-                         ['aaa', 'bbb'])
+                         [b'aaa', b'bbb'])
 
     def test_no_conflicts(self):
         """No conflicts because only one side changed"""
-        m3 = Merge3(['aaa', 'bbb'],
-                    ['aaa', '111', 'bbb'],
-                    ['aaa', 'bbb'])
+        m3 = Merge3([b'aaa', b'bbb'],
+                    [b'aaa', b'111', b'bbb'],
+                    [b'aaa', b'bbb'])
 
         self.assertEqual(m3.find_unconflicted(),
                          [(0, 1), (1, 2)])
@@ -192,72 +192,72 @@
                           (2, 2,  3, 3,  2, 2)])
 
         self.assertEqual(list(m3.merge_regions()),
-                         [('unchanged', 0, 1),
-                          ('a', 1, 2),
-                          ('unchanged', 1, 2)])
+                         [(b'unchanged', 0, 1),
+                          (b'a', 1, 2),
+                          (b'unchanged', 1, 2)])
 
     def test_append_a(self):
-        m3 = Merge3(['aaa\n', 'bbb\n'],
-                    ['aaa\n', 'bbb\n', '222\n'],
-                    ['aaa\n', 'bbb\n'])
+        m3 = Merge3([b'aaa\n', b'bbb\n'],
+                    [b'aaa\n', b'bbb\n', b'222\n'],
+                    [b'aaa\n', b'bbb\n'])
 
-        self.assertEqual(''.join(m3.merge_lines()),
-                         'aaa\nbbb\n222\n')
+        self.assertEqual(b''.join(m3.merge_lines()),
+                         b'aaa\nbbb\n222\n')
 
     def test_append_b(self):
-        m3 = Merge3(['aaa\n', 'bbb\n'],
-                    ['aaa\n', 'bbb\n'],
-                    ['aaa\n', 'bbb\n', '222\n'])
+        m3 = Merge3([b'aaa\n', b'bbb\n'],
+                    [b'aaa\n', b'bbb\n'],
+                    [b'aaa\n', b'bbb\n', b'222\n'])
 
-        self.assertEqual(''.join(m3.merge_lines()),
-                         'aaa\nbbb\n222\n')
+        self.assertEqual(b''.join(m3.merge_lines()),
+                         b'aaa\nbbb\n222\n')
 
     def test_append_agreement(self):
-        m3 = Merge3(['aaa\n', 'bbb\n'],
-                    ['aaa\n', 'bbb\n', '222\n'],
-                    ['aaa\n', 'bbb\n', '222\n'])
+        m3 = Merge3([b'aaa\n', b'bbb\n'],
+                    [b'aaa\n', b'bbb\n', b'222\n'],
+                    [b'aaa\n', b'bbb\n', b'222\n'])
 
-        self.assertEqual(''.join(m3.merge_lines()),
-                         'aaa\nbbb\n222\n')
+        self.assertEqual(b''.join(m3.merge_lines()),
+                         b'aaa\nbbb\n222\n')
 
     def test_append_clash(self):
-        m3 = Merge3(['aaa\n', 'bbb\n'],
-                    ['aaa\n', 'bbb\n', '222\n'],
-                    ['aaa\n', 'bbb\n', '333\n'])
+        m3 = Merge3([b'aaa\n', b'bbb\n'],
+                    [b'aaa\n', b'bbb\n', b'222\n'],
+                    [b'aaa\n', b'bbb\n', b'333\n'])
 
-        ml = m3.merge_lines(name_a='a',
-                            name_b='b',
-                            start_marker='<<',
-                            mid_marker='--',
-                            end_marker='>>')
-        self.assertEqual(''.join(ml),
-                         'aaa\n'
-                         'bbb\n'
-                         '<< a\n'
-                         '222\n'
-                         '--\n'
-                         '333\n'
-                         '>> b\n'
+        ml = m3.merge_lines(name_a=b'a',
+                            name_b=b'b',
+                            start_marker=b'<<',
+                            mid_marker=b'--',
+                            end_marker=b'>>')
+        self.assertEqual(b''.join(ml),
+                         b'aaa\n'
+                         b'bbb\n'
+                         b'<< a\n'
+                         b'222\n'
+                         b'--\n'
+                         b'333\n'
+                         b'>> b\n'
                          )
 
     def test_insert_agreement(self):
-        m3 = Merge3(['aaa\n', 'bbb\n'],
-                    ['aaa\n', '222\n', 'bbb\n'],
-                    ['aaa\n', '222\n', 'bbb\n'])
+        m3 = Merge3([b'aaa\n', b'bbb\n'],
+                    [b'aaa\n', b'222\n', b'bbb\n'],
+                    [b'aaa\n', b'222\n', b'bbb\n'])
 
-        ml = m3.merge_lines(name_a='a',
-                            name_b='b',
-                            start_marker='<<',
-                            mid_marker='--',
-                            end_marker='>>')
-        self.assertEqual(''.join(ml), 'aaa\n222\nbbb\n')
+        ml = m3.merge_lines(name_a=b'a',
+                            name_b=b'b',
+                            start_marker=b'<<',
+                            mid_marker=b'--',
+                            end_marker=b'>>')
+        self.assertEqual(b''.join(ml), b'aaa\n222\nbbb\n')
 
 
     def test_insert_clash(self):
         """Both try to insert lines in the same place."""
-        m3 = Merge3(['aaa\n', 'bbb\n'],
-                    ['aaa\n', '111\n', 'bbb\n'],
-                    ['aaa\n', '222\n', 'bbb\n'])
+        m3 = Merge3([b'aaa\n', b'bbb\n'],
+                    [b'aaa\n', b'111\n', b'bbb\n'],
+                    [b'aaa\n', b'222\n', b'bbb\n'])
 
         self.assertEqual(m3.find_unconflicted(),
                          [(0, 1), (1, 2)])
@@ -268,23 +268,23 @@
                           (2, 2,  3, 3,  3, 3)])
 
         self.assertEqual(list(m3.merge_regions()),
-                         [('unchanged', 0, 1),
-                          ('conflict', 1, 1,  1, 2,  1, 2),
-                          ('unchanged', 1, 2)])
+                         [(b'unchanged', 0, 1),
+                          (b'conflict', 1, 1,  1, 2,  1, 2),
+                          (b'unchanged', 1, 2)])
 
         self.assertEqual(list(m3.merge_groups()),
-                         [('unchanged', ['aaa\n']),
-                          ('conflict', [], ['111\n'], ['222\n']),
-                          ('unchanged', ['bbb\n']),
+                         [(b'unchanged', [b'aaa\n']),
+                          (b'conflict', [], [b'111\n'], [b'222\n']),
+                          (b'unchanged', [b'bbb\n']),
                           ])
 
-        ml = m3.merge_lines(name_a='a',
-                            name_b='b',
-                            start_marker='<<',
-                            mid_marker='--',
-                            end_marker='>>')
-        self.assertEqual(''.join(ml),
-'''aaa
+        ml = m3.merge_lines(name_a=b'a',
+                            name_b=b'b',
+                            start_marker=b'<<',
+                            mid_marker=b'--',
+                            end_marker=b'>>')
+        self.assertEqual(b''.join(ml),
+b'''aaa
 << a
 111
 --
@@ -295,23 +295,23 @@
 
     def test_replace_clash(self):
         """Both try to insert lines in the same place."""
-        m3 = Merge3(['aaa', '000', 'bbb'],
-                    ['aaa', '111', 'bbb'],
-                    ['aaa', '222', 'bbb'])
+        m3 = Merge3([b'aaa', b'000', b'bbb'],
+                    [b'aaa', b'111', b'bbb'],
+                    [b'aaa', b'222', b'bbb'])
 
         self.assertEqual(m3.find_unconflicted(),
                          [(0, 1), (2, 3)])
 
         self.assertEqual(list(m3.find_sync_regions()),
                          [(0, 1,  0, 1,  0, 1),
-                          (2, 3,  2, 3,  2, 3),
-                          (3, 3,  3, 3,  3, 3)])
+                           (2, 3,  2, 3,  2, 3),
+                           (3, 3,  3, 3,  3, 3)])
 
     def test_replace_multi(self):
         """Replacement with regions of different size."""
-        m3 = Merge3(['aaa', '000', '000', 'bbb'],
-                    ['aaa', '111', '111', '111', 'bbb'],
-                    ['aaa', '222', '222', '222', '222', 'bbb'])
+        m3 = Merge3([b'aaa', b'000', b'000', b'bbb'],
+                    [b'aaa', b'111', b'111', b'111', b'bbb'],
+                    [b'aaa', b'222', b'222', b'222', b'222', b'bbb'])
 
         self.assertEqual(m3.find_unconflicted(),
                          [(0, 1), (3, 4)])
@@ -325,34 +325,34 @@
     def test_merge_poem(self):
         """Test case from diff3 manual"""
         m3 = Merge3(TZU, LAO, TAO)
-        ml = list(m3.merge_lines('LAO', 'TAO'))
-        self.log('merge result:')
-        self.log(''.join(ml))
+        ml = list(m3.merge_lines(b'LAO', b'TAO'))
+        self.log(b'merge result:')
+        self.log(b''.join(ml))
         self.assertEqual(ml, MERGED_RESULT)
 
     def test_binary(self):
         with self.assertRaises(error.Abort):
-            Merge3(['\x00'], ['a'], ['b'])
+            Merge3([b'\x00'], [b'a'], [b'b'])
 
     def test_dos_text(self):
-        base_text = 'a\r\n'
-        this_text = 'b\r\n'
-        other_text = 'c\r\n'
+        base_text = b'a\r\n'
+        this_text = b'b\r\n'
+        other_text = b'c\r\n'
         m3 = Merge3(base_text.splitlines(True), other_text.splitlines(True),
                     this_text.splitlines(True))
-        m_lines = m3.merge_lines('OTHER', 'THIS')
-        self.assertEqual('<<<<<<< OTHER\r\nc\r\n=======\r\nb\r\n'
-                         '>>>>>>> THIS\r\n'.splitlines(True), list(m_lines))
+        m_lines = m3.merge_lines(b'OTHER', b'THIS')
+        self.assertEqual(b'<<<<<<< OTHER\r\nc\r\n=======\r\nb\r\n'
+                         b'>>>>>>> THIS\r\n'.splitlines(True), list(m_lines))
 
     def test_mac_text(self):
-        base_text = 'a\r'
-        this_text = 'b\r'
-        other_text = 'c\r'
+        base_text = b'a\r'
+        this_text = b'b\r'
+        other_text = b'c\r'
         m3 = Merge3(base_text.splitlines(True), other_text.splitlines(True),
                     this_text.splitlines(True))
-        m_lines = m3.merge_lines('OTHER', 'THIS')
-        self.assertEqual('<<<<<<< OTHER\rc\r=======\rb\r'
-                         '>>>>>>> THIS\r'.splitlines(True), list(m_lines))
+        m_lines = m3.merge_lines(b'OTHER', b'THIS')
+        self.assertEqual(b'<<<<<<< OTHER\rc\r=======\rb\r'
+                         b'>>>>>>> THIS\r'.splitlines(True), list(m_lines))
 
 if __name__ == '__main__':
     # hide the timer
diff --git a/contrib/python3-whitelist b/contrib/python3-whitelist
--- a/contrib/python3-whitelist
+++ b/contrib/python3-whitelist
@@ -418,6 +418,7 @@
 test-show-work.t
 test-show.t
 test-simple-update.t
+test-simplemerge.py
 test-single-head.t
 test-sparse-clear.t
 test-sparse-import.t



To: durin42, pulkit, #hg-reviewers
Cc: mercurial-devel


More information about the Mercurial-devel mailing list