mercurial/testing/storage.py
author Gregory Szorc <gregory.szorc@gmail.com>
Tue, 16 Oct 2018 15:24:06 +0200
changeset 40322 ddeb510d6815
parent 40056 324b4b10351e
child 40323 2c0aa02ecd5a
permissions -rw-r--r--
testing: remove expectation of error on bad node insert addgroup() doesn't necessarily validate the hashes of each incoming revision. This is an optimization that allows delta group application to complete faster. The fact that revlog raises in this particular test is an implementation detail due to the way revlogs are testing multiple deltas. Differential Revision: https://phab.mercurial-scm.org/D5115
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
39772
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     1
# storage.py - Testing of storage primitives.
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     2
#
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     3
# Copyright 2018 Gregory Szorc <gregory.szorc@gmail.com>
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     4
#
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     5
# This software may be used and distributed according to the terms of the
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     6
# GNU General Public License version 2 or any later version.
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     7
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     8
from __future__ import absolute_import
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     9
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    10
import unittest
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    11
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    12
from ..node import (
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    13
    hex,
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    14
    nullid,
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    15
    nullrev,
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    16
)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    17
from .. import (
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    18
    error,
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    19
    mdiff,
40047
8e398628a3f2 repository: define and use revision flag constants
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40003
diff changeset
    20
    repository,
39772
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    21
)
39878
3e896b51aa5d storageutil: move metadata parsing and packing from revlog (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39876
diff changeset
    22
from ..utils import (
3e896b51aa5d storageutil: move metadata parsing and packing from revlog (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39876
diff changeset
    23
    storageutil,
3e896b51aa5d storageutil: move metadata parsing and packing from revlog (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39876
diff changeset
    24
)
39772
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    25
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    26
class basetestcase(unittest.TestCase):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    27
    if not getattr(unittest.TestCase, r'assertRaisesRegex', False):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    28
        assertRaisesRegex = (# camelcase-required
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    29
            unittest.TestCase.assertRaisesRegexp)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    30
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    31
class ifileindextests(basetestcase):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    32
    """Generic tests for the ifileindex interface.
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    33
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    34
    All file storage backends for index data should conform to the tests in this
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    35
    class.
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    36
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    37
    Use ``makeifileindextests()`` to create an instance of this type.
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    38
    """
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    39
    def testempty(self):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    40
        f = self._makefilefn()
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    41
        self.assertEqual(len(f), 0, 'new file store has 0 length by default')
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    42
        self.assertEqual(list(f), [], 'iter yields nothing by default')
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    43
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    44
        gen = iter(f)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    45
        with self.assertRaises(StopIteration):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    46
            next(gen)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    47
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    48
        # revs() should evaluate to an empty list.
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    49
        self.assertEqual(list(f.revs()), [])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    50
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    51
        revs = iter(f.revs())
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    52
        with self.assertRaises(StopIteration):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    53
            next(revs)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    54
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    55
        self.assertEqual(list(f.revs(start=20)), [])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    56
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    57
        # parents() and parentrevs() work with nullid/nullrev.
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    58
        self.assertEqual(f.parents(nullid), (nullid, nullid))
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    59
        self.assertEqual(f.parentrevs(nullrev), (nullrev, nullrev))
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    60
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    61
        with self.assertRaises(error.LookupError):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    62
            f.parents(b'\x01' * 20)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    63
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    64
        for i in range(-5, 5):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    65
            if i == nullrev:
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    66
                continue
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    67
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    68
            with self.assertRaises(IndexError):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    69
                f.parentrevs(i)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    70
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    71
        # nullid/nullrev lookup always works.
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    72
        self.assertEqual(f.rev(nullid), nullrev)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    73
        self.assertEqual(f.node(nullrev), nullid)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    74
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    75
        with self.assertRaises(error.LookupError):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    76
            f.rev(b'\x01' * 20)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    77
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    78
        for i in range(-5, 5):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    79
            if i == nullrev:
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    80
                continue
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    81
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    82
            with self.assertRaises(IndexError):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    83
                f.node(i)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    84
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    85
        self.assertEqual(f.lookup(nullid), nullid)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    86
        self.assertEqual(f.lookup(nullrev), nullid)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    87
        self.assertEqual(f.lookup(hex(nullid)), nullid)
40002
0e8836be9541 storageutil: implement file identifier resolution method (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40001
diff changeset
    88
        self.assertEqual(f.lookup(b'%d' % nullrev), nullid)
39772
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    89
40001
215fd73cfe52 testing: add more testing for ifileindex.lookup()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39998
diff changeset
    90
        with self.assertRaises(error.LookupError):
215fd73cfe52 testing: add more testing for ifileindex.lookup()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39998
diff changeset
    91
            f.lookup(b'badvalue')
215fd73cfe52 testing: add more testing for ifileindex.lookup()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39998
diff changeset
    92
40002
0e8836be9541 storageutil: implement file identifier resolution method (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40001
diff changeset
    93
        with self.assertRaises(error.LookupError):
0e8836be9541 storageutil: implement file identifier resolution method (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40001
diff changeset
    94
            f.lookup(hex(nullid)[0:12])
40001
215fd73cfe52 testing: add more testing for ifileindex.lookup()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39998
diff changeset
    95
215fd73cfe52 testing: add more testing for ifileindex.lookup()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39998
diff changeset
    96
        with self.assertRaises(error.LookupError):
215fd73cfe52 testing: add more testing for ifileindex.lookup()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39998
diff changeset
    97
            f.lookup(b'-2')
215fd73cfe52 testing: add more testing for ifileindex.lookup()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39998
diff changeset
    98
40002
0e8836be9541 storageutil: implement file identifier resolution method (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40001
diff changeset
    99
        with self.assertRaises(error.LookupError):
0e8836be9541 storageutil: implement file identifier resolution method (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40001
diff changeset
   100
            f.lookup(b'0')
40001
215fd73cfe52 testing: add more testing for ifileindex.lookup()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39998
diff changeset
   101
215fd73cfe52 testing: add more testing for ifileindex.lookup()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39998
diff changeset
   102
        with self.assertRaises(error.LookupError):
215fd73cfe52 testing: add more testing for ifileindex.lookup()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39998
diff changeset
   103
            f.lookup(b'1')
215fd73cfe52 testing: add more testing for ifileindex.lookup()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39998
diff changeset
   104
215fd73cfe52 testing: add more testing for ifileindex.lookup()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39998
diff changeset
   105
        with self.assertRaises(error.LookupError):
215fd73cfe52 testing: add more testing for ifileindex.lookup()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39998
diff changeset
   106
            f.lookup(b'11111111111111111111111111111111111111')
215fd73cfe52 testing: add more testing for ifileindex.lookup()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39998
diff changeset
   107
215fd73cfe52 testing: add more testing for ifileindex.lookup()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39998
diff changeset
   108
        for i in range(-5, 5):
215fd73cfe52 testing: add more testing for ifileindex.lookup()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39998
diff changeset
   109
            if i == nullrev:
215fd73cfe52 testing: add more testing for ifileindex.lookup()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39998
diff changeset
   110
                continue
215fd73cfe52 testing: add more testing for ifileindex.lookup()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39998
diff changeset
   111
215fd73cfe52 testing: add more testing for ifileindex.lookup()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39998
diff changeset
   112
            with self.assertRaises(LookupError):
215fd73cfe52 testing: add more testing for ifileindex.lookup()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39998
diff changeset
   113
                f.lookup(i)
215fd73cfe52 testing: add more testing for ifileindex.lookup()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39998
diff changeset
   114
39772
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   115
        self.assertEqual(f.linkrev(nullrev), nullrev)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   116
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   117
        for i in range(-5, 5):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   118
            if i == nullrev:
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   119
                continue
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   120
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   121
            with self.assertRaises(IndexError):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   122
                f.linkrev(i)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   123
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   124
        self.assertFalse(f.iscensored(nullrev))
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   125
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   126
        for i in range(-5, 5):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   127
            if i == nullrev:
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   128
                continue
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   129
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   130
            with self.assertRaises(IndexError):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   131
                f.iscensored(i)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   132
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   133
        self.assertEqual(list(f.commonancestorsheads(nullid, nullid)), [])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   134
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   135
        with self.assertRaises(ValueError):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   136
            self.assertEqual(list(f.descendants([])), [])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   137
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   138
        self.assertEqual(list(f.descendants([nullrev])), [])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   139
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   140
        self.assertEqual(f.heads(), [nullid])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   141
        self.assertEqual(f.heads(nullid), [nullid])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   142
        self.assertEqual(f.heads(None, [nullid]), [nullid])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   143
        self.assertEqual(f.heads(nullid, [nullid]), [nullid])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   144
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   145
        self.assertEqual(f.children(nullid), [])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   146
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   147
        with self.assertRaises(error.LookupError):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   148
            f.children(b'\x01' * 20)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   149
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   150
    def testsinglerevision(self):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   151
        f = self._makefilefn()
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   152
        with self._maketransactionfn() as tr:
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   153
            node = f.add(b'initial', None, tr, 0, nullid, nullid)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   154
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   155
        self.assertEqual(len(f), 1)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   156
        self.assertEqual(list(f), [0])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   157
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   158
        gen = iter(f)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   159
        self.assertEqual(next(gen), 0)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   160
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   161
        with self.assertRaises(StopIteration):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   162
            next(gen)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   163
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   164
        self.assertEqual(list(f.revs()), [0])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   165
        self.assertEqual(list(f.revs(start=1)), [])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   166
        self.assertEqual(list(f.revs(start=0)), [0])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   167
        self.assertEqual(list(f.revs(stop=0)), [0])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   168
        self.assertEqual(list(f.revs(stop=1)), [0])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   169
        self.assertEqual(list(f.revs(1, 1)), [])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   170
        # TODO buggy
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   171
        self.assertEqual(list(f.revs(1, 0)), [1, 0])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   172
        self.assertEqual(list(f.revs(2, 0)), [2, 1, 0])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   173
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   174
        self.assertEqual(f.parents(node), (nullid, nullid))
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   175
        self.assertEqual(f.parentrevs(0), (nullrev, nullrev))
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   176
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   177
        with self.assertRaises(error.LookupError):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   178
            f.parents(b'\x01' * 20)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   179
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   180
        with self.assertRaises(IndexError):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   181
            f.parentrevs(1)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   182
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   183
        self.assertEqual(f.rev(node), 0)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   184
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   185
        with self.assertRaises(error.LookupError):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   186
            f.rev(b'\x01' * 20)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   187
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   188
        self.assertEqual(f.node(0), node)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   189
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   190
        with self.assertRaises(IndexError):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   191
            f.node(1)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   192
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   193
        self.assertEqual(f.lookup(node), node)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   194
        self.assertEqual(f.lookup(0), node)
40001
215fd73cfe52 testing: add more testing for ifileindex.lookup()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39998
diff changeset
   195
        self.assertEqual(f.lookup(-1), nullid)
39772
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   196
        self.assertEqual(f.lookup(b'0'), node)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   197
        self.assertEqual(f.lookup(hex(node)), node)
40002
0e8836be9541 storageutil: implement file identifier resolution method (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40001
diff changeset
   198
0e8836be9541 storageutil: implement file identifier resolution method (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40001
diff changeset
   199
        with self.assertRaises(error.LookupError):
0e8836be9541 storageutil: implement file identifier resolution method (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40001
diff changeset
   200
            f.lookup(hex(node)[0:12])
40001
215fd73cfe52 testing: add more testing for ifileindex.lookup()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39998
diff changeset
   201
40003
ad8389ecd3f5 storageutil: consistently raise LookupError (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40002
diff changeset
   202
        with self.assertRaises(error.LookupError):
40001
215fd73cfe52 testing: add more testing for ifileindex.lookup()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39998
diff changeset
   203
            f.lookup(-2)
215fd73cfe52 testing: add more testing for ifileindex.lookup()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39998
diff changeset
   204
215fd73cfe52 testing: add more testing for ifileindex.lookup()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39998
diff changeset
   205
        with self.assertRaises(error.LookupError):
215fd73cfe52 testing: add more testing for ifileindex.lookup()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39998
diff changeset
   206
            f.lookup(b'-2')
215fd73cfe52 testing: add more testing for ifileindex.lookup()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39998
diff changeset
   207
40003
ad8389ecd3f5 storageutil: consistently raise LookupError (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40002
diff changeset
   208
        with self.assertRaises(error.LookupError):
40001
215fd73cfe52 testing: add more testing for ifileindex.lookup()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39998
diff changeset
   209
            f.lookup(1)
215fd73cfe52 testing: add more testing for ifileindex.lookup()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39998
diff changeset
   210
215fd73cfe52 testing: add more testing for ifileindex.lookup()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39998
diff changeset
   211
        with self.assertRaises(error.LookupError):
215fd73cfe52 testing: add more testing for ifileindex.lookup()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39998
diff changeset
   212
            f.lookup(b'1')
39772
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   213
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   214
        self.assertEqual(f.linkrev(0), 0)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   215
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   216
        with self.assertRaises(IndexError):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   217
            f.linkrev(1)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   218
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   219
        self.assertFalse(f.iscensored(0))
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   220
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   221
        with self.assertRaises(IndexError):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   222
            f.iscensored(1)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   223
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   224
        self.assertEqual(list(f.descendants([0])), [])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   225
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   226
        self.assertEqual(f.heads(), [node])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   227
        self.assertEqual(f.heads(node), [node])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   228
        self.assertEqual(f.heads(stop=[node]), [node])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   229
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   230
        with self.assertRaises(error.LookupError):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   231
            f.heads(stop=[b'\x01' * 20])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   232
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   233
        self.assertEqual(f.children(node), [])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   234
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   235
    def testmultiplerevisions(self):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   236
        fulltext0 = b'x' * 1024
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   237
        fulltext1 = fulltext0 + b'y'
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   238
        fulltext2 = b'y' + fulltext0 + b'z'
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   239
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   240
        f = self._makefilefn()
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   241
        with self._maketransactionfn() as tr:
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   242
            node0 = f.add(fulltext0, None, tr, 0, nullid, nullid)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   243
            node1 = f.add(fulltext1, None, tr, 1, node0, nullid)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   244
            node2 = f.add(fulltext2, None, tr, 3, node1, nullid)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   245
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   246
        self.assertEqual(len(f), 3)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   247
        self.assertEqual(list(f), [0, 1, 2])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   248
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   249
        gen = iter(f)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   250
        self.assertEqual(next(gen), 0)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   251
        self.assertEqual(next(gen), 1)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   252
        self.assertEqual(next(gen), 2)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   253
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   254
        with self.assertRaises(StopIteration):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   255
            next(gen)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   256
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   257
        self.assertEqual(list(f.revs()), [0, 1, 2])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   258
        self.assertEqual(list(f.revs(0)), [0, 1, 2])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   259
        self.assertEqual(list(f.revs(1)), [1, 2])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   260
        self.assertEqual(list(f.revs(2)), [2])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   261
        self.assertEqual(list(f.revs(3)), [])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   262
        self.assertEqual(list(f.revs(stop=1)), [0, 1])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   263
        self.assertEqual(list(f.revs(stop=2)), [0, 1, 2])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   264
        self.assertEqual(list(f.revs(stop=3)), [0, 1, 2])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   265
        self.assertEqual(list(f.revs(2, 0)), [2, 1, 0])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   266
        self.assertEqual(list(f.revs(2, 1)), [2, 1])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   267
        # TODO this is wrong
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   268
        self.assertEqual(list(f.revs(3, 2)), [3, 2])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   269
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   270
        self.assertEqual(f.parents(node0), (nullid, nullid))
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   271
        self.assertEqual(f.parents(node1), (node0, nullid))
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   272
        self.assertEqual(f.parents(node2), (node1, nullid))
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   273
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   274
        self.assertEqual(f.parentrevs(0), (nullrev, nullrev))
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   275
        self.assertEqual(f.parentrevs(1), (0, nullrev))
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   276
        self.assertEqual(f.parentrevs(2), (1, nullrev))
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   277
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   278
        self.assertEqual(f.rev(node0), 0)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   279
        self.assertEqual(f.rev(node1), 1)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   280
        self.assertEqual(f.rev(node2), 2)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   281
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   282
        with self.assertRaises(error.LookupError):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   283
            f.rev(b'\x01' * 20)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   284
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   285
        self.assertEqual(f.node(0), node0)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   286
        self.assertEqual(f.node(1), node1)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   287
        self.assertEqual(f.node(2), node2)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   288
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   289
        with self.assertRaises(IndexError):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   290
            f.node(3)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   291
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   292
        self.assertEqual(f.lookup(node0), node0)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   293
        self.assertEqual(f.lookup(0), node0)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   294
        self.assertEqual(f.lookup(b'0'), node0)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   295
        self.assertEqual(f.lookup(hex(node0)), node0)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   296
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   297
        self.assertEqual(f.lookup(node1), node1)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   298
        self.assertEqual(f.lookup(1), node1)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   299
        self.assertEqual(f.lookup(b'1'), node1)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   300
        self.assertEqual(f.lookup(hex(node1)), node1)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   301
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   302
        self.assertEqual(f.linkrev(0), 0)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   303
        self.assertEqual(f.linkrev(1), 1)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   304
        self.assertEqual(f.linkrev(2), 3)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   305
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   306
        with self.assertRaises(IndexError):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   307
            f.linkrev(3)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   308
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   309
        self.assertFalse(f.iscensored(0))
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   310
        self.assertFalse(f.iscensored(1))
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   311
        self.assertFalse(f.iscensored(2))
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   312
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   313
        with self.assertRaises(IndexError):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   314
            f.iscensored(3)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   315
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   316
        self.assertEqual(f.commonancestorsheads(node1, nullid), [])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   317
        self.assertEqual(f.commonancestorsheads(node1, node0), [node0])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   318
        self.assertEqual(f.commonancestorsheads(node1, node1), [node1])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   319
        self.assertEqual(f.commonancestorsheads(node0, node1), [node0])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   320
        self.assertEqual(f.commonancestorsheads(node1, node2), [node1])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   321
        self.assertEqual(f.commonancestorsheads(node2, node1), [node1])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   322
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   323
        self.assertEqual(list(f.descendants([0])), [1, 2])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   324
        self.assertEqual(list(f.descendants([1])), [2])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   325
        self.assertEqual(list(f.descendants([0, 1])), [1, 2])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   326
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   327
        self.assertEqual(f.heads(), [node2])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   328
        self.assertEqual(f.heads(node0), [node2])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   329
        self.assertEqual(f.heads(node1), [node2])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   330
        self.assertEqual(f.heads(node2), [node2])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   331
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   332
        # TODO this behavior seems wonky. Is it correct? If so, the
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   333
        # docstring for heads() should be updated to reflect desired
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   334
        # behavior.
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   335
        self.assertEqual(f.heads(stop=[node1]), [node1, node2])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   336
        self.assertEqual(f.heads(stop=[node0]), [node0, node2])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   337
        self.assertEqual(f.heads(stop=[node1, node2]), [node1, node2])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   338
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   339
        with self.assertRaises(error.LookupError):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   340
            f.heads(stop=[b'\x01' * 20])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   341
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   342
        self.assertEqual(f.children(node0), [node1])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   343
        self.assertEqual(f.children(node1), [node2])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   344
        self.assertEqual(f.children(node2), [])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   345
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   346
    def testmultipleheads(self):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   347
        f = self._makefilefn()
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   348
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   349
        with self._maketransactionfn() as tr:
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   350
            node0 = f.add(b'0', None, tr, 0, nullid, nullid)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   351
            node1 = f.add(b'1', None, tr, 1, node0, nullid)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   352
            node2 = f.add(b'2', None, tr, 2, node1, nullid)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   353
            node3 = f.add(b'3', None, tr, 3, node0, nullid)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   354
            node4 = f.add(b'4', None, tr, 4, node3, nullid)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   355
            node5 = f.add(b'5', None, tr, 5, node0, nullid)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   356
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   357
        self.assertEqual(len(f), 6)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   358
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   359
        self.assertEqual(list(f.descendants([0])), [1, 2, 3, 4, 5])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   360
        self.assertEqual(list(f.descendants([1])), [2])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   361
        self.assertEqual(list(f.descendants([2])), [])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   362
        self.assertEqual(list(f.descendants([3])), [4])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   363
        self.assertEqual(list(f.descendants([0, 1])), [1, 2, 3, 4, 5])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   364
        self.assertEqual(list(f.descendants([1, 3])), [2, 4])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   365
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   366
        self.assertEqual(f.heads(), [node2, node4, node5])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   367
        self.assertEqual(f.heads(node0), [node2, node4, node5])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   368
        self.assertEqual(f.heads(node1), [node2])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   369
        self.assertEqual(f.heads(node2), [node2])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   370
        self.assertEqual(f.heads(node3), [node4])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   371
        self.assertEqual(f.heads(node4), [node4])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   372
        self.assertEqual(f.heads(node5), [node5])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   373
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   374
        # TODO this seems wrong.
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   375
        self.assertEqual(f.heads(stop=[node0]), [node0, node2, node4, node5])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   376
        self.assertEqual(f.heads(stop=[node1]), [node1, node2, node4, node5])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   377
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   378
        self.assertEqual(f.children(node0), [node1, node3, node5])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   379
        self.assertEqual(f.children(node1), [node2])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   380
        self.assertEqual(f.children(node2), [])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   381
        self.assertEqual(f.children(node3), [node4])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   382
        self.assertEqual(f.children(node4), [])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   383
        self.assertEqual(f.children(node5), [])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   384
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   385
class ifiledatatests(basetestcase):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   386
    """Generic tests for the ifiledata interface.
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   387
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   388
    All file storage backends for data should conform to the tests in this
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   389
    class.
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   390
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   391
    Use ``makeifiledatatests()`` to create an instance of this type.
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   392
    """
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   393
    def testempty(self):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   394
        f = self._makefilefn()
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   395
39869
14e500b58263 revlog: add method for obtaining storage info (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39866
diff changeset
   396
        self.assertEqual(f.storageinfo(), {})
14e500b58263 revlog: add method for obtaining storage info (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39866
diff changeset
   397
        self.assertEqual(f.storageinfo(revisionscount=True, trackedsize=True),
14e500b58263 revlog: add method for obtaining storage info (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39866
diff changeset
   398
                         {'revisionscount': 0, 'trackedsize': 0})
14e500b58263 revlog: add method for obtaining storage info (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39866
diff changeset
   399
39772
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   400
        self.assertEqual(f.size(nullrev), 0)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   401
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   402
        for i in range(-5, 5):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   403
            if i == nullrev:
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   404
                continue
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   405
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   406
            with self.assertRaises(IndexError):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   407
                f.size(i)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   408
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   409
        self.assertEqual(f.revision(nullid), b'')
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   410
        self.assertEqual(f.revision(nullid, raw=True), b'')
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   411
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   412
        with self.assertRaises(error.LookupError):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   413
            f.revision(b'\x01' * 20)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   414
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   415
        self.assertEqual(f.read(nullid), b'')
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   416
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   417
        with self.assertRaises(error.LookupError):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   418
            f.read(b'\x01' * 20)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   419
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   420
        self.assertFalse(f.renamed(nullid))
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   421
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   422
        with self.assertRaises(error.LookupError):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   423
            f.read(b'\x01' * 20)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   424
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   425
        self.assertTrue(f.cmp(nullid, b''))
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   426
        self.assertTrue(f.cmp(nullid, b'foo'))
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   427
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   428
        with self.assertRaises(error.LookupError):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   429
            f.cmp(b'\x01' * 20, b'irrelevant')
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   430
39862
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   431
        # Emitting empty list is an empty generator.
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   432
        gen = f.emitrevisions([])
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   433
        with self.assertRaises(StopIteration):
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   434
            next(gen)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   435
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   436
        # Emitting null node yields nothing.
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   437
        gen = f.emitrevisions([nullid])
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   438
        with self.assertRaises(StopIteration):
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   439
            next(gen)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   440
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   441
        # Requesting unknown node fails.
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   442
        with self.assertRaises(error.LookupError):
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   443
            list(f.emitrevisions([b'\x01' * 20]))
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   444
39772
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   445
    def testsinglerevision(self):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   446
        fulltext = b'initial'
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   447
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   448
        f = self._makefilefn()
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   449
        with self._maketransactionfn() as tr:
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   450
            node = f.add(fulltext, None, tr, 0, nullid, nullid)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   451
39869
14e500b58263 revlog: add method for obtaining storage info (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39866
diff changeset
   452
        self.assertEqual(f.storageinfo(), {})
14e500b58263 revlog: add method for obtaining storage info (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39866
diff changeset
   453
        self.assertEqual(f.storageinfo(revisionscount=True, trackedsize=True),
14e500b58263 revlog: add method for obtaining storage info (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39866
diff changeset
   454
                         {'revisionscount': 1, 'trackedsize': len(fulltext)})
14e500b58263 revlog: add method for obtaining storage info (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39866
diff changeset
   455
39772
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   456
        self.assertEqual(f.size(0), len(fulltext))
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   457
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   458
        with self.assertRaises(IndexError):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   459
            f.size(1)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   460
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   461
        self.assertEqual(f.revision(node), fulltext)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   462
        self.assertEqual(f.revision(node, raw=True), fulltext)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   463
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   464
        self.assertEqual(f.read(node), fulltext)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   465
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   466
        self.assertFalse(f.renamed(node))
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   467
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   468
        self.assertFalse(f.cmp(node, fulltext))
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   469
        self.assertTrue(f.cmp(node, fulltext + b'extra'))
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   470
39862
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   471
        # Emitting a single revision works.
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   472
        gen = f.emitrevisions([node])
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   473
        rev = next(gen)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   474
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   475
        self.assertEqual(rev.node, node)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   476
        self.assertEqual(rev.p1node, nullid)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   477
        self.assertEqual(rev.p2node, nullid)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   478
        self.assertIsNone(rev.linknode)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   479
        self.assertEqual(rev.basenode, nullid)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   480
        self.assertIsNone(rev.baserevisionsize)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   481
        self.assertIsNone(rev.revision)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   482
        self.assertIsNone(rev.delta)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   483
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   484
        with self.assertRaises(StopIteration):
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   485
            next(gen)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   486
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   487
        # Requesting revision data works.
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   488
        gen = f.emitrevisions([node], revisiondata=True)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   489
        rev = next(gen)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   490
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   491
        self.assertEqual(rev.node, node)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   492
        self.assertEqual(rev.p1node, nullid)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   493
        self.assertEqual(rev.p2node, nullid)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   494
        self.assertIsNone(rev.linknode)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   495
        self.assertEqual(rev.basenode, nullid)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   496
        self.assertIsNone(rev.baserevisionsize)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   497
        self.assertEqual(rev.revision, fulltext)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   498
        self.assertIsNone(rev.delta)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   499
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   500
        with self.assertRaises(StopIteration):
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   501
            next(gen)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   502
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   503
        # Emitting an unknown node after a known revision results in error.
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   504
        with self.assertRaises(error.LookupError):
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   505
            list(f.emitrevisions([node, b'\x01' * 20]))
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   506
39772
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   507
    def testmultiplerevisions(self):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   508
        fulltext0 = b'x' * 1024
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   509
        fulltext1 = fulltext0 + b'y'
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   510
        fulltext2 = b'y' + fulltext0 + b'z'
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   511
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   512
        f = self._makefilefn()
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   513
        with self._maketransactionfn() as tr:
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   514
            node0 = f.add(fulltext0, None, tr, 0, nullid, nullid)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   515
            node1 = f.add(fulltext1, None, tr, 1, node0, nullid)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   516
            node2 = f.add(fulltext2, None, tr, 3, node1, nullid)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   517
39869
14e500b58263 revlog: add method for obtaining storage info (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39866
diff changeset
   518
        self.assertEqual(f.storageinfo(), {})
14e500b58263 revlog: add method for obtaining storage info (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39866
diff changeset
   519
        self.assertEqual(
14e500b58263 revlog: add method for obtaining storage info (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39866
diff changeset
   520
            f.storageinfo(revisionscount=True, trackedsize=True),
14e500b58263 revlog: add method for obtaining storage info (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39866
diff changeset
   521
            {
14e500b58263 revlog: add method for obtaining storage info (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39866
diff changeset
   522
                'revisionscount': 3,
14e500b58263 revlog: add method for obtaining storage info (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39866
diff changeset
   523
                'trackedsize': len(fulltext0) + len(fulltext1) + len(fulltext2),
14e500b58263 revlog: add method for obtaining storage info (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39866
diff changeset
   524
            })
14e500b58263 revlog: add method for obtaining storage info (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39866
diff changeset
   525
39772
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   526
        self.assertEqual(f.size(0), len(fulltext0))
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   527
        self.assertEqual(f.size(1), len(fulltext1))
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   528
        self.assertEqual(f.size(2), len(fulltext2))
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   529
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   530
        with self.assertRaises(IndexError):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   531
            f.size(3)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   532
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   533
        self.assertEqual(f.revision(node0), fulltext0)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   534
        self.assertEqual(f.revision(node0, raw=True), fulltext0)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   535
        self.assertEqual(f.revision(node1), fulltext1)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   536
        self.assertEqual(f.revision(node1, raw=True), fulltext1)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   537
        self.assertEqual(f.revision(node2), fulltext2)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   538
        self.assertEqual(f.revision(node2, raw=True), fulltext2)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   539
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   540
        with self.assertRaises(error.LookupError):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   541
            f.revision(b'\x01' * 20)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   542
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   543
        self.assertEqual(f.read(node0), fulltext0)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   544
        self.assertEqual(f.read(node1), fulltext1)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   545
        self.assertEqual(f.read(node2), fulltext2)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   546
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   547
        with self.assertRaises(error.LookupError):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   548
            f.read(b'\x01' * 20)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   549
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   550
        self.assertFalse(f.renamed(node0))
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   551
        self.assertFalse(f.renamed(node1))
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   552
        self.assertFalse(f.renamed(node2))
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   553
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   554
        with self.assertRaises(error.LookupError):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   555
            f.renamed(b'\x01' * 20)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   556
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   557
        self.assertFalse(f.cmp(node0, fulltext0))
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   558
        self.assertFalse(f.cmp(node1, fulltext1))
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   559
        self.assertFalse(f.cmp(node2, fulltext2))
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   560
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   561
        self.assertTrue(f.cmp(node1, fulltext0))
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   562
        self.assertTrue(f.cmp(node2, fulltext1))
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   563
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   564
        with self.assertRaises(error.LookupError):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   565
            f.cmp(b'\x01' * 20, b'irrelevant')
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   566
39862
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   567
        # Nodes should be emitted in order.
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   568
        gen = f.emitrevisions([node0, node1, node2], revisiondata=True)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   569
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   570
        rev = next(gen)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   571
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   572
        self.assertEqual(rev.node, node0)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   573
        self.assertEqual(rev.p1node, nullid)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   574
        self.assertEqual(rev.p2node, nullid)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   575
        self.assertIsNone(rev.linknode)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   576
        self.assertEqual(rev.basenode, nullid)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   577
        self.assertIsNone(rev.baserevisionsize)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   578
        self.assertEqual(rev.revision, fulltext0)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   579
        self.assertIsNone(rev.delta)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   580
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   581
        rev = next(gen)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   582
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   583
        self.assertEqual(rev.node, node1)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   584
        self.assertEqual(rev.p1node, node0)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   585
        self.assertEqual(rev.p2node, nullid)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   586
        self.assertIsNone(rev.linknode)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   587
        self.assertEqual(rev.basenode, node0)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   588
        self.assertIsNone(rev.baserevisionsize)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   589
        self.assertIsNone(rev.revision)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   590
        self.assertEqual(rev.delta,
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   591
                         b'\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x04\x01' +
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   592
                         fulltext1)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   593
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   594
        rev = next(gen)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   595
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   596
        self.assertEqual(rev.node, node2)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   597
        self.assertEqual(rev.p1node, node1)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   598
        self.assertEqual(rev.p2node, nullid)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   599
        self.assertIsNone(rev.linknode)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   600
        self.assertEqual(rev.basenode, node1)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   601
        self.assertIsNone(rev.baserevisionsize)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   602
        self.assertIsNone(rev.revision)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   603
        self.assertEqual(rev.delta,
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   604
                         b'\x00\x00\x00\x00\x00\x00\x04\x01\x00\x00\x04\x02' +
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   605
                         fulltext2)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   606
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   607
        with self.assertRaises(StopIteration):
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   608
            next(gen)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   609
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   610
        # Request not in DAG order is reordered to be in DAG order.
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   611
        gen = f.emitrevisions([node2, node1, node0], revisiondata=True)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   612
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   613
        rev = next(gen)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   614
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   615
        self.assertEqual(rev.node, node0)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   616
        self.assertEqual(rev.p1node, nullid)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   617
        self.assertEqual(rev.p2node, nullid)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   618
        self.assertIsNone(rev.linknode)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   619
        self.assertEqual(rev.basenode, nullid)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   620
        self.assertIsNone(rev.baserevisionsize)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   621
        self.assertEqual(rev.revision, fulltext0)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   622
        self.assertIsNone(rev.delta)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   623
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   624
        rev = next(gen)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   625
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   626
        self.assertEqual(rev.node, node1)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   627
        self.assertEqual(rev.p1node, node0)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   628
        self.assertEqual(rev.p2node, nullid)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   629
        self.assertIsNone(rev.linknode)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   630
        self.assertEqual(rev.basenode, node0)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   631
        self.assertIsNone(rev.baserevisionsize)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   632
        self.assertIsNone(rev.revision)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   633
        self.assertEqual(rev.delta,
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   634
                         b'\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x04\x01' +
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   635
                         fulltext1)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   636
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   637
        rev = next(gen)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   638
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   639
        self.assertEqual(rev.node, node2)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   640
        self.assertEqual(rev.p1node, node1)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   641
        self.assertEqual(rev.p2node, nullid)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   642
        self.assertIsNone(rev.linknode)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   643
        self.assertEqual(rev.basenode, node1)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   644
        self.assertIsNone(rev.baserevisionsize)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   645
        self.assertIsNone(rev.revision)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   646
        self.assertEqual(rev.delta,
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   647
                         b'\x00\x00\x00\x00\x00\x00\x04\x01\x00\x00\x04\x02' +
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   648
                         fulltext2)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   649
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   650
        with self.assertRaises(StopIteration):
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   651
            next(gen)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   652
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   653
        # Unrecognized nodesorder value raises ProgrammingError.
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   654
        with self.assertRaises(error.ProgrammingError):
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   655
            list(f.emitrevisions([], nodesorder='bad'))
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   656
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   657
        # nodesorder=storage is recognized. But we can't test it thoroughly
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   658
        # because behavior is storage-dependent.
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   659
        res = list(f.emitrevisions([node2, node1, node0],
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   660
                                         nodesorder='storage'))
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   661
        self.assertEqual(len(res), 3)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   662
        self.assertEqual({o.node for o in res}, {node0, node1, node2})
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   663
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   664
        # nodesorder=nodes forces the order.
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   665
        gen = f.emitrevisions([node2, node0], nodesorder='nodes',
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   666
                              revisiondata=True)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   667
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   668
        rev = next(gen)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   669
        self.assertEqual(rev.node, node2)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   670
        self.assertEqual(rev.p1node, node1)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   671
        self.assertEqual(rev.p2node, nullid)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   672
        self.assertEqual(rev.basenode, nullid)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   673
        self.assertIsNone(rev.baserevisionsize)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   674
        self.assertEqual(rev.revision, fulltext2)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   675
        self.assertIsNone(rev.delta)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   676
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   677
        rev = next(gen)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   678
        self.assertEqual(rev.node, node0)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   679
        self.assertEqual(rev.p1node, nullid)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   680
        self.assertEqual(rev.p2node, nullid)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   681
        # Delta behavior is storage dependent, so we can't easily test it.
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   682
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   683
        with self.assertRaises(StopIteration):
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   684
            next(gen)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   685
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   686
        # assumehaveparentrevisions=False (the default) won't send a delta for
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   687
        # the first revision.
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   688
        gen = f.emitrevisions({node2, node1}, revisiondata=True)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   689
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   690
        rev = next(gen)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   691
        self.assertEqual(rev.node, node1)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   692
        self.assertEqual(rev.p1node, node0)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   693
        self.assertEqual(rev.p2node, nullid)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   694
        self.assertEqual(rev.basenode, nullid)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   695
        self.assertIsNone(rev.baserevisionsize)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   696
        self.assertEqual(rev.revision, fulltext1)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   697
        self.assertIsNone(rev.delta)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   698
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   699
        rev = next(gen)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   700
        self.assertEqual(rev.node, node2)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   701
        self.assertEqual(rev.p1node, node1)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   702
        self.assertEqual(rev.p2node, nullid)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   703
        self.assertEqual(rev.basenode, node1)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   704
        self.assertIsNone(rev.baserevisionsize)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   705
        self.assertIsNone(rev.revision)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   706
        self.assertEqual(rev.delta,
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   707
                         b'\x00\x00\x00\x00\x00\x00\x04\x01\x00\x00\x04\x02' +
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   708
                         fulltext2)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   709
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   710
        with self.assertRaises(StopIteration):
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   711
            next(gen)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   712
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   713
        # assumehaveparentrevisions=True allows delta against initial revision.
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   714
        gen = f.emitrevisions([node2, node1],
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   715
                              revisiondata=True, assumehaveparentrevisions=True)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   716
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   717
        rev = next(gen)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   718
        self.assertEqual(rev.node, node1)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   719
        self.assertEqual(rev.p1node, node0)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   720
        self.assertEqual(rev.p2node, nullid)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   721
        self.assertEqual(rev.basenode, node0)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   722
        self.assertIsNone(rev.baserevisionsize)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   723
        self.assertIsNone(rev.revision)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   724
        self.assertEqual(rev.delta,
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   725
                         b'\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x04\x01' +
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   726
                         fulltext1)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   727
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   728
        # forceprevious=True forces a delta against the previous revision.
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   729
        # Special case for initial revision.
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   730
        gen = f.emitrevisions([node0], revisiondata=True, deltaprevious=True)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   731
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   732
        rev = next(gen)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   733
        self.assertEqual(rev.node, node0)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   734
        self.assertEqual(rev.p1node, nullid)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   735
        self.assertEqual(rev.p2node, nullid)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   736
        self.assertEqual(rev.basenode, nullid)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   737
        self.assertIsNone(rev.baserevisionsize)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   738
        self.assertIsNone(rev.revision)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   739
        self.assertEqual(rev.delta,
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   740
                         b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00' +
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   741
                         fulltext0)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   742
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   743
        with self.assertRaises(StopIteration):
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   744
            next(gen)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   745
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   746
        gen = f.emitrevisions([node0, node2], revisiondata=True,
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   747
                              deltaprevious=True)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   748
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   749
        rev = next(gen)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   750
        self.assertEqual(rev.node, node0)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   751
        self.assertEqual(rev.p1node, nullid)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   752
        self.assertEqual(rev.p2node, nullid)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   753
        self.assertEqual(rev.basenode, nullid)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   754
        self.assertIsNone(rev.baserevisionsize)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   755
        self.assertIsNone(rev.revision)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   756
        self.assertEqual(rev.delta,
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   757
                         b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00' +
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   758
                         fulltext0)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   759
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   760
        rev = next(gen)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   761
        self.assertEqual(rev.node, node2)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   762
        self.assertEqual(rev.p1node, node1)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   763
        self.assertEqual(rev.p2node, nullid)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   764
        self.assertEqual(rev.basenode, node0)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   765
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   766
        with self.assertRaises(StopIteration):
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   767
            next(gen)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
   768
39772
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   769
    def testrenamed(self):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   770
        fulltext0 = b'foo'
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   771
        fulltext1 = b'bar'
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   772
        fulltext2 = b'baz'
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   773
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   774
        meta1 = {
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   775
            b'copy': b'source0',
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   776
            b'copyrev': b'a' * 40,
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   777
        }
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   778
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   779
        meta2 = {
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   780
            b'copy': b'source1',
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   781
            b'copyrev': b'b' * 40,
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   782
        }
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   783
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   784
        stored1 = b''.join([
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   785
            b'\x01\ncopy: source0\n',
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   786
            b'copyrev: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n\x01\n',
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   787
            fulltext1,
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   788
        ])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   789
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   790
        stored2 = b''.join([
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   791
            b'\x01\ncopy: source1\n',
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   792
            b'copyrev: bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\n\x01\n',
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   793
            fulltext2,
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   794
        ])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   795
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   796
        f = self._makefilefn()
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   797
        with self._maketransactionfn() as tr:
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   798
            node0 = f.add(fulltext0, None, tr, 0, nullid, nullid)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   799
            node1 = f.add(fulltext1, meta1, tr, 1, node0, nullid)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   800
            node2 = f.add(fulltext2, meta2, tr, 2, nullid, nullid)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   801
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   802
        # Metadata header isn't recognized when parent isn't nullid.
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   803
        self.assertEqual(f.size(1), len(stored1))
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   804
        self.assertEqual(f.size(2), len(fulltext2))
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   805
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   806
        self.assertEqual(f.revision(node1), stored1)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   807
        self.assertEqual(f.revision(node1, raw=True), stored1)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   808
        self.assertEqual(f.revision(node2), stored2)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   809
        self.assertEqual(f.revision(node2, raw=True), stored2)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   810
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   811
        self.assertEqual(f.read(node1), fulltext1)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   812
        self.assertEqual(f.read(node2), fulltext2)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   813
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   814
        # Returns False when first parent is set.
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   815
        self.assertFalse(f.renamed(node1))
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   816
        self.assertEqual(f.renamed(node2), (b'source1', b'\xbb' * 20))
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   817
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   818
        self.assertTrue(f.cmp(node1, fulltext1))
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   819
        self.assertTrue(f.cmp(node1, stored1))
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   820
        self.assertFalse(f.cmp(node2, fulltext2))
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   821
        self.assertTrue(f.cmp(node2, stored2))
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   822
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   823
    def testmetadataprefix(self):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   824
        # Content with metadata prefix has extra prefix inserted in storage.
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   825
        fulltext0 = b'\x01\nfoo'
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   826
        stored0 = b'\x01\n\x01\n\x01\nfoo'
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   827
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   828
        fulltext1 = b'\x01\nbar'
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   829
        meta1 = {
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   830
            b'copy': b'source0',
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   831
            b'copyrev': b'b' * 40,
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   832
        }
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   833
        stored1 = b''.join([
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   834
            b'\x01\ncopy: source0\n',
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   835
            b'copyrev: %s\n' % (b'b' * 40),
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   836
            b'\x01\n\x01\nbar',
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   837
        ])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   838
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   839
        f = self._makefilefn()
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   840
        with self._maketransactionfn() as tr:
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   841
            node0 = f.add(fulltext0, {}, tr, 0, nullid, nullid)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   842
            node1 = f.add(fulltext1, meta1, tr, 1, nullid, nullid)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   843
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   844
        # TODO this is buggy.
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   845
        self.assertEqual(f.size(0), len(fulltext0) + 4)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   846
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   847
        self.assertEqual(f.size(1), len(fulltext1))
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   848
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   849
        self.assertEqual(f.revision(node0), stored0)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   850
        self.assertEqual(f.revision(node0, raw=True), stored0)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   851
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   852
        self.assertEqual(f.revision(node1), stored1)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   853
        self.assertEqual(f.revision(node1, raw=True), stored1)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   854
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   855
        self.assertEqual(f.read(node0), fulltext0)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   856
        self.assertEqual(f.read(node1), fulltext1)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   857
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   858
        self.assertFalse(f.cmp(node0, fulltext0))
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   859
        self.assertTrue(f.cmp(node0, stored0))
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   860
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   861
        self.assertFalse(f.cmp(node1, fulltext1))
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   862
        self.assertTrue(f.cmp(node1, stored0))
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   863
40051
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   864
    def testbadnoderead(self):
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   865
        f = self._makefilefn()
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   866
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   867
        fulltext0 = b'foo\n' * 30
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   868
        fulltext1 = fulltext0 + b'bar\n'
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   869
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   870
        with self._maketransactionfn() as tr:
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   871
            node0 = f.add(fulltext0, None, tr, 0, nullid, nullid)
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   872
            node1 = b'\xaa' * 20
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   873
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   874
            self._addrawrevisionfn(f, tr, node1, node0, nullid, 1,
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   875
                                   rawtext=fulltext1)
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   876
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   877
        self.assertEqual(len(f), 2)
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   878
        self.assertEqual(f.parents(node1), (node0, nullid))
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   879
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   880
        # revision() raises since it performs hash verification.
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   881
        with self.assertRaises(error.StorageError):
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   882
            f.revision(node1)
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   883
40054
801ccd8e67c0 revlog: clear revision cache on hash verification failure
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40051
diff changeset
   884
        # raw=True still verifies because there are no special storage
801ccd8e67c0 revlog: clear revision cache on hash verification failure
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40051
diff changeset
   885
        # settings.
801ccd8e67c0 revlog: clear revision cache on hash verification failure
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40051
diff changeset
   886
        with self.assertRaises(error.StorageError):
801ccd8e67c0 revlog: clear revision cache on hash verification failure
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40051
diff changeset
   887
            f.revision(node1, raw=True)
40051
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   888
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   889
        # read() behaves like revision().
40054
801ccd8e67c0 revlog: clear revision cache on hash verification failure
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40051
diff changeset
   890
        with self.assertRaises(error.StorageError):
801ccd8e67c0 revlog: clear revision cache on hash verification failure
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40051
diff changeset
   891
            f.read(node1)
40051
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   892
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   893
        # We can't test renamed() here because some backends may not require
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   894
        # reading/validating the fulltext to return rename metadata.
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   895
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   896
    def testbadnoderevisionraw(self):
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   897
        # Like above except we test revision(raw=True) first to isolate
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   898
        # revision caching behavior.
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   899
        f = self._makefilefn()
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   900
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   901
        fulltext0 = b'foo\n' * 30
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   902
        fulltext1 = fulltext0 + b'bar\n'
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   903
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   904
        with self._maketransactionfn() as tr:
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   905
            node0 = f.add(fulltext0, None, tr, 0, nullid, nullid)
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   906
            node1 = b'\xaa' * 20
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   907
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   908
            self._addrawrevisionfn(f, tr, node1, node0, nullid, 1,
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   909
                                   rawtext=fulltext1)
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   910
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   911
        with self.assertRaises(error.StorageError):
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   912
            f.revision(node1, raw=True)
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   913
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   914
        with self.assertRaises(error.StorageError):
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   915
            f.revision(node1, raw=True)
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   916
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   917
    def testbadnoderevisionraw(self):
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   918
        # Like above except we test read() first to isolate revision caching
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   919
        # behavior.
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   920
        f = self._makefilefn()
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   921
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   922
        fulltext0 = b'foo\n' * 30
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   923
        fulltext1 = fulltext0 + b'bar\n'
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   924
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   925
        with self._maketransactionfn() as tr:
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   926
            node0 = f.add(fulltext0, None, tr, 0, nullid, nullid)
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   927
            node1 = b'\xaa' * 20
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   928
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   929
            self._addrawrevisionfn(f, tr, node1, node0, nullid, 1,
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   930
                                   rawtext=fulltext1)
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   931
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   932
        with self.assertRaises(error.StorageError):
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   933
            f.read(node1)
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   934
40054
801ccd8e67c0 revlog: clear revision cache on hash verification failure
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40051
diff changeset
   935
        with self.assertRaises(error.StorageError):
801ccd8e67c0 revlog: clear revision cache on hash verification failure
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40051
diff changeset
   936
            f.read(node1)
40051
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   937
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   938
    def testbadnodedelta(self):
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   939
        f = self._makefilefn()
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   940
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   941
        fulltext0 = b'foo\n' * 31
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   942
        fulltext1 = fulltext0 + b'bar\n'
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   943
        fulltext2 = fulltext1 + b'baz\n'
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   944
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   945
        with self._maketransactionfn() as tr:
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   946
            node0 = f.add(fulltext0, None, tr, 0, nullid, nullid)
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   947
            node1 = b'\xaa' * 20
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   948
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   949
            self._addrawrevisionfn(f, tr, node1, node0, nullid, 1,
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   950
                                   rawtext=fulltext1)
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   951
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   952
        with self.assertRaises(error.StorageError):
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   953
            f.read(node1)
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   954
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   955
        diff = mdiff.textdiff(fulltext1, fulltext2)
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   956
        node2 = storageutil.hashrevisionsha1(fulltext2, node1, nullid)
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   957
        deltas = [(node2, node1, nullid, b'\x01' * 20, node1, diff, 0)]
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   958
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   959
        # This /might/ fail on some backends.
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   960
        with self._maketransactionfn() as tr:
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   961
            f.addgroup(deltas, lambda x: 0, tr)
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   962
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   963
        self.assertEqual(len(f), 3)
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   964
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   965
        # Assuming a delta is stored, we shouldn't need to validate node1 in
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   966
        # order to retrieve node2.
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   967
        self.assertEqual(f.read(node2), fulltext2)
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   968
39772
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   969
    def testcensored(self):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   970
        f = self._makefilefn()
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   971
39878
3e896b51aa5d storageutil: move metadata parsing and packing from revlog (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39876
diff changeset
   972
        stored1 = storageutil.packmeta({
39772
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   973
            b'censored': b'tombstone',
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   974
        }, b'')
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   975
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   976
        with self._maketransactionfn() as tr:
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   977
            node0 = f.add(b'foo', None, tr, 0, nullid, nullid)
40051
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   978
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   979
            # The node value doesn't matter since we can't verify it.
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   980
            node1 = b'\xbb' * 20
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   981
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   982
            self._addrawrevisionfn(f, tr, node1, node0, nullid, 1, stored1,
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   983
                                   censored=True)
39772
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   984
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   985
        self.assertTrue(f.iscensored(1))
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   986
40051
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   987
        with self.assertRaises(error.CensoredNodeError):
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   988
            f.revision(1)
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   989
40054
801ccd8e67c0 revlog: clear revision cache on hash verification failure
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40051
diff changeset
   990
        with self.assertRaises(error.CensoredNodeError):
801ccd8e67c0 revlog: clear revision cache on hash verification failure
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40051
diff changeset
   991
            f.revision(1, raw=True)
39772
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   992
40051
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   993
        with self.assertRaises(error.CensoredNodeError):
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   994
            f.read(1)
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   995
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   996
    def testcensoredrawrevision(self):
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   997
        # Like above, except we do the revision(raw=True) request first to
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   998
        # isolate revision caching behavior.
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
   999
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
  1000
        f = self._makefilefn()
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
  1001
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
  1002
        stored1 = storageutil.packmeta({
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
  1003
            b'censored': b'tombstone',
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
  1004
        }, b'')
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
  1005
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
  1006
        with self._maketransactionfn() as tr:
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
  1007
            node0 = f.add(b'foo', None, tr, 0, nullid, nullid)
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
  1008
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
  1009
            # The node value doesn't matter since we can't verify it.
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
  1010
            node1 = b'\xbb' * 20
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
  1011
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
  1012
            self._addrawrevisionfn(f, tr, node1, node0, nullid, 1, stored1,
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
  1013
                                   censored=True)
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
  1014
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
  1015
        with self.assertRaises(error.CensoredNodeError):
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
  1016
            f.revision(1, raw=True)
39772
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1017
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1018
class ifilemutationtests(basetestcase):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1019
    """Generic tests for the ifilemutation interface.
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1020
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1021
    All file storage backends that support writing should conform to this
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1022
    interface.
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1023
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1024
    Use ``makeifilemutationtests()`` to create an instance of this type.
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1025
    """
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1026
    def testaddnoop(self):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1027
        f = self._makefilefn()
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1028
        with self._maketransactionfn() as tr:
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1029
            node0 = f.add(b'foo', None, tr, 0, nullid, nullid)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1030
            node1 = f.add(b'foo', None, tr, 0, nullid, nullid)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1031
            # Varying by linkrev shouldn't impact hash.
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1032
            node2 = f.add(b'foo', None, tr, 1, nullid, nullid)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1033
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1034
        self.assertEqual(node1, node0)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1035
        self.assertEqual(node2, node0)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1036
        self.assertEqual(len(f), 1)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1037
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1038
    def testaddrevisionbadnode(self):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1039
        f = self._makefilefn()
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1040
        with self._maketransactionfn() as tr:
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1041
            # Adding a revision with bad node value fails.
39776
cb65d4b7e429 error: introduce StorageError
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39772
diff changeset
  1042
            with self.assertRaises(error.StorageError):
39772
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1043
                f.addrevision(b'foo', tr, 0, nullid, nullid, node=b'\x01' * 20)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1044
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1045
    def testaddrevisionunknownflag(self):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1046
        f = self._makefilefn()
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1047
        with self._maketransactionfn() as tr:
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1048
            for i in range(15, 0, -1):
40047
8e398628a3f2 repository: define and use revision flag constants
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40003
diff changeset
  1049
                if (1 << i) & ~repository.REVISION_FLAGS_KNOWN:
39772
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1050
                    flags = 1 << i
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1051
                    break
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1052
39776
cb65d4b7e429 error: introduce StorageError
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39772
diff changeset
  1053
            with self.assertRaises(error.StorageError):
39772
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1054
                f.addrevision(b'foo', tr, 0, nullid, nullid, flags=flags)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1055
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1056
    def testaddgroupsimple(self):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1057
        f = self._makefilefn()
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1058
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1059
        callbackargs = []
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1060
        def cb(*args, **kwargs):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1061
            callbackargs.append((args, kwargs))
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1062
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1063
        def linkmapper(node):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1064
            return 0
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1065
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1066
        with self._maketransactionfn() as tr:
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1067
            nodes = f.addgroup([], None, tr, addrevisioncb=cb)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1068
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1069
        self.assertEqual(nodes, [])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1070
        self.assertEqual(callbackargs, [])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1071
        self.assertEqual(len(f), 0)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1072
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1073
        fulltext0 = b'foo'
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1074
        delta0 = mdiff.trivialdiffheader(len(fulltext0)) + fulltext0
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1075
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1076
        with self._maketransactionfn() as tr:
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1077
            node0 = f.add(fulltext0, None, tr, 0, nullid, nullid)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1078
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1079
        f = self._makefilefn()
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1080
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1081
        deltas = [
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1082
            (node0, nullid, nullid, nullid, nullid, delta0, 0),
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1083
        ]
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1084
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1085
        with self._maketransactionfn() as tr:
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1086
            nodes = f.addgroup(deltas, linkmapper, tr, addrevisioncb=cb)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1087
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1088
        self.assertEqual(nodes, [
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1089
            b'\x49\xd8\xcb\xb1\x5c\xe2\x57\x92\x04\x47'
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1090
            b'\x00\x6b\x46\x97\x8b\x7a\xf9\x80\xa9\x79'])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1091
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1092
        self.assertEqual(len(callbackargs), 1)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1093
        self.assertEqual(callbackargs[0][0][1], nodes[0])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1094
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1095
        self.assertEqual(list(f.revs()), [0])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1096
        self.assertEqual(f.rev(nodes[0]), 0)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1097
        self.assertEqual(f.node(0), nodes[0])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1098
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1099
    def testaddgroupmultiple(self):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1100
        f = self._makefilefn()
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1101
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1102
        fulltexts = [
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1103
            b'foo',
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1104
            b'bar',
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1105
            b'x' * 1024,
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1106
        ]
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1107
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1108
        nodes = []
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1109
        with self._maketransactionfn() as tr:
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1110
            for fulltext in fulltexts:
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1111
                nodes.append(f.add(fulltext, None, tr, 0, nullid, nullid))
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1112
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1113
        f = self._makefilefn()
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1114
        deltas = []
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1115
        for i, fulltext in enumerate(fulltexts):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1116
            delta = mdiff.trivialdiffheader(len(fulltext)) + fulltext
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1117
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1118
            deltas.append((nodes[i], nullid, nullid, nullid, nullid, delta, 0))
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1119
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1120
        with self._maketransactionfn() as tr:
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1121
            self.assertEqual(f.addgroup(deltas, lambda x: 0, tr), nodes)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1122
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1123
        self.assertEqual(len(f), len(deltas))
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1124
        self.assertEqual(list(f.revs()), [0, 1, 2])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1125
        self.assertEqual(f.rev(nodes[0]), 0)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1126
        self.assertEqual(f.rev(nodes[1]), 1)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1127
        self.assertEqual(f.rev(nodes[2]), 2)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1128
        self.assertEqual(f.node(0), nodes[0])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1129
        self.assertEqual(f.node(1), nodes[1])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1130
        self.assertEqual(f.node(2), nodes[2])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1131
40051
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
  1132
    def testdeltaagainstcensored(self):
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
  1133
        # Attempt to apply a delta made against a censored revision.
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
  1134
        f = self._makefilefn()
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
  1135
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
  1136
        stored1 = storageutil.packmeta({
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
  1137
            b'censored': b'tombstone',
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
  1138
        }, b'')
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
  1139
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
  1140
        with self._maketransactionfn() as tr:
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
  1141
            node0 = f.add(b'foo\n' * 30, None, tr, 0, nullid, nullid)
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
  1142
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
  1143
            # The node value doesn't matter since we can't verify it.
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
  1144
            node1 = b'\xbb' * 20
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
  1145
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
  1146
            self._addrawrevisionfn(f, tr, node1, node0, nullid, 1, stored1,
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
  1147
                                   censored=True)
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
  1148
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
  1149
        delta = mdiff.textdiff(b'bar\n' * 30, (b'bar\n' * 30) + b'baz\n')
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
  1150
        deltas = [(b'\xcc' * 20, node1, nullid, b'\x01' * 20, node1, delta, 0)]
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
  1151
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
  1152
        with self._maketransactionfn() as tr:
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
  1153
            with self.assertRaises(error.CensoredBaseError):
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
  1154
                f.addgroup(deltas, lambda x: 0, tr)
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
  1155
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
  1156
    def testcensorrevisionbasic(self):
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
  1157
        f = self._makefilefn()
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
  1158
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
  1159
        with self._maketransactionfn() as tr:
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
  1160
            node0 = f.add(b'foo\n' * 30, None, tr, 0, nullid, nullid)
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
  1161
            node1 = f.add(b'foo\n' * 31, None, tr, 1, node0, nullid)
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
  1162
            node2 = f.add(b'foo\n' * 32, None, tr, 2, node1, nullid)
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
  1163
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
  1164
        with self._maketransactionfn() as tr:
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
  1165
            f.censorrevision(tr, node1)
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
  1166
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
  1167
        self.assertEqual(len(f), 3)
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
  1168
        self.assertEqual(list(f.revs()), [0, 1, 2])
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
  1169
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
  1170
        self.assertEqual(f.read(node0), b'foo\n' * 30)
40056
324b4b10351e revlog: rewrite censoring logic
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40054
diff changeset
  1171
        self.assertEqual(f.read(node2), b'foo\n' * 32)
40051
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
  1172
40056
324b4b10351e revlog: rewrite censoring logic
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40054
diff changeset
  1173
        with self.assertRaises(error.CensoredNodeError):
40051
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
  1174
            f.read(node1)
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
  1175
40050
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1176
    def testgetstrippointnoparents(self):
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1177
        # N revisions where none have parents.
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1178
        f = self._makefilefn()
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1179
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1180
        with self._maketransactionfn() as tr:
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1181
            for rev in range(10):
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1182
                f.add(b'%d' % rev, None, tr, rev, nullid, nullid)
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1183
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1184
        for rev in range(10):
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1185
            self.assertEqual(f.getstrippoint(rev), (rev, set()))
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1186
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1187
    def testgetstrippointlinear(self):
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1188
        # N revisions in a linear chain.
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1189
        f = self._makefilefn()
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1190
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1191
        with self._maketransactionfn() as tr:
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1192
            p1 = nullid
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1193
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1194
            for rev in range(10):
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1195
                f.add(b'%d' % rev, None, tr, rev, p1, nullid)
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1196
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1197
        for rev in range(10):
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1198
            self.assertEqual(f.getstrippoint(rev), (rev, set()))
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1199
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1200
    def testgetstrippointmultipleheads(self):
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1201
        f = self._makefilefn()
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1202
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1203
        with self._maketransactionfn() as tr:
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1204
            node0 = f.add(b'0', None, tr, 0, nullid, nullid)
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1205
            node1 = f.add(b'1', None, tr, 1, node0, nullid)
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1206
            f.add(b'2', None, tr, 2, node1, nullid)
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1207
            f.add(b'3', None, tr, 3, node0, nullid)
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1208
            f.add(b'4', None, tr, 4, node0, nullid)
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1209
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1210
        for rev in range(5):
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1211
            self.assertEqual(f.getstrippoint(rev), (rev, set()))
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1212
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1213
    def testgetstrippointearlierlinkrevs(self):
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1214
        f = self._makefilefn()
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1215
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1216
        with self._maketransactionfn() as tr:
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1217
            node0 = f.add(b'0', None, tr, 0, nullid, nullid)
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1218
            f.add(b'1', None, tr, 10, node0, nullid)
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1219
            f.add(b'2', None, tr, 5, node0, nullid)
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1220
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1221
        self.assertEqual(f.getstrippoint(0), (0, set()))
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1222
        self.assertEqual(f.getstrippoint(1), (1, set()))
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1223
        self.assertEqual(f.getstrippoint(2), (1, set()))
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1224
        self.assertEqual(f.getstrippoint(3), (1, set()))
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1225
        self.assertEqual(f.getstrippoint(4), (1, set()))
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1226
        self.assertEqual(f.getstrippoint(5), (1, set()))
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1227
        self.assertEqual(f.getstrippoint(6), (1, {2}))
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1228
        self.assertEqual(f.getstrippoint(7), (1, {2}))
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1229
        self.assertEqual(f.getstrippoint(8), (1, {2}))
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1230
        self.assertEqual(f.getstrippoint(9), (1, {2}))
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1231
        self.assertEqual(f.getstrippoint(10), (1, {2}))
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1232
        self.assertEqual(f.getstrippoint(11), (3, set()))
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1233
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1234
    def teststripempty(self):
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1235
        f = self._makefilefn()
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1236
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1237
        with self._maketransactionfn() as tr:
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1238
            f.strip(0, tr)
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1239
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1240
        self.assertEqual(len(f), 0)
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1241
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1242
    def teststripall(self):
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1243
        f = self._makefilefn()
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1244
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1245
        with self._maketransactionfn() as tr:
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1246
            p1 = nullid
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1247
            for rev in range(10):
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1248
                p1 = f.add(b'%d' % rev, None, tr, rev, p1, nullid)
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1249
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1250
        self.assertEqual(len(f), 10)
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1251
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1252
        with self._maketransactionfn() as tr:
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1253
            f.strip(0, tr)
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1254
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1255
        self.assertEqual(len(f), 0)
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1256
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1257
    def teststrippartial(self):
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1258
        f = self._makefilefn()
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1259
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1260
        with self._maketransactionfn() as tr:
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1261
            f.add(b'0', None, tr, 0, nullid, nullid)
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1262
            node1 = f.add(b'1', None, tr, 5, nullid, nullid)
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1263
            node2 = f.add(b'2', None, tr, 10, nullid, nullid)
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1264
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1265
        self.assertEqual(len(f), 3)
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1266
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1267
        with self._maketransactionfn() as tr:
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1268
            f.strip(11, tr)
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1269
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1270
        self.assertEqual(len(f), 3)
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1271
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1272
        with self._maketransactionfn() as tr:
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1273
            f.strip(10, tr)
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1274
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1275
        self.assertEqual(len(f), 2)
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1276
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1277
        with self.assertRaises(error.LookupError):
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1278
            f.rev(node2)
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1279
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1280
        with self._maketransactionfn() as tr:
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1281
            f.strip(6, tr)
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1282
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1283
        self.assertEqual(len(f), 2)
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1284
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1285
        with self._maketransactionfn() as tr:
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1286
            f.strip(3, tr)
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1287
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1288
        self.assertEqual(len(f), 1)
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1289
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1290
        with self.assertRaises(error.LookupError):
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1291
            f.rev(node1)
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
  1292
40051
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
  1293
def makeifileindextests(makefilefn, maketransactionfn, addrawrevisionfn):
39772
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1294
    """Create a unittest.TestCase class suitable for testing file storage.
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1295
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1296
    ``makefilefn`` is a callable which receives the test case as an
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1297
    argument and returns an object implementing the ``ifilestorage`` interface.
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1298
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1299
    ``maketransactionfn`` is a callable which receives the test case as an
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1300
    argument and returns a transaction object.
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1301
40051
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
  1302
    ``addrawrevisionfn`` is a callable which receives arguments describing a
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
  1303
    low-level revision to add. This callable allows the insertion of
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
  1304
    potentially bad data into the store in order to facilitate testing.
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
  1305
39772
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1306
    Returns a type that is a ``unittest.TestCase`` that can be used for
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1307
    testing the object implementing the file storage interface. Simply
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1308
    assign the returned value to a module-level attribute and a test loader
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1309
    should find and run it automatically.
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1310
    """
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1311
    d = {
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1312
        r'_makefilefn': makefilefn,
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1313
        r'_maketransactionfn': maketransactionfn,
40051
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
  1314
        r'_addrawrevisionfn': addrawrevisionfn,
39772
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1315
    }
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1316
    return type(r'ifileindextests', (ifileindextests,), d)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1317
40051
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
  1318
def makeifiledatatests(makefilefn, maketransactionfn, addrawrevisionfn):
39772
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1319
    d = {
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1320
        r'_makefilefn': makefilefn,
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1321
        r'_maketransactionfn': maketransactionfn,
40051
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
  1322
        r'_addrawrevisionfn': addrawrevisionfn,
39772
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1323
    }
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1324
    return type(r'ifiledatatests', (ifiledatatests,), d)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1325
40051
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
  1326
def makeifilemutationtests(makefilefn, maketransactionfn, addrawrevisionfn):
39772
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1327
    d = {
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1328
        r'_makefilefn': makefilefn,
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1329
        r'_maketransactionfn': maketransactionfn,
40051
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
  1330
        r'_addrawrevisionfn': addrawrevisionfn,
39772
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1331
    }
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
  1332
    return type(r'ifilemutationtests', (ifilemutationtests,), d)