D4175: tests: port test-absorb-filefixupstate to Python 3

durin42 (Augie Fackler) phabricator at mercurial-scm.org
Thu Aug 9 14:34:03 EDT 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rHG1aab0007a7c0: tests: port test-absorb-filefixupstate to Python 3 (authored by durin42, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D4175?vs=10107&id=10152

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

AFFECTED FILES
  contrib/python3-whitelist
  tests/test-absorb-filefixupstate.py

CHANGE DETAILS

diff --git a/tests/test-absorb-filefixupstate.py b/tests/test-absorb-filefixupstate.py
--- a/tests/test-absorb-filefixupstate.py
+++ b/tests/test-absorb-filefixupstate.py
@@ -1,7 +1,7 @@
 from __future__ import absolute_import, print_function
 
 import itertools
-
+from mercurial import pycompat
 from hgext import absorb
 
 class simplefctx(object):
@@ -13,17 +13,17 @@
 
 def insertreturns(x):
     # insert "\n"s after each single char
-    if isinstance(x, str):
-        return ''.join(ch + '\n' for ch in x)
+    if isinstance(x, bytes):
+        return b''.join(ch + b'\n' for ch in pycompat.bytestr(x))
     else:
-        return map(insertreturns, x)
+        return pycompat.maplist(insertreturns, x)
 
 def removereturns(x):
     # the revert of "insertreturns"
-    if isinstance(x, str):
-        return x.replace('\n', '')
+    if isinstance(x, bytes):
+        return x.replace(b'\n', b'')
     else:
-        return map(removereturns, x)
+        return pycompat.maplist(removereturns, x)
 
 def assertlistequal(lhs, rhs, decorator=lambda x: x):
     if lhs != rhs:
@@ -43,7 +43,7 @@
     expectedcontents = insertreturns(expectedcontents)
     oldcontents = insertreturns(oldcontents)
     workingcopy = insertreturns(workingcopy)
-    state = absorb.filefixupstate(map(simplefctx, oldcontents))
+    state = absorb.filefixupstate(pycompat.maplist(simplefctx, oldcontents))
     state.diffwith(simplefctx(workingcopy))
     if fixups is not None:
         assertlistequal(state.fixups, fixups)
@@ -53,155 +53,155 @@
 def buildcontents(linesrevs):
     # linesrevs: [(linecontent : str, revs : [int])]
     revs = set(itertools.chain(*[revs for line, revs in linesrevs]))
-    return [''] + [
-        ''.join([l for l, rs in linesrevs if r in rs])
+    return [b''] + [
+        b''.join([l for l, rs in linesrevs if r in rs])
         for r in sorted(revs)
     ]
 
 # input case 0: one single commit
-case0 = ['', '11']
+case0 = [b'', b'11']
 
 # replace a single chunk
-testfilefixup(case0, '', ['', ''])
-testfilefixup(case0, '2', ['', '2'])
-testfilefixup(case0, '22', ['', '22'])
-testfilefixup(case0, '222', ['', '222'])
+testfilefixup(case0, b'', [b'', b''])
+testfilefixup(case0, b'2', [b'', b'2'])
+testfilefixup(case0, b'22', [b'', b'22'])
+testfilefixup(case0, b'222', [b'', b'222'])
 
 # input case 1: 3 lines, each commit adds one line
 case1 = buildcontents([
-    ('1', [1, 2, 3]),
-    ('2', [   2, 3]),
-    ('3', [      3]),
+    (b'1', [1, 2, 3]),
+    (b'2', [   2, 3]),
+    (b'3', [      3]),
 ])
 
 # 1:1 line mapping
-testfilefixup(case1, '123', case1)
-testfilefixup(case1, '12c', ['', '1', '12', '12c'])
-testfilefixup(case1, '1b3', ['', '1', '1b', '1b3'])
-testfilefixup(case1, '1bc', ['', '1', '1b', '1bc'])
-testfilefixup(case1, 'a23', ['', 'a', 'a2', 'a23'])
-testfilefixup(case1, 'a2c', ['', 'a', 'a2', 'a2c'])
-testfilefixup(case1, 'ab3', ['', 'a', 'ab', 'ab3'])
-testfilefixup(case1, 'abc', ['', 'a', 'ab', 'abc'])
+testfilefixup(case1, b'123', case1)
+testfilefixup(case1, b'12c', [b'', b'1', b'12', b'12c'])
+testfilefixup(case1, b'1b3', [b'', b'1', b'1b', b'1b3'])
+testfilefixup(case1, b'1bc', [b'', b'1', b'1b', b'1bc'])
+testfilefixup(case1, b'a23', [b'', b'a', b'a2', b'a23'])
+testfilefixup(case1, b'a2c', [b'', b'a', b'a2', b'a2c'])
+testfilefixup(case1, b'ab3', [b'', b'a', b'ab', b'ab3'])
+testfilefixup(case1, b'abc', [b'', b'a', b'ab', b'abc'])
 
 # non 1:1 edits
-testfilefixup(case1, 'abcd', case1)
-testfilefixup(case1, 'ab', case1)
+testfilefixup(case1, b'abcd', case1)
+testfilefixup(case1, b'ab', case1)
 
 # deletion
-testfilefixup(case1, '',   ['', '', '', ''])
-testfilefixup(case1, '1',  ['', '1', '1', '1'])
-testfilefixup(case1, '2',  ['', '', '2', '2'])
-testfilefixup(case1, '3',  ['', '', '', '3'])
-testfilefixup(case1, '13', ['', '1', '1', '13'])
+testfilefixup(case1, b'',   [b'', b'', b'', b''])
+testfilefixup(case1, b'1',  [b'', b'1', b'1', b'1'])
+testfilefixup(case1, b'2',  [b'', b'', b'2', b'2'])
+testfilefixup(case1, b'3',  [b'', b'', b'', b'3'])
+testfilefixup(case1, b'13', [b'', b'1', b'1', b'13'])
 
 # replaces
-testfilefixup(case1, '1bb3', ['', '1', '1bb', '1bb3'])
+testfilefixup(case1, b'1bb3', [b'', b'1', b'1bb', b'1bb3'])
 
 # (confusing) replaces
-testfilefixup(case1, '1bbb', case1)
-testfilefixup(case1, 'bbbb', case1)
-testfilefixup(case1, 'bbb3', case1)
-testfilefixup(case1, '1b', case1)
-testfilefixup(case1, 'bb', case1)
-testfilefixup(case1, 'b3', case1)
+testfilefixup(case1, b'1bbb', case1)
+testfilefixup(case1, b'bbbb', case1)
+testfilefixup(case1, b'bbb3', case1)
+testfilefixup(case1, b'1b', case1)
+testfilefixup(case1, b'bb', case1)
+testfilefixup(case1, b'b3', case1)
 
 # insertions at the beginning and the end
-testfilefixup(case1, '123c', ['', '1', '12', '123c'])
-testfilefixup(case1, 'a123', ['', 'a1', 'a12', 'a123'])
+testfilefixup(case1, b'123c', [b'', b'1', b'12', b'123c'])
+testfilefixup(case1, b'a123', [b'', b'a1', b'a12', b'a123'])
 
 # (confusing) insertions
-testfilefixup(case1, '1a23', case1)
-testfilefixup(case1, '12b3', case1)
+testfilefixup(case1, b'1a23', case1)
+testfilefixup(case1, b'12b3', case1)
 
 # input case 2: delete in the middle
 case2 = buildcontents([
-    ('11', [1, 2]),
-    ('22', [1   ]),
-    ('33', [1, 2]),
+    (b'11', [1, 2]),
+    (b'22', [1   ]),
+    (b'33', [1, 2]),
 ])
 
 # deletion (optimize code should make it 2 chunks)
-testfilefixup(case2, '', ['', '22', ''],
+testfilefixup(case2, b'', [b'', b'22', b''],
               fixups=[(4, 0, 2, 0, 0), (4, 2, 4, 0, 0)])
 
 # 1:1 line mapping
-testfilefixup(case2, 'aaaa', ['', 'aa22aa', 'aaaa'])
+testfilefixup(case2, b'aaaa', [b'', b'aa22aa', b'aaaa'])
 
 # non 1:1 edits
 # note: unlike case0, the chunk is not "continuous" and no edit allowed
-testfilefixup(case2, 'aaa', case2)
+testfilefixup(case2, b'aaa', case2)
 
 # input case 3: rev 3 reverts rev 2
 case3 = buildcontents([
-    ('1', [1, 2, 3]),
-    ('2', [   2   ]),
-    ('3', [1, 2, 3]),
+    (b'1', [1, 2, 3]),
+    (b'2', [   2   ]),
+    (b'3', [1, 2, 3]),
 ])
 
 # 1:1 line mapping
-testfilefixup(case3, '13', case3)
-testfilefixup(case3, '1b', ['', '1b', '12b', '1b'])
-testfilefixup(case3, 'a3', ['', 'a3', 'a23', 'a3'])
-testfilefixup(case3, 'ab', ['', 'ab', 'a2b', 'ab'])
+testfilefixup(case3, b'13', case3)
+testfilefixup(case3, b'1b', [b'', b'1b', b'12b', b'1b'])
+testfilefixup(case3, b'a3', [b'', b'a3', b'a23', b'a3'])
+testfilefixup(case3, b'ab', [b'', b'ab', b'a2b', b'ab'])
 
 # non 1:1 edits
-testfilefixup(case3, 'a', case3)
-testfilefixup(case3, 'abc', case3)
+testfilefixup(case3, b'a', case3)
+testfilefixup(case3, b'abc', case3)
 
 # deletion
-testfilefixup(case3, '', ['', '', '2', ''])
+testfilefixup(case3, b'', [b'', b'', b'2', b''])
 
 # insertion
-testfilefixup(case3, 'a13c', ['', 'a13c', 'a123c', 'a13c'])
+testfilefixup(case3, b'a13c', [b'', b'a13c', b'a123c', b'a13c'])
 
 # input case 4: a slightly complex case
 case4 = buildcontents([
-    ('1', [1, 2, 3]),
-    ('2', [   2, 3]),
-    ('3', [1, 2,  ]),
-    ('4', [1,    3]),
-    ('5', [      3]),
-    ('6', [   2, 3]),
-    ('7', [   2   ]),
-    ('8', [   2, 3]),
-    ('9', [      3]),
+    (b'1', [1, 2, 3]),
+    (b'2', [   2, 3]),
+    (b'3', [1, 2,  ]),
+    (b'4', [1,    3]),
+    (b'5', [      3]),
+    (b'6', [   2, 3]),
+    (b'7', [   2   ]),
+    (b'8', [   2, 3]),
+    (b'9', [      3]),
 ])
 
-testfilefixup(case4, '1245689', case4)
-testfilefixup(case4, '1a2456bbb', case4)
-testfilefixup(case4, '1abc5689', case4)
-testfilefixup(case4, '1ab5689', ['', '134', '1a3678', '1ab5689'])
-testfilefixup(case4, 'aa2bcd8ee', ['', 'aa34', 'aa23d78', 'aa2bcd8ee'])
-testfilefixup(case4, 'aa2bcdd8ee',['', 'aa34', 'aa23678', 'aa24568ee'])
-testfilefixup(case4, 'aaaaaa', case4)
-testfilefixup(case4, 'aa258b', ['', 'aa34', 'aa2378', 'aa258b'])
-testfilefixup(case4, '25bb', ['', '34', '23678', '25689'])
-testfilefixup(case4, '27', ['', '34', '23678', '245689'])
-testfilefixup(case4, '28', ['', '34', '2378', '28'])
-testfilefixup(case4, '', ['', '34', '37', ''])
+testfilefixup(case4, b'1245689', case4)
+testfilefixup(case4, b'1a2456bbb', case4)
+testfilefixup(case4, b'1abc5689', case4)
+testfilefixup(case4, b'1ab5689', [b'', b'134', b'1a3678', b'1ab5689'])
+testfilefixup(case4, b'aa2bcd8ee', [b'', b'aa34', b'aa23d78', b'aa2bcd8ee'])
+testfilefixup(case4, b'aa2bcdd8ee',[b'', b'aa34', b'aa23678', b'aa24568ee'])
+testfilefixup(case4, b'aaaaaa', case4)
+testfilefixup(case4, b'aa258b', [b'', b'aa34', b'aa2378', b'aa258b'])
+testfilefixup(case4, b'25bb', [b'', b'34', b'23678', b'25689'])
+testfilefixup(case4, b'27', [b'', b'34', b'23678', b'245689'])
+testfilefixup(case4, b'28', [b'', b'34', b'2378', b'28'])
+testfilefixup(case4, b'', [b'', b'34', b'37', b''])
 
 # input case 5: replace a small chunk which is near a deleted line
 case5 = buildcontents([
-    ('12', [1, 2]),
-    ('3',  [1]),
-    ('4',  [1, 2]),
+    (b'12', [1, 2]),
+    (b'3',  [1]),
+    (b'4',  [1, 2]),
 ])
 
-testfilefixup(case5, '1cd4', ['', '1cd34', '1cd4'])
+testfilefixup(case5, b'1cd4', [b'', b'1cd34', b'1cd4'])
 
 # input case 6: base "changeset" is immutable
-case6 = ['1357', '0125678']
+case6 = [b'1357', b'0125678']
 
-testfilefixup(case6, '0125678', case6)
-testfilefixup(case6, '0a25678', case6)
-testfilefixup(case6, '0a256b8', case6)
-testfilefixup(case6, 'abcdefg', ['1357', 'a1c5e7g'])
-testfilefixup(case6, 'abcdef', case6)
-testfilefixup(case6, '', ['1357', '157'])
-testfilefixup(case6, '0123456789', ['1357', '0123456789'])
+testfilefixup(case6, b'0125678', case6)
+testfilefixup(case6, b'0a25678', case6)
+testfilefixup(case6, b'0a256b8', case6)
+testfilefixup(case6, b'abcdefg', [b'1357', b'a1c5e7g'])
+testfilefixup(case6, b'abcdef', case6)
+testfilefixup(case6, b'', [b'1357', b'157'])
+testfilefixup(case6, b'0123456789', [b'1357', b'0123456789'])
 
 # input case 7: change an empty file
-case7 = ['']
+case7 = [b'']
 
-testfilefixup(case7, '1', case7)
+testfilefixup(case7, b'1', case7)
diff --git a/contrib/python3-whitelist b/contrib/python3-whitelist
--- a/contrib/python3-whitelist
+++ b/contrib/python3-whitelist
@@ -1,4 +1,5 @@
 test-abort-checkin.t
+test-absorb-filefixupstate.py
 test-absorb-phase.t
 test-absorb-strip.t
 test-add.t



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


More information about the Mercurial-devel mailing list