Mercurial > hg
comparison tests/test-context.py @ 28738:706f4ab710c8
py3: lexicographical order imports and print_function in test-context.py
author | Robert Stanca <robert.stanca7@gmail.com> |
---|---|
date | Sun, 03 Apr 2016 16:34:55 +0300 |
parents | 5edde05ff58e |
children | 67bff672ccc2 |
comparison
equal
deleted
inserted
replaced
28737:a3a01194a337 | 28738:706f4ab710c8 |
---|---|
1 from __future__ import absolute_import | 1 from __future__ import absolute_import, print_function |
2 import os | 2 import os |
3 from mercurial import ( | 3 from mercurial import ( |
4 context, | |
5 encoding, | |
4 hg, | 6 hg, |
5 ui, | 7 ui, |
6 context, | |
7 encoding, | |
8 ) | 8 ) |
9 | 9 |
10 u = ui.ui() | 10 u = ui.ui() |
11 | 11 |
12 repo = hg.repository(u, 'test1', create=1) | 12 repo = hg.repository(u, 'test1', create=1) |
22 repo[None].add(['foo']) | 22 repo[None].add(['foo']) |
23 repo.commit(text='commit1', date="0 0") | 23 repo.commit(text='commit1', date="0 0") |
24 | 24 |
25 if os.name == 'nt': | 25 if os.name == 'nt': |
26 d = repo[None]['foo'].date() | 26 d = repo[None]['foo'].date() |
27 print "workingfilectx.date = (%d, %d)" % (d[0], d[1]) | 27 print("workingfilectx.date = (%d, %d)" % (d[0], d[1])) |
28 else: | 28 else: |
29 print "workingfilectx.date =", repo[None]['foo'].date() | 29 print("workingfilectx.date =", repo[None]['foo'].date()) |
30 | 30 |
31 # test memctx with non-ASCII commit message | 31 # test memctx with non-ASCII commit message |
32 | 32 |
33 def filectxfn(repo, memctx, path): | 33 def filectxfn(repo, memctx, path): |
34 return context.memfilectx(repo, "foo", "") | 34 return context.memfilectx(repo, "foo", "") |
37 encoding.tolocal("Gr\xc3\xbcezi!"), | 37 encoding.tolocal("Gr\xc3\xbcezi!"), |
38 ["foo"], filectxfn) | 38 ["foo"], filectxfn) |
39 ctx.commit() | 39 ctx.commit() |
40 for enc in "ASCII", "Latin-1", "UTF-8": | 40 for enc in "ASCII", "Latin-1", "UTF-8": |
41 encoding.encoding = enc | 41 encoding.encoding = enc |
42 print "%-8s: %s" % (enc, repo["tip"].description()) | 42 print("%-8s: %s" % (enc, repo["tip"].description())) |
43 | 43 |
44 # test performing a status | 44 # test performing a status |
45 | 45 |
46 def getfilectx(repo, memctx, f): | 46 def getfilectx(repo, memctx, f): |
47 fctx = memctx.parents()[0][f] | 47 fctx = memctx.parents()[0][f] |
52 | 52 |
53 ctxa = repo.changectx(0) | 53 ctxa = repo.changectx(0) |
54 ctxb = context.memctx(repo, [ctxa.node(), None], "test diff", ["foo"], | 54 ctxb = context.memctx(repo, [ctxa.node(), None], "test diff", ["foo"], |
55 getfilectx, ctxa.user(), ctxa.date()) | 55 getfilectx, ctxa.user(), ctxa.date()) |
56 | 56 |
57 print ctxb.status(ctxa) | 57 print(ctxb.status(ctxa)) |
58 | 58 |
59 # test performing a diff on a memctx | 59 # test performing a diff on a memctx |
60 | 60 |
61 for d in ctxb.diff(ctxa, git=True): | 61 for d in ctxb.diff(ctxa, git=True): |
62 print d | 62 print(d) |
63 | 63 |
64 # test safeness and correctness of "ctx.status()" | 64 # test safeness and correctness of "ctx.status()" |
65 print '= checking context.status():' | 65 print('= checking context.status():') |
66 | 66 |
67 # ancestor "wcctx ~ 2" | 67 # ancestor "wcctx ~ 2" |
68 actx2 = repo['.'] | 68 actx2 = repo['.'] |
69 | 69 |
70 repo.wwrite('bar-m', 'bar-m\n', '') | 70 repo.wwrite('bar-m', 'bar-m\n', '') |
86 # R bar-r | 86 # R bar-r |
87 # C foo | 87 # C foo |
88 | 88 |
89 from mercurial import scmutil | 89 from mercurial import scmutil |
90 | 90 |
91 print '== checking workingctx.status:' | 91 print('== checking workingctx.status:') |
92 | 92 |
93 wctx = repo[None] | 93 wctx = repo[None] |
94 print 'wctx._status=%s' % (str(wctx._status)) | 94 print('wctx._status=%s' % (str(wctx._status))) |
95 | 95 |
96 print '=== with "pattern match":' | 96 print('=== with "pattern match":') |
97 print actx1.status(other=wctx, | 97 print(actx1.status(other=wctx, |
98 match=scmutil.matchfiles(repo, ['bar-m', 'foo'])) | 98 match=scmutil.matchfiles(repo, ['bar-m', 'foo']))) |
99 print 'wctx._status=%s' % (str(wctx._status)) | 99 print('wctx._status=%s' % (str(wctx._status))) |
100 print actx2.status(other=wctx, | 100 print(actx2.status(other=wctx, |
101 match=scmutil.matchfiles(repo, ['bar-m', 'foo'])) | 101 match=scmutil.matchfiles(repo, ['bar-m', 'foo']))) |
102 print 'wctx._status=%s' % (str(wctx._status)) | 102 print('wctx._status=%s' % (str(wctx._status))) |
103 | 103 |
104 print '=== with "always match" and "listclean=True":' | 104 print('=== with "always match" and "listclean=True":') |
105 print actx1.status(other=wctx, listclean=True) | 105 print(actx1.status(other=wctx, listclean=True)) |
106 print 'wctx._status=%s' % (str(wctx._status)) | 106 print('wctx._status=%s' % (str(wctx._status))) |
107 print actx2.status(other=wctx, listclean=True) | 107 print(actx2.status(other=wctx, listclean=True)) |
108 print 'wctx._status=%s' % (str(wctx._status)) | 108 print('wctx._status=%s' % (str(wctx._status))) |
109 | 109 |
110 print "== checking workingcommitctx.status:" | 110 print("== checking workingcommitctx.status:") |
111 | 111 |
112 wcctx = context.workingcommitctx(repo, | 112 wcctx = context.workingcommitctx(repo, |
113 scmutil.status(['bar-m'], | 113 scmutil.status(['bar-m'], |
114 ['bar-a'], | 114 ['bar-a'], |
115 [], | 115 [], |
116 [], [], [], []), | 116 [], [], [], []), |
117 text='', date='0 0') | 117 text='', date='0 0') |
118 print 'wcctx._status=%s' % (str(wcctx._status)) | 118 print('wcctx._status=%s' % (str(wcctx._status))) |
119 | 119 |
120 print '=== with "always match":' | 120 print('=== with "always match":') |
121 print actx1.status(other=wcctx) | 121 print(actx1.status(other=wcctx)) |
122 print 'wcctx._status=%s' % (str(wcctx._status)) | 122 print('wcctx._status=%s' % (str(wcctx._status))) |
123 print actx2.status(other=wcctx) | 123 print(actx2.status(other=wcctx)) |
124 print 'wcctx._status=%s' % (str(wcctx._status)) | 124 print('wcctx._status=%s' % (str(wcctx._status))) |
125 | 125 |
126 print '=== with "always match" and "listclean=True":' | 126 print('=== with "always match" and "listclean=True":') |
127 print actx1.status(other=wcctx, listclean=True) | 127 print(actx1.status(other=wcctx, listclean=True)) |
128 print 'wcctx._status=%s' % (str(wcctx._status)) | 128 print('wcctx._status=%s' % (str(wcctx._status))) |
129 print actx2.status(other=wcctx, listclean=True) | 129 print(actx2.status(other=wcctx, listclean=True)) |
130 print 'wcctx._status=%s' % (str(wcctx._status)) | 130 print('wcctx._status=%s' % (str(wcctx._status))) |
131 | 131 |
132 print '=== with "pattern match":' | 132 print('=== with "pattern match":') |
133 print actx1.status(other=wcctx, | 133 print(actx1.status(other=wcctx, |
134 match=scmutil.matchfiles(repo, ['bar-m', 'foo'])) | 134 match=scmutil.matchfiles(repo, ['bar-m', 'foo']))) |
135 print 'wcctx._status=%s' % (str(wcctx._status)) | 135 print('wcctx._status=%s' % (str(wcctx._status))) |
136 print actx2.status(other=wcctx, | 136 print(actx2.status(other=wcctx, |
137 match=scmutil.matchfiles(repo, ['bar-m', 'foo'])) | 137 match=scmutil.matchfiles(repo, ['bar-m', 'foo']))) |
138 print 'wcctx._status=%s' % (str(wcctx._status)) | 138 print('wcctx._status=%s' % (str(wcctx._status))) |
139 | 139 |
140 print '=== with "pattern match" and "listclean=True":' | 140 print('=== with "pattern match" and "listclean=True":') |
141 print actx1.status(other=wcctx, | 141 print(actx1.status(other=wcctx, |
142 match=scmutil.matchfiles(repo, ['bar-r', 'foo']), | 142 match=scmutil.matchfiles(repo, ['bar-r', 'foo']), |
143 listclean=True) | 143 listclean=True)) |
144 print 'wcctx._status=%s' % (str(wcctx._status)) | 144 print('wcctx._status=%s' % (str(wcctx._status))) |
145 print actx2.status(other=wcctx, | 145 print(actx2.status(other=wcctx, |
146 match=scmutil.matchfiles(repo, ['bar-r', 'foo']), | 146 match=scmutil.matchfiles(repo, ['bar-r', 'foo']), |
147 listclean=True) | 147 listclean=True)) |
148 print 'wcctx._status=%s' % (str(wcctx._status)) | 148 print('wcctx._status=%s' % (str(wcctx._status))) |