Patchwork [05,of,11] py3: make sure we use bytes in generate-working-copy-states.py

login
register
mail settings
Submitter Pulkit Goyal
Date Feb. 23, 2018, 6:15 p.m.
Message ID <66968eaf19d62767cbdb.1519409718@workspace>
Download mbox | patch
Permalink /patch/28282/
State Accepted
Headers show

Comments

Pulkit Goyal - Feb. 23, 2018, 6:15 p.m.
# HG changeset patch
# User Pulkit Goyal <7895pulkit@gmail.com>
# Date 1519386951 -19800
#      Fri Feb 23 17:25:51 2018 +0530
# Node ID 66968eaf19d62767cbdb446d0c173e67d5a925ce
# Parent  6610c379cb0f90d9dbdc787e3d7982fce07ded86
py3: make sure we use bytes in generate-working-copy-states.py

Patch

diff --git a/tests/generate-working-copy-states.py b/tests/generate-working-copy-states.py
--- a/tests/generate-working-copy-states.py
+++ b/tests/generate-working-copy-states.py
@@ -42,12 +42,12 @@  import sys
 def generatestates(maxchangesets, parentcontents):
     depth = len(parentcontents)
     if depth == maxchangesets + 1:
-        for tracked in ('untracked', 'tracked'):
-            filename = "_".join([(content is None and 'missing' or content) for
-                                 content in parentcontents]) + "-" + tracked
+        for tracked in (b'untracked', b'tracked'):
+            filename = b"_".join([(content is None and b'missing' or content)
+                                for content in parentcontents]) + b"-" + tracked
             yield (filename, parentcontents)
     else:
-        for content in ({None, 'content' + str(depth + 1)} |
+        for content in ({None, b'content' + (b"%d" % (depth + 1))} |
                       set(parentcontents)):
             for combination in generatestates(maxchangesets,
                                               parentcontents + [content]):
@@ -71,7 +71,7 @@  for filename, states in combinations:
         if depth == 'wc':
             # Make sure there is content so the file gets written and can be
             # tracked. It will be deleted outside of this script.
-            content.append((filename, states[maxchangesets] or 'TOBEDELETED'))
+            content.append((filename, states[maxchangesets] or b'TOBEDELETED'))
         else:
             content.append((filename, states[int(depth) - 1]))
     else:
@@ -82,7 +82,7 @@  for filename, states in combinations:
 for filename, data in content:
     if data is not None:
         f = open(filename, 'wb')
-        f.write(data + '\n')
+        f.write(data + b'\n')
         f.close()
     elif os.path.exists(filename):
         os.remove(filename)