##// END OF EJS Templates
localrepo: use context manager for lock and transaction in commitctx()...
localrepo: use context manager for lock and transaction in commitctx() Differential Revision: https://phab.mercurial-scm.org/D5624

File last commit:

r38680:a75896bf default
r41400:0132221c default
Show More
test-context.py
211 lines | 6.3 KiB | text/x-python | PythonLexer
Robert Stanca
py3: lexicographical order imports and print_function in test-context.py
r28738 from __future__ import absolute_import, print_function
Thomas Arendsen Hein
Fixed workingfilectx.date() (found by Thomas Waldmann) with test.
r4110 import os
Augie Fackler
cleanup: use stat_result[stat.ST_MTIME] instead of stat_result.st_mtime...
r36799 import stat
Augie Fackler
tests: port test-context.py to Python 3...
r37941 import sys
Jun Wu
test-context: add a case demonstrating manifest caching problem...
r32518 from mercurial.node import hex
Robert Stanca
py3: use absolute_import in test-context.py
r28735 from mercurial import (
Robert Stanca
py3: lexicographical order imports and print_function in test-context.py
r28738 context,
Yuya Nishihara
diffutil: move the module out of utils package...
r38607 diffutil,
Robert Stanca
py3: lexicographical order imports and print_function in test-context.py
r28738 encoding,
Robert Stanca
py3: use absolute_import in test-context.py
r28735 hg,
Jun Wu
test-context: add a case demonstrating manifest caching problem...
r32518 scmutil,
Yuya Nishihara
tests: alias ui as uimod in test-context
r28775 ui as uimod,
Robert Stanca
py3: use absolute_import in test-context.py
r28735 )
Thomas Arendsen Hein
Fixed workingfilectx.date() (found by Thomas Waldmann) with test.
r4110
Augie Fackler
tests: port test-context.py to Python 3...
r37941 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()
def printb(data, end=b'\n'):
out = getattr(sys.stdout, 'buffer', sys.stdout)
out.write(data + end)
out.flush()
Yuya Nishihara
ui: factor out ui.load() to create a ui without loading configs (API)...
r30559 u = uimod.ui.load()
Thomas Arendsen Hein
Fixed workingfilectx.date() (found by Thomas Waldmann) with test.
r4110
Augie Fackler
tests: port test-context.py to Python 3...
r37941 repo = hg.repository(u, b'test1', create=1)
Thomas Arendsen Hein
Fixed workingfilectx.date() (found by Thomas Waldmann) with test.
r4110 os.chdir('test1')
# create 'foo' with fixed time stamp
FUJIWARA Katsunori
tests: open file in binary mode to use POSIX end-of-line style anywhere...
r23060 f = open('foo', 'wb')
timeless
tests: mark test-context.py write as binary
r29187 f.write(b'foo\n')
Thomas Arendsen Hein
Fixed workingfilectx.date() (found by Thomas Waldmann) with test.
r4110 f.close()
os.utime('foo', (1000, 1000))
# add+commit 'foo'
Augie Fackler
tests: port test-context.py to Python 3...
r37941 repo[None].add([b'foo'])
repo.commit(text=b'commit1', date=b"0 0")
Thomas Arendsen Hein
Fixed workingfilectx.date() (found by Thomas Waldmann) with test.
r4110
Augie Fackler
tests: port test-context.py to Python 3...
r37941 d = repo[None][b'foo'].date()
Matt Harbison
test-context: conditionalize the workingfilectx date printing for Windows...
r27056 if os.name == 'nt':
Tristan Seligmann
hg: tolerate long vs. int in test-context.py...
r33797 d = d[:2]
print("workingfilectx.date = (%d, %d)" % d)
Martin Geisler
changelog: convert user and desc from local encoding early...
r14379
# test memctx with non-ASCII commit message
def filectxfn(repo, memctx, path):
Augie Fackler
tests: port test-context.py to Python 3...
r37941 return context.memfilectx(repo, memctx, b"foo", b"")
Martin Geisler
changelog: convert user and desc from local encoding early...
r14379
Augie Fackler
tests: port test-context.py to Python 3...
r37941 ctx = context.memctx(repo, [b'tip', None],
encoding.tolocal(b"Gr\xc3\xbcezi!"),
[b"foo"], filectxfn)
Martin Geisler
changelog: convert user and desc from local encoding early...
r14379 ctx.commit()
for enc in "ASCII", "Latin-1", "UTF-8":
encoding.encoding = enc
Augie Fackler
tests: port test-context.py to Python 3...
r37941 printb(b"%-8s: %s" % (enc.encode('ascii'), repo[b"tip"].description()))
Sean Farley
test-context: add test for memctx status
r21836
# test performing a status
def getfilectx(repo, memctx, f):
fctx = memctx.parents()[0][f]
data, flags = fctx.data(), fctx.flags()
Augie Fackler
tests: port test-context.py to Python 3...
r37941 if f == b'foo':
data += b'bar\n'
return context.memfilectx(
repo, memctx, f, data, b'l' in flags, b'x' in flags)
Sean Farley
test-context: add test for memctx status
r21836
Martin von Zweigbergk
tests: remove dependence on repo.changectx()...
r37320 ctxa = repo[0]
Augie Fackler
tests: port test-context.py to Python 3...
r37941 ctxb = context.memctx(repo, [ctxa.node(), None], b"test diff", [b"foo"],
Sean Farley
test-context: add test for performing a diff on a memctx...
r21837 getfilectx, ctxa.user(), ctxa.date())
Sean Farley
test-context: add test for memctx status
r21836
Robert Stanca
py3: lexicographical order imports and print_function in test-context.py
r28738 print(ctxb.status(ctxa))
Sean Farley
test-context: add test for performing a diff on a memctx...
r21837
# test performing a diff on a memctx
Augie Fackler
tests: add missing b prefix in test-context.py...
r38680 diffopts = diffutil.diffallopts(repo.ui, {b'git': True})
Boris Feld
tests: update test-context.py to use diffopts as diff argument
r38582 for d in ctxb.diff(ctxa, opts=diffopts):
Augie Fackler
tests: port test-context.py to Python 3...
r37941 printb(d, end=b'')
FUJIWARA Katsunori
context: cache self._status correctly at workingctx.status...
r23700
Mads Kiilerich
spelling: fixes from proofreading of spell checker issues
r24180 # test safeness and correctness of "ctx.status()"
Robert Stanca
py3: lexicographical order imports and print_function in test-context.py
r28738 print('= checking context.status():')
FUJIWARA Katsunori
context: cache self._status correctly at workingctx.status...
r23700
# ancestor "wcctx ~ 2"
Augie Fackler
tests: port test-context.py to Python 3...
r37941 actx2 = repo[b'.']
FUJIWARA Katsunori
context: cache self._status correctly at workingctx.status...
r23700
Augie Fackler
tests: port test-context.py to Python 3...
r37941 repo.wwrite(b'bar-m', b'bar-m\n', b'')
repo.wwrite(b'bar-r', b'bar-r\n', b'')
repo[None].add([b'bar-m', b'bar-r'])
repo.commit(text=b'add bar-m, bar-r', date=b"0 0")
FUJIWARA Katsunori
context: cache self._status correctly at workingctx.status...
r23700
# ancestor "wcctx ~ 1"
Augie Fackler
tests: port test-context.py to Python 3...
r37941 actx1 = repo[b'.']
FUJIWARA Katsunori
context: cache self._status correctly at workingctx.status...
r23700
Augie Fackler
tests: port test-context.py to Python 3...
r37941 repo.wwrite(b'bar-m', b'bar-m bar-m\n', b'')
repo.wwrite(b'bar-a', b'bar-a\n', b'')
repo[None].add([b'bar-a'])
repo[None].forget([b'bar-r'])
FUJIWARA Katsunori
context: cache self._status correctly at workingctx.status...
r23700
# status at this point:
# M bar-m
# A bar-a
# R bar-r
# C foo
from mercurial import scmutil
Robert Stanca
py3: lexicographical order imports and print_function in test-context.py
r28738 print('== checking workingctx.status:')
FUJIWARA Katsunori
context: cache self._status correctly at workingctx.status...
r23700
wctx = repo[None]
Robert Stanca
py3: lexicographical order imports and print_function in test-context.py
r28738 print('wctx._status=%s' % (str(wctx._status)))
FUJIWARA Katsunori
context: cache self._status correctly at workingctx.status...
r23700
Robert Stanca
py3: lexicographical order imports and print_function in test-context.py
r28738 print('=== with "pattern match":')
print(actx1.status(other=wctx,
Augie Fackler
tests: port test-context.py to Python 3...
r37941 match=scmutil.matchfiles(repo, [b'bar-m', b'foo'])))
Robert Stanca
py3: lexicographical order imports and print_function in test-context.py
r28738 print('wctx._status=%s' % (str(wctx._status)))
print(actx2.status(other=wctx,
Augie Fackler
tests: port test-context.py to Python 3...
r37941 match=scmutil.matchfiles(repo, [b'bar-m', b'foo'])))
Robert Stanca
py3: lexicographical order imports and print_function in test-context.py
r28738 print('wctx._status=%s' % (str(wctx._status)))
FUJIWARA Katsunori
context: make unknown/ignored/clean of cached status empty for equivalence...
r23709
Robert Stanca
py3: lexicographical order imports and print_function in test-context.py
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
context: avoid breaking already fixed self._status at ctx.status()...
r23711
Robert Stanca
py3: lexicographical order imports and print_function in test-context.py
r28738 print("== checking workingcommitctx.status:")
FUJIWARA Katsunori
context: avoid breaking already fixed self._status at ctx.status()...
r23711
wcctx = context.workingcommitctx(repo,
Augie Fackler
tests: port test-context.py to Python 3...
r37941 scmutil.status([b'bar-m'],
[b'bar-a'],
FUJIWARA Katsunori
context: avoid breaking already fixed self._status at ctx.status()...
r23711 [],
[], [], [], []),
Augie Fackler
tests: port test-context.py to Python 3...
r37941 text=b'', date=b'0 0')
Robert Stanca
py3: lexicographical order imports and print_function in test-context.py
r28738 print('wcctx._status=%s' % (str(wcctx._status)))
FUJIWARA Katsunori
context: avoid breaking already fixed self._status at ctx.status()...
r23711
Robert Stanca
py3: lexicographical order imports and print_function in test-context.py
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
context: avoid breaking already fixed self._status at ctx.status()...
r23711
Robert Stanca
py3: lexicographical order imports and print_function in test-context.py
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
context: override _dirstatestatus in workingcommitctx for correct matching...
r23712
Robert Stanca
py3: lexicographical order imports and print_function in test-context.py
r28738 print('=== with "pattern match":')
print(actx1.status(other=wcctx,
Augie Fackler
tests: port test-context.py to Python 3...
r37941 match=scmutil.matchfiles(repo, [b'bar-m', b'foo'])))
Robert Stanca
py3: lexicographical order imports and print_function in test-context.py
r28738 print('wcctx._status=%s' % (str(wcctx._status)))
print(actx2.status(other=wcctx,
Augie Fackler
tests: port test-context.py to Python 3...
r37941 match=scmutil.matchfiles(repo, [b'bar-m', b'foo'])))
Robert Stanca
py3: lexicographical order imports and print_function in test-context.py
r28738 print('wcctx._status=%s' % (str(wcctx._status)))
FUJIWARA Katsunori
context: override _dirstatestatus in workingcommitctx for correct matching...
r23712
Robert Stanca
py3: lexicographical order imports and print_function in test-context.py
r28738 print('=== with "pattern match" and "listclean=True":')
print(actx1.status(other=wcctx,
Augie Fackler
tests: port test-context.py to Python 3...
r37941 match=scmutil.matchfiles(repo, [b'bar-r', b'foo']),
Robert Stanca
py3: lexicographical order imports and print_function in test-context.py
r28738 listclean=True))
print('wcctx._status=%s' % (str(wcctx._status)))
print(actx2.status(other=wcctx,
Augie Fackler
tests: port test-context.py to Python 3...
r37941 match=scmutil.matchfiles(repo, [b'bar-r', b'foo']),
Robert Stanca
py3: lexicographical order imports and print_function in test-context.py
r28738 listclean=True))
print('wcctx._status=%s' % (str(wcctx._status)))
Jun Wu
test-context: add a case demonstrating manifest caching problem...
r32518
os.chdir('..')
# test manifestlog being changed
print('== commit with manifestlog invalidated')
Augie Fackler
tests: port test-context.py to Python 3...
r37941 repo = hg.repository(u, b'test2', create=1)
Jun Wu
test-context: add a case demonstrating manifest caching problem...
r32518 os.chdir('test2')
# make some commits
for i in [b'1', b'2', b'3']:
with open(i, 'wb') as f:
f.write(i)
status = scmutil.status([], [i], [], [], [], [], [])
ctx = context.workingcommitctx(repo, status, text=i, user=b'test@test.com',
date=(0, 0))
ctx.p1().manifest() # side effect: cache manifestctx
n = repo.commitctx(ctx)
Augie Fackler
tests: port test-context.py to Python 3...
r37941 printb(b'commit %s: %s' % (i, hex(n)))
Jun Wu
test-context: add a case demonstrating manifest caching problem...
r32518
# touch 00manifest.i mtime so storecache could expire.
# repo.__dict__['manifestlog'] is deleted by transaction releasefn.
Augie Fackler
tests: port test-context.py to Python 3...
r37941 st = repo.svfs.stat(b'00manifest.i')
repo.svfs.utime(b'00manifest.i',
Augie Fackler
cleanup: use stat_result[stat.ST_MTIME] instead of stat_result.st_mtime...
r36799 (st[stat.ST_MTIME] + 1, st[stat.ST_MTIME] + 1))
Jun Wu
test-context: add a case demonstrating manifest caching problem...
r32518
# read the file just committed
try:
if repo[n][i].data() != i:
print('data mismatch')
except Exception as ex:
print('cannot read data: %r' % ex)
Martin von Zweigbergk
repo: skip invalidation of changelog if it has 'delayed' changes (API)...
r33672
Augie Fackler
tests: port test-context.py to Python 3...
r37941 with repo.wlock(), repo.lock(), repo.transaction(b'test'):
Martin von Zweigbergk
repo: skip invalidation of changelog if it has 'delayed' changes (API)...
r33672 with open(b'4', 'wb') as f:
f.write(b'4')
Augie Fackler
tests: port test-context.py to Python 3...
r37941 repo.dirstate.normal(b'4')
repo.commit(b'4')
Martin von Zweigbergk
repo: skip invalidation of changelog if it has 'delayed' changes (API)...
r33672 revsbefore = len(repo.changelog)
repo.invalidate(clearfilecache=True)
revsafter = len(repo.changelog)
if revsbefore != revsafter:
print('changeset lost by repo.invalidate()')