# HG changeset patch # User Augie Fackler # Date 2018-04-27 14:17:48 # Node ID c1bc196e021d9caa616af8829f86ca4383381771 # Parent a3ed6e7217c16da9a7c7fd41552a63d4b162aab0 tests: port test-simplemerge.py to Python 3 # skip-blame just b prefixes Differential Revision: https://phab.mercurial-scm.org/D3492 diff --git a/contrib/python3-whitelist b/contrib/python3-whitelist --- a/contrib/python3-whitelist +++ b/contrib/python3-whitelist @@ -415,6 +415,7 @@ test-show-stack.t 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 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 @@ class Merge3(simplemerge.Merge3Text): 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 @@ def split_lines(t): ############################################################ # 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 @@ TZU = split_lines(""" The Nameless i 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 @@ LAO = split_lines(""" The Way that c """) -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 @@ TAO = split_lines(""" The Way that c """) -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 @@ class TestMerge3(TestCase): 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 @@ class TestMerge3(TestCase): (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 @@ class TestMerge3(TestCase): (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 @@ class TestMerge3(TestCase): [(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 @@ class TestMerge3(TestCase): (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 @@ class TestMerge3(TestCase): (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 @@ bbb 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 @@ bbb 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