Mercurial > public > mercurial-scm > hg-stable
view tests/test-filelog.py @ 52742:f8f14e6d032b
py3: update the remaining shebang lines (mostly tests) to `python3`
I noticed this when running `py hghave` on a system that still has Python2- the
Windows launcher attempts to honor the version of python in the shebang, but
`hghave` recently gained py3 type annotations, so that resulted in a
SyntaxError. I guess CI has the compat shim installed to redirect `python` to
`python3`, and maybe that's why nobody noticed.
These were located by grepping for `#!.+python\b`. The remaining handful of
cases are tests trying to find python files, which is fine as-is.
The one thing to call out here is that apparently the RPM building hasn't worked
with Python3 (or we've been getting lucky). `contrib/hg-ssh` has had a python3
shebang line since late 2020, which means the EOL anchor would have caused it to
not match and not be replaced with `%{pythonexe}`. OTOH, it looks like that
variable was used prior to the `hg-ssh` update in order to default to python3
(as opposed to using a specific /path/to/pythonX), and maybe the update to
`hg-ssh` simply broke python2 builds. I'm not going to worry about this for
now, since there are also direct calls to `setup.py`, which no longer work as of
this release cycle. Somebody interested in RPMs can figure out all of the
issues at once.
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Thu, 30 Jan 2025 13:51:02 -0500 |
parents | 6000f5b25c9b |
children |
line wrap: on
line source
#!/usr/bin/env python3 """ Tests the behavior of filelog w.r.t. data starting with '\1\n' """ from mercurial.node import hex from mercurial import ( hg, ui as uimod, ) myui = uimod.ui.load() repo = hg.repository(myui, path=b'.', create=True) fl = repo.file(b'foobar') def addrev(text, renamed=False): if renamed: # data doesn't matter. Just make sure filelog.renamed() returns True meta = {b'copyrev': hex(repo.nullid), b'copy': b'bar'} else: meta = {} lock = t = None try: lock = repo.lock() t = repo.transaction(b'commit') node = fl.add(text, meta, t, 0, repo.nullid, repo.nullid) return node finally: if t: t.close() if lock: lock.release() def error(text): print('ERROR: ' + text) textwith = b'\1\nfoo' without = b'foo' node = addrev(textwith) if not textwith == fl.read(node): error('filelog.read for data starting with \\1\\n') if fl.cmp(node, textwith) or not fl.cmp(node, without): error('filelog.cmp for data starting with \\1\\n') if fl.size(0) != len(textwith): error( 'FIXME: This is a known failure of filelog.size for data starting ' 'with \\1\\n' ) node = addrev(textwith, renamed=True) if not textwith == fl.read(node): error('filelog.read for a renaming + data starting with \\1\\n') if fl.cmp(node, textwith) or not fl.cmp(node, without): error('filelog.cmp for a renaming + data starting with \\1\\n') if fl.size(1) != len(textwith): error('filelog.size for a renaming + data starting with \\1\\n') print('OK.')