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() | ||
Mads Kiilerich
|
r16498 | repo = hg.repository(myui, path='.', create=True) | ||
fl = repo.file('foobar') | ||||
def addrev(text, renamed=False): | ||||
if renamed: | ||||
timeless@mozdev.org
|
r17486 | # data doesn't matter. Just make sure filelog.renamed() returns True | ||
Augie Fackler
|
r20684 | meta = {'copyrev': hex(nullid), 'copy': 'bar'} | ||
Mads Kiilerich
|
r16498 | else: | ||
meta = {} | ||||
lock = t = None | ||||
try: | ||||
lock = repo.lock() | ||||
t = repo.transaction('commit') | ||||
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 | |||
textwith = '\1\nfoo' | ||||
without = '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') | ||||
Robert Stanca
|
r28744 | print('OK.') | ||