##// END OF EJS Templates
tests: add missing b prefix in test-context.py...
Augie Fackler -
r38680:a75896bf default
parent child Browse files
Show More
@@ -1,211 +1,211 b''
1 1 from __future__ import absolute_import, print_function
2 2 import os
3 3 import stat
4 4 import sys
5 5 from mercurial.node import hex
6 6 from mercurial import (
7 7 context,
8 8 diffutil,
9 9 encoding,
10 10 hg,
11 11 scmutil,
12 12 ui as uimod,
13 13 )
14 14
15 15 print_ = print
16 16 def print(*args, **kwargs):
17 17 """print() wrapper that flushes stdout buffers to avoid py3 buffer issues
18 18
19 19 We could also just write directly to sys.stdout.buffer the way the
20 20 ui object will, but this was easier for porting the test.
21 21 """
22 22 print_(*args, **kwargs)
23 23 sys.stdout.flush()
24 24
25 25 def printb(data, end=b'\n'):
26 26 out = getattr(sys.stdout, 'buffer', sys.stdout)
27 27 out.write(data + end)
28 28 out.flush()
29 29
30 30 u = uimod.ui.load()
31 31
32 32 repo = hg.repository(u, b'test1', create=1)
33 33 os.chdir('test1')
34 34
35 35 # create 'foo' with fixed time stamp
36 36 f = open('foo', 'wb')
37 37 f.write(b'foo\n')
38 38 f.close()
39 39 os.utime('foo', (1000, 1000))
40 40
41 41 # add+commit 'foo'
42 42 repo[None].add([b'foo'])
43 43 repo.commit(text=b'commit1', date=b"0 0")
44 44
45 45 d = repo[None][b'foo'].date()
46 46 if os.name == 'nt':
47 47 d = d[:2]
48 48 print("workingfilectx.date = (%d, %d)" % d)
49 49
50 50 # test memctx with non-ASCII commit message
51 51
52 52 def filectxfn(repo, memctx, path):
53 53 return context.memfilectx(repo, memctx, b"foo", b"")
54 54
55 55 ctx = context.memctx(repo, [b'tip', None],
56 56 encoding.tolocal(b"Gr\xc3\xbcezi!"),
57 57 [b"foo"], filectxfn)
58 58 ctx.commit()
59 59 for enc in "ASCII", "Latin-1", "UTF-8":
60 60 encoding.encoding = enc
61 61 printb(b"%-8s: %s" % (enc.encode('ascii'), repo[b"tip"].description()))
62 62
63 63 # test performing a status
64 64
65 65 def getfilectx(repo, memctx, f):
66 66 fctx = memctx.parents()[0][f]
67 67 data, flags = fctx.data(), fctx.flags()
68 68 if f == b'foo':
69 69 data += b'bar\n'
70 70 return context.memfilectx(
71 71 repo, memctx, f, data, b'l' in flags, b'x' in flags)
72 72
73 73 ctxa = repo[0]
74 74 ctxb = context.memctx(repo, [ctxa.node(), None], b"test diff", [b"foo"],
75 75 getfilectx, ctxa.user(), ctxa.date())
76 76
77 77 print(ctxb.status(ctxa))
78 78
79 79 # test performing a diff on a memctx
80 diffopts = diffutil.diffallopts(repo.ui, {'git': True})
80 diffopts = diffutil.diffallopts(repo.ui, {b'git': True})
81 81 for d in ctxb.diff(ctxa, opts=diffopts):
82 82 printb(d, end=b'')
83 83
84 84 # test safeness and correctness of "ctx.status()"
85 85 print('= checking context.status():')
86 86
87 87 # ancestor "wcctx ~ 2"
88 88 actx2 = repo[b'.']
89 89
90 90 repo.wwrite(b'bar-m', b'bar-m\n', b'')
91 91 repo.wwrite(b'bar-r', b'bar-r\n', b'')
92 92 repo[None].add([b'bar-m', b'bar-r'])
93 93 repo.commit(text=b'add bar-m, bar-r', date=b"0 0")
94 94
95 95 # ancestor "wcctx ~ 1"
96 96 actx1 = repo[b'.']
97 97
98 98 repo.wwrite(b'bar-m', b'bar-m bar-m\n', b'')
99 99 repo.wwrite(b'bar-a', b'bar-a\n', b'')
100 100 repo[None].add([b'bar-a'])
101 101 repo[None].forget([b'bar-r'])
102 102
103 103 # status at this point:
104 104 # M bar-m
105 105 # A bar-a
106 106 # R bar-r
107 107 # C foo
108 108
109 109 from mercurial import scmutil
110 110
111 111 print('== checking workingctx.status:')
112 112
113 113 wctx = repo[None]
114 114 print('wctx._status=%s' % (str(wctx._status)))
115 115
116 116 print('=== with "pattern match":')
117 117 print(actx1.status(other=wctx,
118 118 match=scmutil.matchfiles(repo, [b'bar-m', b'foo'])))
119 119 print('wctx._status=%s' % (str(wctx._status)))
120 120 print(actx2.status(other=wctx,
121 121 match=scmutil.matchfiles(repo, [b'bar-m', b'foo'])))
122 122 print('wctx._status=%s' % (str(wctx._status)))
123 123
124 124 print('=== with "always match" and "listclean=True":')
125 125 print(actx1.status(other=wctx, listclean=True))
126 126 print('wctx._status=%s' % (str(wctx._status)))
127 127 print(actx2.status(other=wctx, listclean=True))
128 128 print('wctx._status=%s' % (str(wctx._status)))
129 129
130 130 print("== checking workingcommitctx.status:")
131 131
132 132 wcctx = context.workingcommitctx(repo,
133 133 scmutil.status([b'bar-m'],
134 134 [b'bar-a'],
135 135 [],
136 136 [], [], [], []),
137 137 text=b'', date=b'0 0')
138 138 print('wcctx._status=%s' % (str(wcctx._status)))
139 139
140 140 print('=== with "always match":')
141 141 print(actx1.status(other=wcctx))
142 142 print('wcctx._status=%s' % (str(wcctx._status)))
143 143 print(actx2.status(other=wcctx))
144 144 print('wcctx._status=%s' % (str(wcctx._status)))
145 145
146 146 print('=== with "always match" and "listclean=True":')
147 147 print(actx1.status(other=wcctx, listclean=True))
148 148 print('wcctx._status=%s' % (str(wcctx._status)))
149 149 print(actx2.status(other=wcctx, listclean=True))
150 150 print('wcctx._status=%s' % (str(wcctx._status)))
151 151
152 152 print('=== with "pattern match":')
153 153 print(actx1.status(other=wcctx,
154 154 match=scmutil.matchfiles(repo, [b'bar-m', b'foo'])))
155 155 print('wcctx._status=%s' % (str(wcctx._status)))
156 156 print(actx2.status(other=wcctx,
157 157 match=scmutil.matchfiles(repo, [b'bar-m', b'foo'])))
158 158 print('wcctx._status=%s' % (str(wcctx._status)))
159 159
160 160 print('=== with "pattern match" and "listclean=True":')
161 161 print(actx1.status(other=wcctx,
162 162 match=scmutil.matchfiles(repo, [b'bar-r', b'foo']),
163 163 listclean=True))
164 164 print('wcctx._status=%s' % (str(wcctx._status)))
165 165 print(actx2.status(other=wcctx,
166 166 match=scmutil.matchfiles(repo, [b'bar-r', b'foo']),
167 167 listclean=True))
168 168 print('wcctx._status=%s' % (str(wcctx._status)))
169 169
170 170 os.chdir('..')
171 171
172 172 # test manifestlog being changed
173 173 print('== commit with manifestlog invalidated')
174 174
175 175 repo = hg.repository(u, b'test2', create=1)
176 176 os.chdir('test2')
177 177
178 178 # make some commits
179 179 for i in [b'1', b'2', b'3']:
180 180 with open(i, 'wb') as f:
181 181 f.write(i)
182 182 status = scmutil.status([], [i], [], [], [], [], [])
183 183 ctx = context.workingcommitctx(repo, status, text=i, user=b'test@test.com',
184 184 date=(0, 0))
185 185 ctx.p1().manifest() # side effect: cache manifestctx
186 186 n = repo.commitctx(ctx)
187 187 printb(b'commit %s: %s' % (i, hex(n)))
188 188
189 189 # touch 00manifest.i mtime so storecache could expire.
190 190 # repo.__dict__['manifestlog'] is deleted by transaction releasefn.
191 191 st = repo.svfs.stat(b'00manifest.i')
192 192 repo.svfs.utime(b'00manifest.i',
193 193 (st[stat.ST_MTIME] + 1, st[stat.ST_MTIME] + 1))
194 194
195 195 # read the file just committed
196 196 try:
197 197 if repo[n][i].data() != i:
198 198 print('data mismatch')
199 199 except Exception as ex:
200 200 print('cannot read data: %r' % ex)
201 201
202 202 with repo.wlock(), repo.lock(), repo.transaction(b'test'):
203 203 with open(b'4', 'wb') as f:
204 204 f.write(b'4')
205 205 repo.dirstate.normal(b'4')
206 206 repo.commit(b'4')
207 207 revsbefore = len(repo.changelog)
208 208 repo.invalidate(clearfilecache=True)
209 209 revsafter = len(repo.changelog)
210 210 if revsbefore != revsafter:
211 211 print('changeset lost by repo.invalidate()')
General Comments 0
You need to be logged in to leave comments. Login now