test-context.py
148 lines
| 4.3 KiB
| text/x-python
|
PythonLexer
/ tests / test-context.py
Robert Stanca
|
r28738 | from __future__ import absolute_import, print_function | ||
Thomas Arendsen Hein
|
r4110 | import os | ||
Robert Stanca
|
r28735 | from mercurial import ( | ||
Robert Stanca
|
r28738 | context, | ||
encoding, | ||||
Robert Stanca
|
r28735 | hg, | ||
Yuya Nishihara
|
r28775 | ui as uimod, | ||
Robert Stanca
|
r28735 | ) | ||
Thomas Arendsen Hein
|
r4110 | |||
Yuya Nishihara
|
r28775 | u = uimod.ui() | ||
Thomas Arendsen Hein
|
r4110 | |||
repo = hg.repository(u, 'test1', create=1) | ||||
os.chdir('test1') | ||||
# create 'foo' with fixed time stamp | ||||
FUJIWARA Katsunori
|
r23060 | f = open('foo', 'wb') | ||
Thomas Arendsen Hein
|
r4110 | f.write('foo\n') | ||
f.close() | ||||
os.utime('foo', (1000, 1000)) | ||||
# add+commit 'foo' | ||||
Dirkjan Ochtman
|
r11303 | repo[None].add(['foo']) | ||
Thomas Arendsen Hein
|
r4110 | repo.commit(text='commit1', date="0 0") | ||
Matt Harbison
|
r27056 | if os.name == 'nt': | ||
d = repo[None]['foo'].date() | ||||
Robert Stanca
|
r28738 | print("workingfilectx.date = (%d, %d)" % (d[0], d[1])) | ||
Matt Harbison
|
r27056 | else: | ||
Robert Stanca
|
r28738 | print("workingfilectx.date =", repo[None]['foo'].date()) | ||
Martin Geisler
|
r14379 | |||
# test memctx with non-ASCII commit message | ||||
def filectxfn(repo, memctx, path): | ||||
Sean Farley
|
r21689 | return context.memfilectx(repo, "foo", "") | ||
Martin Geisler
|
r14379 | |||
ctx = context.memctx(repo, ['tip', None], | ||||
encoding.tolocal("Gr\xc3\xbcezi!"), | ||||
["foo"], filectxfn) | ||||
ctx.commit() | ||||
for enc in "ASCII", "Latin-1", "UTF-8": | ||||
encoding.encoding = enc | ||||
Robert Stanca
|
r28738 | print("%-8s: %s" % (enc, repo["tip"].description())) | ||
Sean Farley
|
r21836 | |||
# test performing a status | ||||
def getfilectx(repo, memctx, f): | ||||
fctx = memctx.parents()[0][f] | ||||
data, flags = fctx.data(), fctx.flags() | ||||
if f == 'foo': | ||||
data += 'bar\n' | ||||
return context.memfilectx(repo, f, data, 'l' in flags, 'x' in flags) | ||||
ctxa = repo.changectx(0) | ||||
Sean Farley
|
r21837 | ctxb = context.memctx(repo, [ctxa.node(), None], "test diff", ["foo"], | ||
getfilectx, ctxa.user(), ctxa.date()) | ||||
Sean Farley
|
r21836 | |||
Robert Stanca
|
r28738 | print(ctxb.status(ctxa)) | ||
Sean Farley
|
r21837 | |||
# test performing a diff on a memctx | ||||
for d in ctxb.diff(ctxa, git=True): | ||||
Robert Stanca
|
r28738 | print(d) | ||
FUJIWARA Katsunori
|
r23700 | |||
Mads Kiilerich
|
r24180 | # test safeness and correctness of "ctx.status()" | ||
Robert Stanca
|
r28738 | print('= checking context.status():') | ||
FUJIWARA Katsunori
|
r23700 | |||
# ancestor "wcctx ~ 2" | ||||
actx2 = repo['.'] | ||||
repo.wwrite('bar-m', 'bar-m\n', '') | ||||
repo.wwrite('bar-r', 'bar-r\n', '') | ||||
repo[None].add(['bar-m', 'bar-r']) | ||||
repo.commit(text='add bar-m, bar-r', date="0 0") | ||||
# ancestor "wcctx ~ 1" | ||||
actx1 = repo['.'] | ||||
repo.wwrite('bar-m', 'bar-m bar-m\n', '') | ||||
repo.wwrite('bar-a', 'bar-a\n', '') | ||||
repo[None].add(['bar-a']) | ||||
repo[None].forget(['bar-r']) | ||||
# status at this point: | ||||
# M bar-m | ||||
# A bar-a | ||||
# R bar-r | ||||
# C foo | ||||
from mercurial import scmutil | ||||
Robert Stanca
|
r28738 | print('== checking workingctx.status:') | ||
FUJIWARA Katsunori
|
r23700 | |||
wctx = repo[None] | ||||
Robert Stanca
|
r28738 | print('wctx._status=%s' % (str(wctx._status))) | ||
FUJIWARA Katsunori
|
r23700 | |||
Robert Stanca
|
r28738 | print('=== with "pattern match":') | ||
print(actx1.status(other=wctx, | ||||
match=scmutil.matchfiles(repo, ['bar-m', 'foo']))) | ||||
print('wctx._status=%s' % (str(wctx._status))) | ||||
print(actx2.status(other=wctx, | ||||
match=scmutil.matchfiles(repo, ['bar-m', 'foo']))) | ||||
print('wctx._status=%s' % (str(wctx._status))) | ||||
FUJIWARA Katsunori
|
r23709 | |||
Robert Stanca
|
r28738 | print('=== with "always match" and "listclean=True":') | ||
print(actx1.status(other=wctx, listclean=True)) | ||||
print('wctx._status=%s' % (str(wctx._status))) | ||||
print(actx2.status(other=wctx, listclean=True)) | ||||
print('wctx._status=%s' % (str(wctx._status))) | ||||
FUJIWARA Katsunori
|
r23711 | |||
Robert Stanca
|
r28738 | print("== checking workingcommitctx.status:") | ||
FUJIWARA Katsunori
|
r23711 | |||
wcctx = context.workingcommitctx(repo, | ||||
scmutil.status(['bar-m'], | ||||
['bar-a'], | ||||
[], | ||||
[], [], [], []), | ||||
text='', date='0 0') | ||||
Robert Stanca
|
r28738 | print('wcctx._status=%s' % (str(wcctx._status))) | ||
FUJIWARA Katsunori
|
r23711 | |||
Robert Stanca
|
r28738 | print('=== with "always match":') | ||
print(actx1.status(other=wcctx)) | ||||
print('wcctx._status=%s' % (str(wcctx._status))) | ||||
print(actx2.status(other=wcctx)) | ||||
print('wcctx._status=%s' % (str(wcctx._status))) | ||||
FUJIWARA Katsunori
|
r23711 | |||
Robert Stanca
|
r28738 | print('=== with "always match" and "listclean=True":') | ||
print(actx1.status(other=wcctx, listclean=True)) | ||||
print('wcctx._status=%s' % (str(wcctx._status))) | ||||
print(actx2.status(other=wcctx, listclean=True)) | ||||
print('wcctx._status=%s' % (str(wcctx._status))) | ||||
FUJIWARA Katsunori
|
r23712 | |||
Robert Stanca
|
r28738 | print('=== with "pattern match":') | ||
print(actx1.status(other=wcctx, | ||||
match=scmutil.matchfiles(repo, ['bar-m', 'foo']))) | ||||
print('wcctx._status=%s' % (str(wcctx._status))) | ||||
print(actx2.status(other=wcctx, | ||||
match=scmutil.matchfiles(repo, ['bar-m', 'foo']))) | ||||
print('wcctx._status=%s' % (str(wcctx._status))) | ||||
FUJIWARA Katsunori
|
r23712 | |||
Robert Stanca
|
r28738 | print('=== with "pattern match" and "listclean=True":') | ||
print(actx1.status(other=wcctx, | ||||
FUJIWARA Katsunori
|
r23712 | match=scmutil.matchfiles(repo, ['bar-r', 'foo']), | ||
Robert Stanca
|
r28738 | listclean=True)) | ||
print('wcctx._status=%s' % (str(wcctx._status))) | ||||
print(actx2.status(other=wcctx, | ||||
FUJIWARA Katsunori
|
r23712 | match=scmutil.matchfiles(repo, ['bar-r', 'foo']), | ||
Robert Stanca
|
r28738 | listclean=True)) | ||
print('wcctx._status=%s' % (str(wcctx._status))) | ||||