changeset 37892:c1bc196e021d

tests: port test-simplemerge.py to Python 3 # skip-blame just b prefixes Differential Revision: https://phab.mercurial-scm.org/D3492
author Augie Fackler <augie@google.com>
date Fri, 27 Apr 2018 10:17:48 -0400
parents a3ed6e7217c1
children b4e42a9bd12e
files contrib/python3-whitelist tests/test-simplemerge.py
diffstat 2 files changed, 110 insertions(+), 109 deletions(-) [+]
line wrap: on
line diff
--- a/contrib/python3-whitelist	Fri Apr 27 10:21:24 2018 -0400
+++ b/contrib/python3-whitelist	Fri Apr 27 10:17:48 2018 -0400
@@ -415,6 +415,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
--- a/tests/test-simplemerge.py	Fri Apr 27 10:21:24 2018 -0400
+++ b/tests/test-simplemerge.py	Fri Apr 27 10:17:48 2018 -0400
@@ -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,15 +138,15 @@
                           (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
@@ -155,16 +155,16 @@
                           (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
@@ -172,16 +172,16 @@
                          [(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