comparison tests/test-context.py @ 43076:2372284d9457

formatting: blacken the codebase This is using my patch to black (https://github.com/psf/black/pull/826) so we don't un-wrap collection literals. Done with: hg files 'set:**.py - mercurial/thirdparty/** - "contrib/python-zstandard/**"' | xargs black -S # skip-blame mass-reformatting only # no-check-commit reformats foo_bar functions Differential Revision: https://phab.mercurial-scm.org/D6971
author Augie Fackler <augie@google.com>
date Sun, 06 Oct 2019 09:45:02 -0400
parents 4950ae4d034f
children 03ef0c8fa7d5
comparison
equal deleted inserted replaced
43075:57875cf423c9 43076:2372284d9457
11 scmutil, 11 scmutil,
12 ui as uimod, 12 ui as uimod,
13 ) 13 )
14 14
15 print_ = print 15 print_ = print
16
17
16 def print(*args, **kwargs): 18 def print(*args, **kwargs):
17 """print() wrapper that flushes stdout buffers to avoid py3 buffer issues 19 """print() wrapper that flushes stdout buffers to avoid py3 buffer issues
18 20
19 We could also just write directly to sys.stdout.buffer the way the 21 We could also just write directly to sys.stdout.buffer the way the
20 ui object will, but this was easier for porting the test. 22 ui object will, but this was easier for porting the test.
21 """ 23 """
22 print_(*args, **kwargs) 24 print_(*args, **kwargs)
23 sys.stdout.flush() 25 sys.stdout.flush()
24 26
27
25 def printb(data, end=b'\n'): 28 def printb(data, end=b'\n'):
26 out = getattr(sys.stdout, 'buffer', sys.stdout) 29 out = getattr(sys.stdout, 'buffer', sys.stdout)
27 out.write(data + end) 30 out.write(data + end)
28 out.flush() 31 out.flush()
32
29 33
30 ui = uimod.ui.load() 34 ui = uimod.ui.load()
31 35
32 repo = hg.repository(ui, b'test1', create=1) 36 repo = hg.repository(ui, b'test1', create=1)
33 os.chdir('test1') 37 os.chdir('test1')
47 d = d[:2] 51 d = d[:2]
48 print("workingfilectx.date = (%d, %d)" % d) 52 print("workingfilectx.date = (%d, %d)" % d)
49 53
50 # test memctx with non-ASCII commit message 54 # test memctx with non-ASCII commit message
51 55
56
52 def filectxfn(repo, memctx, path): 57 def filectxfn(repo, memctx, path):
53 return context.memfilectx(repo, memctx, b"foo", b"") 58 return context.memfilectx(repo, memctx, b"foo", b"")
54 59
55 ctx = context.memctx(repo, [b'tip', None], 60
56 encoding.tolocal(b"Gr\xc3\xbcezi!"), 61 ctx = context.memctx(
57 [b"foo"], filectxfn) 62 repo,
63 [b'tip', None],
64 encoding.tolocal(b"Gr\xc3\xbcezi!"),
65 [b"foo"],
66 filectxfn,
67 )
58 ctx.commit() 68 ctx.commit()
59 for enc in "ASCII", "Latin-1", "UTF-8": 69 for enc in "ASCII", "Latin-1", "UTF-8":
60 encoding.encoding = enc 70 encoding.encoding = enc
61 printb(b"%-8s: %s" % (enc.encode('ascii'), repo[b"tip"].description())) 71 printb(b"%-8s: %s" % (enc.encode('ascii'), repo[b"tip"].description()))
62 72
63 # test performing a status 73 # test performing a status
74
64 75
65 def getfilectx(repo, memctx, f): 76 def getfilectx(repo, memctx, f):
66 fctx = memctx.p1()[f] 77 fctx = memctx.p1()[f]
67 data, flags = fctx.data(), fctx.flags() 78 data, flags = fctx.data(), fctx.flags()
68 if f == b'foo': 79 if f == b'foo':
69 data += b'bar\n' 80 data += b'bar\n'
70 return context.memfilectx( 81 return context.memfilectx(
71 repo, memctx, f, data, b'l' in flags, b'x' in flags) 82 repo, memctx, f, data, b'l' in flags, b'x' in flags
83 )
84
72 85
73 ctxa = repo[0] 86 ctxa = repo[0]
74 ctxb = context.memctx(repo, [ctxa.node(), None], b"test diff", [b"foo"], 87 ctxb = context.memctx(
75 getfilectx, ctxa.user(), ctxa.date()) 88 repo,
89 [ctxa.node(), None],
90 b"test diff",
91 [b"foo"],
92 getfilectx,
93 ctxa.user(),
94 ctxa.date(),
95 )
76 96
77 print(ctxb.status(ctxa)) 97 print(ctxb.status(ctxa))
78 98
79 # test performing a diff on a memctx 99 # test performing a diff on a memctx
80 diffopts = diffutil.diffallopts(repo.ui, {b'git': True}) 100 diffopts = diffutil.diffallopts(repo.ui, {b'git': True})
112 132
113 wctx = repo[None] 133 wctx = repo[None]
114 print('wctx._status=%s' % (str(wctx._status))) 134 print('wctx._status=%s' % (str(wctx._status)))
115 135
116 print('=== with "pattern match":') 136 print('=== with "pattern match":')
117 print(actx1.status(other=wctx, 137 print(
118 match=scmutil.matchfiles(repo, [b'bar-m', b'foo']))) 138 actx1.status(other=wctx, match=scmutil.matchfiles(repo, [b'bar-m', b'foo']))
119 print('wctx._status=%s' % (str(wctx._status))) 139 )
120 print(actx2.status(other=wctx, 140 print('wctx._status=%s' % (str(wctx._status)))
121 match=scmutil.matchfiles(repo, [b'bar-m', b'foo']))) 141 print(
142 actx2.status(other=wctx, match=scmutil.matchfiles(repo, [b'bar-m', b'foo']))
143 )
122 print('wctx._status=%s' % (str(wctx._status))) 144 print('wctx._status=%s' % (str(wctx._status)))
123 145
124 print('=== with "always match" and "listclean=True":') 146 print('=== with "always match" and "listclean=True":')
125 print(actx1.status(other=wctx, listclean=True)) 147 print(actx1.status(other=wctx, listclean=True))
126 print('wctx._status=%s' % (str(wctx._status))) 148 print('wctx._status=%s' % (str(wctx._status)))
127 print(actx2.status(other=wctx, listclean=True)) 149 print(actx2.status(other=wctx, listclean=True))
128 print('wctx._status=%s' % (str(wctx._status))) 150 print('wctx._status=%s' % (str(wctx._status)))
129 151
130 print("== checking workingcommitctx.status:") 152 print("== checking workingcommitctx.status:")
131 153
132 wcctx = context.workingcommitctx(repo, 154 wcctx = context.workingcommitctx(
133 scmutil.status([b'bar-m'], 155 repo,
134 [b'bar-a'], 156 scmutil.status([b'bar-m'], [b'bar-a'], [], [], [], [], []),
135 [], 157 text=b'',
136 [], [], [], []), 158 date=b'0 0',
137 text=b'', date=b'0 0') 159 )
138 print('wcctx._status=%s' % (str(wcctx._status))) 160 print('wcctx._status=%s' % (str(wcctx._status)))
139 161
140 print('=== with "always match":') 162 print('=== with "always match":')
141 print(actx1.status(other=wcctx)) 163 print(actx1.status(other=wcctx))
142 print('wcctx._status=%s' % (str(wcctx._status))) 164 print('wcctx._status=%s' % (str(wcctx._status)))
148 print('wcctx._status=%s' % (str(wcctx._status))) 170 print('wcctx._status=%s' % (str(wcctx._status)))
149 print(actx2.status(other=wcctx, listclean=True)) 171 print(actx2.status(other=wcctx, listclean=True))
150 print('wcctx._status=%s' % (str(wcctx._status))) 172 print('wcctx._status=%s' % (str(wcctx._status)))
151 173
152 print('=== with "pattern match":') 174 print('=== with "pattern match":')
153 print(actx1.status(other=wcctx, 175 print(
154 match=scmutil.matchfiles(repo, [b'bar-m', b'foo']))) 176 actx1.status(
155 print('wcctx._status=%s' % (str(wcctx._status))) 177 other=wcctx, match=scmutil.matchfiles(repo, [b'bar-m', b'foo'])
156 print(actx2.status(other=wcctx, 178 )
157 match=scmutil.matchfiles(repo, [b'bar-m', b'foo']))) 179 )
180 print('wcctx._status=%s' % (str(wcctx._status)))
181 print(
182 actx2.status(
183 other=wcctx, match=scmutil.matchfiles(repo, [b'bar-m', b'foo'])
184 )
185 )
158 print('wcctx._status=%s' % (str(wcctx._status))) 186 print('wcctx._status=%s' % (str(wcctx._status)))
159 187
160 print('=== with "pattern match" and "listclean=True":') 188 print('=== with "pattern match" and "listclean=True":')
161 print(actx1.status(other=wcctx, 189 print(
162 match=scmutil.matchfiles(repo, [b'bar-r', b'foo']), 190 actx1.status(
163 listclean=True)) 191 other=wcctx,
164 print('wcctx._status=%s' % (str(wcctx._status))) 192 match=scmutil.matchfiles(repo, [b'bar-r', b'foo']),
165 print(actx2.status(other=wcctx, 193 listclean=True,
166 match=scmutil.matchfiles(repo, [b'bar-r', b'foo']), 194 )
167 listclean=True)) 195 )
196 print('wcctx._status=%s' % (str(wcctx._status)))
197 print(
198 actx2.status(
199 other=wcctx,
200 match=scmutil.matchfiles(repo, [b'bar-r', b'foo']),
201 listclean=True,
202 )
203 )
168 print('wcctx._status=%s' % (str(wcctx._status))) 204 print('wcctx._status=%s' % (str(wcctx._status)))
169 205
170 os.chdir('..') 206 os.chdir('..')
171 207
172 # test manifestlog being changed 208 # test manifestlog being changed
178 # make some commits 214 # make some commits
179 for i in [b'1', b'2', b'3']: 215 for i in [b'1', b'2', b'3']:
180 with open(i, 'wb') as f: 216 with open(i, 'wb') as f:
181 f.write(i) 217 f.write(i)
182 status = scmutil.status([], [i], [], [], [], [], []) 218 status = scmutil.status([], [i], [], [], [], [], [])
183 ctx = context.workingcommitctx(repo, status, text=i, user=b'test@test.com', 219 ctx = context.workingcommitctx(
184 date=(0, 0)) 220 repo, status, text=i, user=b'test@test.com', date=(0, 0)
185 ctx.p1().manifest() # side effect: cache manifestctx 221 )
222 ctx.p1().manifest() # side effect: cache manifestctx
186 n = repo.commitctx(ctx) 223 n = repo.commitctx(ctx)
187 printb(b'commit %s: %s' % (i, hex(n))) 224 printb(b'commit %s: %s' % (i, hex(n)))
188 225
189 # touch 00manifest.i mtime so storecache could expire. 226 # touch 00manifest.i mtime so storecache could expire.
190 # repo.__dict__['manifestlog'] is deleted by transaction releasefn. 227 # repo.__dict__['manifestlog'] is deleted by transaction releasefn.
191 st = repo.svfs.stat(b'00manifest.i') 228 st = repo.svfs.stat(b'00manifest.i')
192 repo.svfs.utime(b'00manifest.i', 229 repo.svfs.utime(
193 (st[stat.ST_MTIME] + 1, st[stat.ST_MTIME] + 1)) 230 b'00manifest.i', (st[stat.ST_MTIME] + 1, st[stat.ST_MTIME] + 1)
231 )
194 232
195 # read the file just committed 233 # read the file just committed
196 try: 234 try:
197 if repo[n][i].data() != i: 235 if repo[n][i].data() != i:
198 print('data mismatch') 236 print('data mismatch')