##// END OF EJS Templates
tests: alias ui as uimod in test-context
Yuya Nishihara -
r28775:67bff672 default
parent child Browse files
Show More
@@ -1,148 +1,148 b''
1 from __future__ import absolute_import, print_function
1 from __future__ import absolute_import, print_function
2 import os
2 import os
3 from mercurial import (
3 from mercurial import (
4 context,
4 context,
5 encoding,
5 encoding,
6 hg,
6 hg,
7 ui,
7 ui as uimod,
8 )
8 )
9
9
10 u = ui.ui()
10 u = uimod.ui()
11
11
12 repo = hg.repository(u, 'test1', create=1)
12 repo = hg.repository(u, 'test1', create=1)
13 os.chdir('test1')
13 os.chdir('test1')
14
14
15 # create 'foo' with fixed time stamp
15 # create 'foo' with fixed time stamp
16 f = open('foo', 'wb')
16 f = open('foo', 'wb')
17 f.write('foo\n')
17 f.write('foo\n')
18 f.close()
18 f.close()
19 os.utime('foo', (1000, 1000))
19 os.utime('foo', (1000, 1000))
20
20
21 # add+commit 'foo'
21 # add+commit 'foo'
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", "")
35
35
36 ctx = context.memctx(repo, ['tip', None],
36 ctx = context.memctx(repo, ['tip', None],
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]
48 data, flags = fctx.data(), fctx.flags()
48 data, flags = fctx.data(), fctx.flags()
49 if f == 'foo':
49 if f == 'foo':
50 data += 'bar\n'
50 data += 'bar\n'
51 return context.memfilectx(repo, f, data, 'l' in flags, 'x' in flags)
51 return context.memfilectx(repo, f, data, 'l' in flags, 'x' in flags)
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', '')
71 repo.wwrite('bar-r', 'bar-r\n', '')
71 repo.wwrite('bar-r', 'bar-r\n', '')
72 repo[None].add(['bar-m', 'bar-r'])
72 repo[None].add(['bar-m', 'bar-r'])
73 repo.commit(text='add bar-m, bar-r', date="0 0")
73 repo.commit(text='add bar-m, bar-r', date="0 0")
74
74
75 # ancestor "wcctx ~ 1"
75 # ancestor "wcctx ~ 1"
76 actx1 = repo['.']
76 actx1 = repo['.']
77
77
78 repo.wwrite('bar-m', 'bar-m bar-m\n', '')
78 repo.wwrite('bar-m', 'bar-m bar-m\n', '')
79 repo.wwrite('bar-a', 'bar-a\n', '')
79 repo.wwrite('bar-a', 'bar-a\n', '')
80 repo[None].add(['bar-a'])
80 repo[None].add(['bar-a'])
81 repo[None].forget(['bar-r'])
81 repo[None].forget(['bar-r'])
82
82
83 # status at this point:
83 # status at this point:
84 # M bar-m
84 # M bar-m
85 # A bar-a
85 # A bar-a
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)))
General Comments 0
You need to be logged in to leave comments. Login now