test-filelog.py
63 lines
| 1.6 KiB
| text/x-python
|
PythonLexer
/ tests / test-filelog.py
Mads Kiilerich
|
r16498 | #!/usr/bin/env python | ||
""" | ||||
timeless@mozdev.org
|
r26098 | Tests the behavior of filelog w.r.t. data starting with '\1\n' | ||
Mads Kiilerich
|
r16498 | """ | ||
Robert Stanca
|
r28744 | from __future__ import absolute_import, print_function | ||
Yuya Nishihara
|
r29205 | |||
from mercurial.node import ( | ||||
hex, | ||||
nullid, | ||||
) | ||||
Robert Stanca
|
r28743 | from mercurial import ( | ||
hg, | ||||
Yuya Nishihara
|
r28805 | ui as uimod, | ||
Robert Stanca
|
r28743 | ) | ||
Mads Kiilerich
|
r16498 | |||
Yuya Nishihara
|
r30559 | myui = uimod.ui.load() | ||
Augie Fackler
|
r37952 | repo = hg.repository(myui, path=b'.', create=True) | ||
Mads Kiilerich
|
r16498 | |||
Augie Fackler
|
r37952 | fl = repo.file(b'foobar') | ||
Mads Kiilerich
|
r16498 | |||
def addrev(text, renamed=False): | ||||
if renamed: | ||||
timeless@mozdev.org
|
r17486 | # data doesn't matter. Just make sure filelog.renamed() returns True | ||
Augie Fackler
|
r37952 | meta = {b'copyrev': hex(nullid), b'copy': b'bar'} | ||
Mads Kiilerich
|
r16498 | else: | ||
meta = {} | ||||
lock = t = None | ||||
try: | ||||
lock = repo.lock() | ||||
Augie Fackler
|
r37952 | t = repo.transaction(b'commit') | ||
Mads Kiilerich
|
r16498 | node = fl.add(text, meta, t, 0, nullid, nullid) | ||
return node | ||||
finally: | ||||
if t: | ||||
t.close() | ||||
if lock: | ||||
lock.release() | ||||
def error(text): | ||||
Robert Stanca
|
r28744 | print('ERROR: ' + text) | ||
Mads Kiilerich
|
r16498 | |||
Augie Fackler
|
r37952 | textwith = b'\1\nfoo' | ||
without = b'foo' | ||||
Mads Kiilerich
|
r16498 | |||
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') | ||||
Robert Stanca
|
r28744 | print('OK.') | ||