##// END OF EJS Templates
errors: stop passing non-strings to Abort's constructor...
errors: stop passing non-strings to Abort's constructor The next patch will change `Abort`'s constructor and `__bytes__` functions and they will start assuming that the first argument is the messages as `bytes`. Differential Revision: https://phab.mercurial-scm.org/D9178

File last commit:

r43346:2372284d default
r46273:a736ab68 default
Show More
test-context.py
249 lines | 6.1 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
Augie Fackler
formatting: blacken the codebase...
r43346
Augie Fackler
tests: port test-context.py to Python 3...
r37941 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()
Augie Fackler
formatting: blacken the codebase...
r43346
Augie Fackler
tests: port test-context.py to Python 3...
r37941 def printb(data, end=b'\n'):
out = getattr(sys.stdout, 'buffer', sys.stdout)
out.write(data + end)
out.flush()
Augie Fackler
formatting: blacken the codebase...
r43346
Martin von Zweigbergk
tests: rename "u" to more usual "ui" in test-context.py...
r42223 ui = uimod.ui.load()
Thomas Arendsen Hein
Fixed workingfilectx.date() (found by Thomas Waldmann) with test.
r4110
Martin von Zweigbergk
tests: rename "u" to more usual "ui" in test-context.py...
r42223 repo = hg.repository(ui, 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
Augie Fackler
formatting: blacken the codebase...
r43346
Martin Geisler
changelog: convert user and desc from local encoding early...
r14379 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
formatting: blacken the codebase...
r43346
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
Augie Fackler
formatting: blacken the codebase...
r43346
Sean Farley
test-context: add test for memctx status
r21836 def getfilectx(repo, memctx, f):
Martin von Zweigbergk
cleanup: use p1() and p2() instead of parents()[0] and parents()[1]...
r41442 fctx = memctx.p1()[f]
Sean Farley
test-context: add test for memctx status
r21836 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(
Augie Fackler
formatting: blacken the codebase...
r43346 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
formatting: blacken the codebase...
r43346 ctxb = context.memctx(
repo,
[ctxa.node(), None],
b"test diff",
[b"foo"],
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":')
Augie Fackler
formatting: blacken the codebase...
r43346 print(
actx1.status(other=wctx, 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)))
Augie Fackler
formatting: blacken the codebase...
r43346 print(
actx2.status(other=wctx, 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
Augie Fackler
formatting: blacken the codebase...
r43346 wcctx = context.workingcommitctx(
repo,
scmutil.status([b'bar-m'], [b'bar-a'], [], [], [], [], []),
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":')
Augie Fackler
formatting: blacken the codebase...
r43346 print(
actx1.status(
other=wcctx, 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)))
Augie Fackler
formatting: blacken the codebase...
r43346 print(
actx2.status(
other=wcctx, 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":')
Augie Fackler
formatting: blacken the codebase...
r43346 print(
actx1.status(
other=wcctx,
match=scmutil.matchfiles(repo, [b'bar-r', b'foo']),
listclean=True,
)
)
Robert Stanca
py3: lexicographical order imports and print_function in test-context.py
r28738 print('wcctx._status=%s' % (str(wcctx._status)))
Augie Fackler
formatting: blacken the codebase...
r43346 print(
actx2.status(
other=wcctx,
match=scmutil.matchfiles(repo, [b'bar-r', b'foo']),
listclean=True,
)
)
Robert Stanca
py3: lexicographical order imports and print_function in test-context.py
r28738 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')
Martin von Zweigbergk
tests: rename "u" to more usual "ui" in test-context.py...
r42223 repo = hg.repository(ui, 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], [], [], [], [], [])
Augie Fackler
formatting: blacken the codebase...
r43346 ctx = context.workingcommitctx(
repo, status, text=i, user=b'test@test.com', date=(0, 0)
)
ctx.p1().manifest() # side effect: cache manifestctx
Jun Wu
test-context: add a case demonstrating manifest caching problem...
r32518 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')
Augie Fackler
formatting: blacken the codebase...
r43346 repo.svfs.utime(
b'00manifest.i', (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()')