tests/test-context.py
author Sean Farley <sean.michael.farley@gmail.com>
Thu, 15 Aug 2013 16:49:27 -0500
changeset 21689 503bb3af70fe
parent 14379 bd23d5f28bbb
child 21836 232038a05fdb
permissions -rw-r--r--
memfilectx: call super.__init__ instead of duplicating code This patch changes the calling signature of memfilectx's __init__ to fall in line with the other file contexts. Calling code and tests have been updated accordingly.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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())