D3506: tests: port test-filecache.py to Python 3

durin42 (Augie Fackler) phabricator at mercurial-scm.org
Tue May 8 16:22:51 EDT 2018


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

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D3506?vs=8574&id=8582

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

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

CHANGE DETAILS

diff --git a/tests/test-filecache.py b/tests/test-filecache.py
--- a/tests/test-filecache.py
+++ b/tests/test-filecache.py
@@ -8,6 +8,16 @@
                     'cacheable']):
     sys.exit(80)
 
+print_ = print
+def print(*args, **kwargs):
+    """print() wrapper that flushes stdout buffers to avoid py3 buffer issues
+
+    We could also just write directly to sys.stdout.buffer the way the
+    ui object will, but this was easier for porting the test.
+    """
+    print_(*args, **kwargs)
+    sys.stdout.flush()
+
 from mercurial import (
     extensions,
     hg,
@@ -46,7 +56,7 @@
     def invalidate(self):
         for k in self._filecache:
             try:
-                delattr(self, k)
+                delattr(self, pycompat.sysstr(k))
             except AttributeError:
                 pass
 
@@ -84,8 +94,8 @@
     # atomic replace file, size doesn't change
     # hopefully st_mtime doesn't change as well so this doesn't use the cache
     # because of inode change
-    f = vfsmod.vfs('.')('x', 'w', atomictemp=True)
-    f.write('b')
+    f = vfsmod.vfs(b'.')(b'x', b'w', atomictemp=True)
+    f.write(b'b')
     f.close()
 
     repo.invalidate()
@@ -108,19 +118,19 @@
     # should recreate the object
     repo.cached
 
-    f = vfsmod.vfs('.')('y', 'w', atomictemp=True)
-    f.write('B')
+    f = vfsmod.vfs(b'.')(b'y', b'w', atomictemp=True)
+    f.write(b'B')
     f.close()
 
     repo.invalidate()
     print("* file y changed inode")
     repo.cached
 
-    f = vfsmod.vfs('.')('x', 'w', atomictemp=True)
-    f.write('c')
+    f = vfsmod.vfs(b'.')(b'x', b'w', atomictemp=True)
+    f.write(b'c')
     f.close()
-    f = vfsmod.vfs('.')('y', 'w', atomictemp=True)
-    f.write('C')
+    f = vfsmod.vfs(b'.')(b'y', b'w', atomictemp=True)
+    f.write(b'C')
     f.close()
 
     repo.invalidate()
@@ -155,14 +165,14 @@
     repo = hg.repository(uimod.ui.load())
     # first rollback clears the filecache, but changelog to stays in __dict__
     repo.rollback()
-    repo.commit('.')
+    repo.commit(b'.')
     # second rollback comes along and touches the changelog externally
     # (file is moved)
     repo.rollback()
     # but since changelog isn't under the filecache control anymore, we don't
     # see that it changed, and return the old changelog without reconstructing
     # it
-    repo.commit('.')
+    repo.commit(b'.')
 
 def setbeforeget(repo):
     os.remove('x')
diff --git a/contrib/python3-whitelist b/contrib/python3-whitelist
--- a/contrib/python3-whitelist
+++ b/contrib/python3-whitelist
@@ -147,6 +147,7 @@
 test-extdiff.t
 test-extra-filelog-entry.t
 test-filebranch.t
+test-filecache.py
 test-fileset-generated.t
 test-fix-topology.t
 test-flags.t



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


More information about the Mercurial-devel mailing list