Mercurial > hg
annotate tests/test-context.py @ 21977:4ca4e1572022
run-tests: '--time' option provide more details to Linux users
As our tests execute in child processes, this patch uses os.times()
module in replace of time.time() module to provide additional info like
user time and system time spent by child's processes along with real elapsed
time taken by a process.
There is one limitation of this patch. It can work only for Linux users and
not for Windows.
"os.times" module returns a 5-tuple of a floaing point numbers.
1) User time
2) System time
3) Child's user time
4) Child's system time
5) Ellapsed real time
On Windows, only the first two items are filled, the others are zero.
Therefore, below test cases does not break on Windows but instead gives the
zero value.
author | anuraggoel <anurag.dsps@gmail.com> |
---|---|
date | Thu, 26 Jun 2014 01:22:50 +0530 |
parents | 61b333b982ea |
children | 4eaea93b3e5b |
rev | line source |
---|---|
4110
20af6a2f0b0e
Fixed workingfilectx.date() (found by Thomas Waldmann) with test.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
1 import os |
14379
bd23d5f28bbb
changelog: convert user and desc from local encoding early
Martin Geisler <mg@aragost.com>
parents:
11303
diff
changeset
|
2 from mercurial import hg, ui, context, encoding |
4110
20af6a2f0b0e
Fixed workingfilectx.date() (found by Thomas Waldmann) with test.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
3 |
20af6a2f0b0e
Fixed workingfilectx.date() (found by Thomas Waldmann) with test.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
4 u = ui.ui() |
20af6a2f0b0e
Fixed workingfilectx.date() (found by Thomas Waldmann) with test.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
5 |
20af6a2f0b0e
Fixed workingfilectx.date() (found by Thomas Waldmann) with test.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
6 repo = hg.repository(u, 'test1', create=1) |
20af6a2f0b0e
Fixed workingfilectx.date() (found by Thomas Waldmann) with test.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
7 os.chdir('test1') |
20af6a2f0b0e
Fixed workingfilectx.date() (found by Thomas Waldmann) with test.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
8 |
20af6a2f0b0e
Fixed workingfilectx.date() (found by Thomas Waldmann) with test.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
9 # create 'foo' with fixed time stamp |
9031
3b76321aa0de
compat: use open() instead of file() everywhere
Alejandro Santos <alejolp@alejolp.com>
parents:
6747
diff
changeset
|
10 f = open('foo', 'w') |
4110
20af6a2f0b0e
Fixed workingfilectx.date() (found by Thomas Waldmann) with test.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
11 f.write('foo\n') |
20af6a2f0b0e
Fixed workingfilectx.date() (found by Thomas Waldmann) with test.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
12 f.close() |
20af6a2f0b0e
Fixed workingfilectx.date() (found by Thomas Waldmann) with test.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
13 os.utime('foo', (1000, 1000)) |
20af6a2f0b0e
Fixed workingfilectx.date() (found by Thomas Waldmann) with test.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
14 |
20af6a2f0b0e
Fixed workingfilectx.date() (found by Thomas Waldmann) with test.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
15 # add+commit 'foo' |
11303
a1aad8333864
move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9031
diff
changeset
|
16 repo[None].add(['foo']) |
4110
20af6a2f0b0e
Fixed workingfilectx.date() (found by Thomas Waldmann) with test.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
17 repo.commit(text='commit1', date="0 0") |
20af6a2f0b0e
Fixed workingfilectx.date() (found by Thomas Waldmann) with test.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff
changeset
|
18 |
6747
f6c00b17387c
use repo[changeid] to get a changectx
Matt Mackall <mpm@selenic.com>
parents:
6740
diff
changeset
|
19 print "workingfilectx.date =", repo[None]['foo'].date() |
14379
bd23d5f28bbb
changelog: convert user and desc from local encoding early
Martin Geisler <mg@aragost.com>
parents:
11303
diff
changeset
|
20 |
bd23d5f28bbb
changelog: convert user and desc from local encoding early
Martin Geisler <mg@aragost.com>
parents:
11303
diff
changeset
|
21 # test memctx with non-ASCII commit message |
bd23d5f28bbb
changelog: convert user and desc from local encoding early
Martin Geisler <mg@aragost.com>
parents:
11303
diff
changeset
|
22 |
bd23d5f28bbb
changelog: convert user and desc from local encoding early
Martin Geisler <mg@aragost.com>
parents:
11303
diff
changeset
|
23 def filectxfn(repo, memctx, path): |
21689
503bb3af70fe
memfilectx: call super.__init__ instead of duplicating code
Sean Farley <sean.michael.farley@gmail.com>
parents:
14379
diff
changeset
|
24 return context.memfilectx(repo, "foo", "") |
14379
bd23d5f28bbb
changelog: convert user and desc from local encoding early
Martin Geisler <mg@aragost.com>
parents:
11303
diff
changeset
|
25 |
bd23d5f28bbb
changelog: convert user and desc from local encoding early
Martin Geisler <mg@aragost.com>
parents:
11303
diff
changeset
|
26 ctx = context.memctx(repo, ['tip', None], |
bd23d5f28bbb
changelog: convert user and desc from local encoding early
Martin Geisler <mg@aragost.com>
parents:
11303
diff
changeset
|
27 encoding.tolocal("Gr\xc3\xbcezi!"), |
bd23d5f28bbb
changelog: convert user and desc from local encoding early
Martin Geisler <mg@aragost.com>
parents:
11303
diff
changeset
|
28 ["foo"], filectxfn) |
bd23d5f28bbb
changelog: convert user and desc from local encoding early
Martin Geisler <mg@aragost.com>
parents:
11303
diff
changeset
|
29 ctx.commit() |
bd23d5f28bbb
changelog: convert user and desc from local encoding early
Martin Geisler <mg@aragost.com>
parents:
11303
diff
changeset
|
30 for enc in "ASCII", "Latin-1", "UTF-8": |
bd23d5f28bbb
changelog: convert user and desc from local encoding early
Martin Geisler <mg@aragost.com>
parents:
11303
diff
changeset
|
31 encoding.encoding = enc |
bd23d5f28bbb
changelog: convert user and desc from local encoding early
Martin Geisler <mg@aragost.com>
parents:
11303
diff
changeset
|
32 print "%-8s: %s" % (enc, repo["tip"].description()) |
21836
232038a05fdb
test-context: add test for memctx status
Sean Farley <sean.michael.farley@gmail.com>
parents:
21689
diff
changeset
|
33 |
232038a05fdb
test-context: add test for memctx status
Sean Farley <sean.michael.farley@gmail.com>
parents:
21689
diff
changeset
|
34 # test performing a status |
232038a05fdb
test-context: add test for memctx status
Sean Farley <sean.michael.farley@gmail.com>
parents:
21689
diff
changeset
|
35 |
232038a05fdb
test-context: add test for memctx status
Sean Farley <sean.michael.farley@gmail.com>
parents:
21689
diff
changeset
|
36 def getfilectx(repo, memctx, f): |
232038a05fdb
test-context: add test for memctx status
Sean Farley <sean.michael.farley@gmail.com>
parents:
21689
diff
changeset
|
37 fctx = memctx.parents()[0][f] |
232038a05fdb
test-context: add test for memctx status
Sean Farley <sean.michael.farley@gmail.com>
parents:
21689
diff
changeset
|
38 data, flags = fctx.data(), fctx.flags() |
232038a05fdb
test-context: add test for memctx status
Sean Farley <sean.michael.farley@gmail.com>
parents:
21689
diff
changeset
|
39 if f == 'foo': |
232038a05fdb
test-context: add test for memctx status
Sean Farley <sean.michael.farley@gmail.com>
parents:
21689
diff
changeset
|
40 data += 'bar\n' |
232038a05fdb
test-context: add test for memctx status
Sean Farley <sean.michael.farley@gmail.com>
parents:
21689
diff
changeset
|
41 return context.memfilectx(repo, f, data, 'l' in flags, 'x' in flags) |
232038a05fdb
test-context: add test for memctx status
Sean Farley <sean.michael.farley@gmail.com>
parents:
21689
diff
changeset
|
42 |
232038a05fdb
test-context: add test for memctx status
Sean Farley <sean.michael.farley@gmail.com>
parents:
21689
diff
changeset
|
43 ctxa = repo.changectx(0) |
21837
61b333b982ea
test-context: add test for performing a diff on a memctx
Sean Farley <sean.michael.farley@gmail.com>
parents:
21836
diff
changeset
|
44 ctxb = context.memctx(repo, [ctxa.node(), None], "test diff", ["foo"], |
61b333b982ea
test-context: add test for performing a diff on a memctx
Sean Farley <sean.michael.farley@gmail.com>
parents:
21836
diff
changeset
|
45 getfilectx, ctxa.user(), ctxa.date()) |
21836
232038a05fdb
test-context: add test for memctx status
Sean Farley <sean.michael.farley@gmail.com>
parents:
21689
diff
changeset
|
46 |
232038a05fdb
test-context: add test for memctx status
Sean Farley <sean.michael.farley@gmail.com>
parents:
21689
diff
changeset
|
47 print ctxb.status(ctxa) |
21837
61b333b982ea
test-context: add test for performing a diff on a memctx
Sean Farley <sean.michael.farley@gmail.com>
parents:
21836
diff
changeset
|
48 |
61b333b982ea
test-context: add test for performing a diff on a memctx
Sean Farley <sean.michael.farley@gmail.com>
parents:
21836
diff
changeset
|
49 # test performing a diff on a memctx |
61b333b982ea
test-context: add test for performing a diff on a memctx
Sean Farley <sean.michael.farley@gmail.com>
parents:
21836
diff
changeset
|
50 |
61b333b982ea
test-context: add test for performing a diff on a memctx
Sean Farley <sean.michael.farley@gmail.com>
parents:
21836
diff
changeset
|
51 for d in ctxb.diff(ctxa, git=True): |
61b333b982ea
test-context: add test for performing a diff on a memctx
Sean Farley <sean.michael.farley@gmail.com>
parents:
21836
diff
changeset
|
52 print d |