tests/test-parseindex
author Alexis S. L. Carvalho <alexis@cecm.usp.br>
Mon, 16 Apr 2007 20:17:39 -0300
changeset 4363 2e3c54fb79a3
parent 3853 c0b449154a90
child 6750 fb42030d79d6
permissions -rwxr-xr-x
actually port simplemerge to hg - use bdiff instead of patiencediff; this is a larger change, since bdiff works on 2 multi-line strings, while patiencediff works on 2 lists; - rename the main class from Merge3 to Merge3Text and add a Merge3 class that derives from Merge3Text. This new Merge3 class has the same interface from the original class, so that the tests still work; - Merge3 uses util.binary to detect binary data and raises util.Abort instead of a specific exception; - don't use the @decorator syntax, to keep python2.3 compatibility; - the test uses unittest, which likes to print how long it took to run. This obviously doesn't play too well with hg's test suite, so we override time.time to fool unittest; - one test has a different (but still valid) output because of the different diff algorithm used; - the TestCase class used by bzr has some extras to help debugging. test-merge3.py used 2 of them: - log method to log some data - assertEqualDiff method to ease viewing diffs of diffs We add a dummy log method and use regular assertEquals instead of assertEqualDiff. - make simplemerge executable and add "#!/usr/bin/env python" header
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2290
6563438219e3 add test for revlog.parseindex
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
     1
#!/bin/sh
6563438219e3 add test for revlog.parseindex
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
     2
#
6563438219e3 add test for revlog.parseindex
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
     3
# revlog.parseindex must be able to parse the index file even if
6563438219e3 add test for revlog.parseindex
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
     4
# an index entry is split between two 64k blocks.  The ideal test
6563438219e3 add test for revlog.parseindex
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
     5
# would be to create an index file with inline data where
6563438219e3 add test for revlog.parseindex
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
     6
# 64k < size < 64k + 64 (64k is the size of the read buffer, 64 is
6563438219e3 add test for revlog.parseindex
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
     7
# the size of an index entry) and with an index entry starting right
6563438219e3 add test for revlog.parseindex
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
     8
# before the 64k block boundary, and try to read it.
6563438219e3 add test for revlog.parseindex
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
     9
#
6563438219e3 add test for revlog.parseindex
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    10
# We approximate that by reducing the read buffer to 1 byte.
6563438219e3 add test for revlog.parseindex
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    11
#
6563438219e3 add test for revlog.parseindex
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    12
6563438219e3 add test for revlog.parseindex
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    13
hg init a
6563438219e3 add test for revlog.parseindex
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    14
cd a
6563438219e3 add test for revlog.parseindex
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    15
echo abc > foo
6563438219e3 add test for revlog.parseindex
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    16
hg add foo
6563438219e3 add test for revlog.parseindex
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    17
hg commit -m 'add foo' -d '1000000 0'
6563438219e3 add test for revlog.parseindex
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    18
6563438219e3 add test for revlog.parseindex
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    19
echo >> foo
6563438219e3 add test for revlog.parseindex
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    20
hg commit -m 'change foo' -d '1000001 0'
6563438219e3 add test for revlog.parseindex
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    21
hg log -r 0:
6563438219e3 add test for revlog.parseindex
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    22
6563438219e3 add test for revlog.parseindex
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    23
cat >> test.py << EOF
6563438219e3 add test for revlog.parseindex
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    24
from mercurial import changelog, util
6563438219e3 add test for revlog.parseindex
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    25
from mercurial.node import *
6563438219e3 add test for revlog.parseindex
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    26
6563438219e3 add test for revlog.parseindex
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    27
class singlebyteread(object):
6563438219e3 add test for revlog.parseindex
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    28
    def __init__(self, real):
6563438219e3 add test for revlog.parseindex
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    29
        self.real = real
6563438219e3 add test for revlog.parseindex
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    30
6563438219e3 add test for revlog.parseindex
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    31
    def read(self, size=-1):
6563438219e3 add test for revlog.parseindex
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    32
        if size == 65536:
6563438219e3 add test for revlog.parseindex
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    33
            size = 1
6563438219e3 add test for revlog.parseindex
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    34
        return self.real.read(size)
6563438219e3 add test for revlog.parseindex
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    35
6563438219e3 add test for revlog.parseindex
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    36
    def __getattr__(self, key):
6563438219e3 add test for revlog.parseindex
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    37
        return getattr(self.real, key)
6563438219e3 add test for revlog.parseindex
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    38
6563438219e3 add test for revlog.parseindex
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    39
def opener(*args):
6563438219e3 add test for revlog.parseindex
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    40
    o = util.opener(*args)
6563438219e3 add test for revlog.parseindex
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    41
    def wrapper(*a):
6563438219e3 add test for revlog.parseindex
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    42
        f = o(*a)
6563438219e3 add test for revlog.parseindex
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    43
        return singlebyteread(f)
6563438219e3 add test for revlog.parseindex
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    44
    return wrapper
6563438219e3 add test for revlog.parseindex
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    45
3853
c0b449154a90 switch to the .hg/store layout, fix the tests
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 2290
diff changeset
    46
cl = changelog.changelog(opener('.hg/store'))
2290
6563438219e3 add test for revlog.parseindex
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    47
print cl.count(), 'revisions:'
6563438219e3 add test for revlog.parseindex
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    48
for r in xrange(cl.count()):
6563438219e3 add test for revlog.parseindex
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    49
    print short(cl.node(r))
6563438219e3 add test for revlog.parseindex
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    50
EOF
6563438219e3 add test for revlog.parseindex
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    51
6563438219e3 add test for revlog.parseindex
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    52
python test.py