Mercurial > hg
changeset 37900:b3ffa2faae04
tests: port test-filecache.py to Python 3
Only remarkable bit is my wrapper around print(), which I regret a
little, but not enough to go back and try to do something cleaner.
Differential Revision: https://phab.mercurial-scm.org/D3506
author | Augie Fackler <augie@google.com> |
---|---|
date | Fri, 27 Apr 2018 11:22:00 -0400 |
parents | 2b3b6187c316 |
children | bbff7170f665 |
files | contrib/python3-whitelist tests/test-filecache.py |
diffstat | 2 files changed, 22 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/contrib/python3-whitelist Fri Apr 27 11:07:24 2018 -0400 +++ b/contrib/python3-whitelist Fri Apr 27 11:22:00 2018 -0400 @@ -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
--- a/tests/test-filecache.py Fri Apr 27 11:07:24 2018 -0400 +++ b/tests/test-filecache.py Fri Apr 27 11:22:00 2018 -0400 @@ -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')