annotate mercurial/testing/storage.py @ 51863:f4733654f144

typing: add `from __future__ import annotations` to most files Now that py36 is no longer supported, we can postpone annotation evaluation. This means that the quoting is usually optional (for things imported under the guard of `if typing.TYPE_CHECKING:` to avoid circular imports), and there's less overhead on startup[1]. There may be some missing here. I backed out 6000f5b25c9b (which removed the `from __future__ import ...` that was supporting py2), reverted the changes in `contrib/`, `doc/`, and `tests/`, and then ran: $ hg status -n --change . | \ xargs sed -i -e 's/from __future__ import .*$/from __future__ import annotations/' There were some minor tweaks needed when reviewing (mostly making the spacing around the import consistent, and `mercurial/testing/__init__.py` had a multiline import that wasn't fully rewritten. [1] https://docs.python.org/3/whatsnew/3.7.html#pep-563-postponed-evaluation-of-annotations
author Matt Harbison <matt_harbison@yahoo.com>
date Mon, 16 Sep 2024 15:36:44 +0200
parents ceeb8fa23cc8
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
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
51863
f4733654f144 typing: add `from __future__ import annotations` to most files
Matt Harbison <matt_harbison@yahoo.com>
parents: 51270
diff changeset
8 from __future__ import annotations
39772
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 nullrev,
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
15 )
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
16 from .. import (
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
17 error,
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
18 mdiff,
42813
268662aac075 interfaces: create a new folder for interfaces and move repository.py in it
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 42778
diff changeset
19 )
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
20 from ..interfaces import repository
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
21 from ..utils import storageutil
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
22
39772
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
23
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
24 class basetestcase(unittest.TestCase):
43103
c95b2f40db7c py3: stop normalizing 2nd argument of *attr() to unicode
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43089
diff changeset
25 if not getattr(unittest.TestCase, 'assertRaisesRegex', False):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
26 assertRaisesRegex = ( # camelcase-required
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
27 unittest.TestCase.assertRaisesRegexp
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
28 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
29
39772
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 """
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
39
39772
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
40 def testempty(self):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
41 f = self._makefilefn()
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
42 self.assertEqual(len(f), 0, b'new file store has 0 length by default')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
43 self.assertEqual(list(f), [], b'iter yields nothing by default')
39772
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
44
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
45 gen = iter(f)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
46 with self.assertRaises(StopIteration):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
47 next(gen)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
48
40387
f1a39128da95 filelog: add a hasnode() method (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40323
diff changeset
49 self.assertFalse(f.hasnode(None))
f1a39128da95 filelog: add a hasnode() method (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40323
diff changeset
50 self.assertFalse(f.hasnode(0))
f1a39128da95 filelog: add a hasnode() method (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40323
diff changeset
51 self.assertFalse(f.hasnode(nullrev))
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
52 self.assertFalse(f.hasnode(f.nullid))
40387
f1a39128da95 filelog: add a hasnode() method (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40323
diff changeset
53 self.assertFalse(f.hasnode(b'0'))
f1a39128da95 filelog: add a hasnode() method (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40323
diff changeset
54 self.assertFalse(f.hasnode(b'a' * 20))
f1a39128da95 filelog: add a hasnode() method (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40323
diff changeset
55
39772
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
56 # 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
57 self.assertEqual(list(f.revs()), [])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
58
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
59 revs = iter(f.revs())
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
60 with self.assertRaises(StopIteration):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
61 next(revs)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
62
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
63 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
64
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
65 # parents() and parentrevs() work with f.nullid/nullrev.
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
66 self.assertEqual(f.parents(f.nullid), (f.nullid, f.nullid))
39772
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
67 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
68
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
69 with self.assertRaises(error.LookupError):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
70 f.parents(b'\x01' * 20)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
71
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
72 for i in range(-5, 5):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
73 if i == nullrev:
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
74 continue
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
75
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
76 with self.assertRaises(IndexError):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
77 f.parentrevs(i)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
78
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
79 # f.nullid/nullrev lookup always works.
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
80 self.assertEqual(f.rev(f.nullid), nullrev)
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
81 self.assertEqual(f.node(nullrev), f.nullid)
39772
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
82
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
83 with self.assertRaises(error.LookupError):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
84 f.rev(b'\x01' * 20)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
85
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
86 for i in range(-5, 5):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
87 if i == nullrev:
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
88 continue
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
89
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
90 with self.assertRaises(IndexError):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
91 f.node(i)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
92
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
93 self.assertEqual(f.lookup(f.nullid), f.nullid)
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
94 self.assertEqual(f.lookup(nullrev), f.nullid)
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
95 self.assertEqual(f.lookup(hex(f.nullid)), f.nullid)
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
96 self.assertEqual(f.lookup(b'%d' % nullrev), f.nullid)
39772
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
97
40001
215fd73cfe52 testing: add more testing for ifileindex.lookup()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39998
diff changeset
98 with self.assertRaises(error.LookupError):
215fd73cfe52 testing: add more testing for ifileindex.lookup()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39998
diff changeset
99 f.lookup(b'badvalue')
215fd73cfe52 testing: add more testing for ifileindex.lookup()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39998
diff changeset
100
40002
0e8836be9541 storageutil: implement file identifier resolution method (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40001
diff changeset
101 with self.assertRaises(error.LookupError):
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
102 f.lookup(hex(f.nullid)[0:12])
40001
215fd73cfe52 testing: add more testing for ifileindex.lookup()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39998
diff changeset
103
215fd73cfe52 testing: add more testing for ifileindex.lookup()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39998
diff changeset
104 with self.assertRaises(error.LookupError):
215fd73cfe52 testing: add more testing for ifileindex.lookup()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39998
diff changeset
105 f.lookup(b'-2')
215fd73cfe52 testing: add more testing for ifileindex.lookup()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39998
diff changeset
106
40002
0e8836be9541 storageutil: implement file identifier resolution method (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40001
diff changeset
107 with self.assertRaises(error.LookupError):
0e8836be9541 storageutil: implement file identifier resolution method (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40001
diff changeset
108 f.lookup(b'0')
40001
215fd73cfe52 testing: add more testing for ifileindex.lookup()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39998
diff changeset
109
215fd73cfe52 testing: add more testing for ifileindex.lookup()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39998
diff changeset
110 with self.assertRaises(error.LookupError):
215fd73cfe52 testing: add more testing for ifileindex.lookup()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39998
diff changeset
111 f.lookup(b'1')
215fd73cfe52 testing: add more testing for ifileindex.lookup()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39998
diff changeset
112
215fd73cfe52 testing: add more testing for ifileindex.lookup()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39998
diff changeset
113 with self.assertRaises(error.LookupError):
215fd73cfe52 testing: add more testing for ifileindex.lookup()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39998
diff changeset
114 f.lookup(b'11111111111111111111111111111111111111')
215fd73cfe52 testing: add more testing for ifileindex.lookup()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39998
diff changeset
115
215fd73cfe52 testing: add more testing for ifileindex.lookup()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39998
diff changeset
116 for i in range(-5, 5):
215fd73cfe52 testing: add more testing for ifileindex.lookup()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39998
diff changeset
117 if i == nullrev:
215fd73cfe52 testing: add more testing for ifileindex.lookup()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39998
diff changeset
118 continue
215fd73cfe52 testing: add more testing for ifileindex.lookup()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39998
diff changeset
119
215fd73cfe52 testing: add more testing for ifileindex.lookup()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39998
diff changeset
120 with self.assertRaises(LookupError):
215fd73cfe52 testing: add more testing for ifileindex.lookup()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39998
diff changeset
121 f.lookup(i)
215fd73cfe52 testing: add more testing for ifileindex.lookup()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39998
diff changeset
122
39772
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
123 self.assertEqual(f.linkrev(nullrev), nullrev)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
124
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
125 for i in range(-5, 5):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
126 if i == nullrev:
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
127 continue
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
128
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
129 with self.assertRaises(IndexError):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
130 f.linkrev(i)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
131
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
132 self.assertFalse(f.iscensored(nullrev))
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
133
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
134 for i in range(-5, 5):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
135 if i == nullrev:
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
136 continue
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 with self.assertRaises(IndexError):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
139 f.iscensored(i)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
140
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
141 self.assertEqual(list(f.commonancestorsheads(f.nullid, f.nullid)), [])
39772
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
142
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
143 with self.assertRaises(ValueError):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
144 self.assertEqual(list(f.descendants([])), [])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
145
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
146 self.assertEqual(list(f.descendants([nullrev])), [])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
147
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
148 self.assertEqual(f.heads(), [f.nullid])
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
149 self.assertEqual(f.heads(f.nullid), [f.nullid])
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
150 self.assertEqual(f.heads(None, [f.nullid]), [f.nullid])
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
151 self.assertEqual(f.heads(f.nullid, [f.nullid]), [f.nullid])
39772
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
152
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
153 self.assertEqual(f.children(f.nullid), [])
39772
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 with self.assertRaises(error.LookupError):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
156 f.children(b'\x01' * 20)
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 def testsinglerevision(self):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
159 f = self._makefilefn()
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
160 with self._maketransactionfn() as tr:
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
161 node = f.add(b'initial', None, tr, 0, f.nullid, f.nullid)
39772
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
162
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
163 self.assertEqual(len(f), 1)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
164 self.assertEqual(list(f), [0])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
165
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
166 gen = iter(f)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
167 self.assertEqual(next(gen), 0)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
168
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
169 with self.assertRaises(StopIteration):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
170 next(gen)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
171
40387
f1a39128da95 filelog: add a hasnode() method (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40323
diff changeset
172 self.assertTrue(f.hasnode(node))
f1a39128da95 filelog: add a hasnode() method (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40323
diff changeset
173 self.assertFalse(f.hasnode(hex(node)))
f1a39128da95 filelog: add a hasnode() method (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40323
diff changeset
174 self.assertFalse(f.hasnode(nullrev))
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
175 self.assertFalse(f.hasnode(f.nullid))
40387
f1a39128da95 filelog: add a hasnode() method (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40323
diff changeset
176 self.assertFalse(f.hasnode(node[0:12]))
f1a39128da95 filelog: add a hasnode() method (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40323
diff changeset
177 self.assertFalse(f.hasnode(hex(node)[0:20]))
f1a39128da95 filelog: add a hasnode() method (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40323
diff changeset
178
39772
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
179 self.assertEqual(list(f.revs()), [0])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
180 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
181 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
182 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
183 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
184 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
185 # TODO buggy
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
186 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
187 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
188
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
189 self.assertEqual(f.parents(node), (f.nullid, f.nullid))
39772
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
190 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
191
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
192 with self.assertRaises(error.LookupError):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
193 f.parents(b'\x01' * 20)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
194
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
195 with self.assertRaises(IndexError):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
196 f.parentrevs(1)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
197
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
198 self.assertEqual(f.rev(node), 0)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
199
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
200 with self.assertRaises(error.LookupError):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
201 f.rev(b'\x01' * 20)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
202
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
203 self.assertEqual(f.node(0), node)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
204
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
205 with self.assertRaises(IndexError):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
206 f.node(1)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
207
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
208 self.assertEqual(f.lookup(node), node)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
209 self.assertEqual(f.lookup(0), node)
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
210 self.assertEqual(f.lookup(-1), f.nullid)
39772
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
211 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
212 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
213
0e8836be9541 storageutil: implement file identifier resolution method (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40001
diff changeset
214 with self.assertRaises(error.LookupError):
0e8836be9541 storageutil: implement file identifier resolution method (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40001
diff changeset
215 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
216
40003
ad8389ecd3f5 storageutil: consistently raise LookupError (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40002
diff changeset
217 with self.assertRaises(error.LookupError):
40001
215fd73cfe52 testing: add more testing for ifileindex.lookup()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39998
diff changeset
218 f.lookup(-2)
215fd73cfe52 testing: add more testing for ifileindex.lookup()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39998
diff changeset
219
215fd73cfe52 testing: add more testing for ifileindex.lookup()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39998
diff changeset
220 with self.assertRaises(error.LookupError):
215fd73cfe52 testing: add more testing for ifileindex.lookup()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39998
diff changeset
221 f.lookup(b'-2')
215fd73cfe52 testing: add more testing for ifileindex.lookup()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39998
diff changeset
222
40003
ad8389ecd3f5 storageutil: consistently raise LookupError (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40002
diff changeset
223 with self.assertRaises(error.LookupError):
40001
215fd73cfe52 testing: add more testing for ifileindex.lookup()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39998
diff changeset
224 f.lookup(1)
215fd73cfe52 testing: add more testing for ifileindex.lookup()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39998
diff changeset
225
215fd73cfe52 testing: add more testing for ifileindex.lookup()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39998
diff changeset
226 with self.assertRaises(error.LookupError):
215fd73cfe52 testing: add more testing for ifileindex.lookup()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39998
diff changeset
227 f.lookup(b'1')
39772
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
228
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
229 self.assertEqual(f.linkrev(0), 0)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
230
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
231 with self.assertRaises(IndexError):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
232 f.linkrev(1)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
233
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
234 self.assertFalse(f.iscensored(0))
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
235
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
236 with self.assertRaises(IndexError):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
237 f.iscensored(1)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
238
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
239 self.assertEqual(list(f.descendants([0])), [])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
240
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
241 self.assertEqual(f.heads(), [node])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
242 self.assertEqual(f.heads(node), [node])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
243 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
244
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
245 with self.assertRaises(error.LookupError):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
246 f.heads(stop=[b'\x01' * 20])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
247
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
248 self.assertEqual(f.children(node), [])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
249
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
250 def testmultiplerevisions(self):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
251 fulltext0 = b'x' * 1024
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
252 fulltext1 = fulltext0 + b'y'
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
253 fulltext2 = b'y' + fulltext0 + b'z'
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
254
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
255 f = self._makefilefn()
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
256 with self._maketransactionfn() as tr:
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
257 node0 = f.add(fulltext0, None, tr, 0, f.nullid, f.nullid)
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
258 node1 = f.add(fulltext1, None, tr, 1, node0, f.nullid)
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
259 node2 = f.add(fulltext2, None, tr, 3, node1, f.nullid)
39772
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
260
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
261 self.assertEqual(len(f), 3)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
262 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
263
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
264 gen = iter(f)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
265 self.assertEqual(next(gen), 0)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
266 self.assertEqual(next(gen), 1)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
267 self.assertEqual(next(gen), 2)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
268
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
269 with self.assertRaises(StopIteration):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
270 next(gen)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
271
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
272 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
273 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
274 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
275 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
276 self.assertEqual(list(f.revs(3)), [])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
277 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
278 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
279 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
280 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
281 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
282 # TODO this is wrong
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
283 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
284
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
285 self.assertEqual(f.parents(node0), (f.nullid, f.nullid))
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
286 self.assertEqual(f.parents(node1), (node0, f.nullid))
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
287 self.assertEqual(f.parents(node2), (node1, f.nullid))
39772
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 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
290 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
291 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
292
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
293 self.assertEqual(f.rev(node0), 0)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
294 self.assertEqual(f.rev(node1), 1)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
295 self.assertEqual(f.rev(node2), 2)
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 with self.assertRaises(error.LookupError):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
298 f.rev(b'\x01' * 20)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
299
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
300 self.assertEqual(f.node(0), node0)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
301 self.assertEqual(f.node(1), node1)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
302 self.assertEqual(f.node(2), node2)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
303
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
304 with self.assertRaises(IndexError):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
305 f.node(3)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
306
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
307 self.assertEqual(f.lookup(node0), node0)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
308 self.assertEqual(f.lookup(0), node0)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
309 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
310 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
311
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
312 self.assertEqual(f.lookup(node1), node1)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
313 self.assertEqual(f.lookup(1), node1)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
314 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
315 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
316
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
317 self.assertEqual(f.linkrev(0), 0)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
318 self.assertEqual(f.linkrev(1), 1)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
319 self.assertEqual(f.linkrev(2), 3)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
320
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
321 with self.assertRaises(IndexError):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
322 f.linkrev(3)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
323
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
324 self.assertFalse(f.iscensored(0))
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
325 self.assertFalse(f.iscensored(1))
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
326 self.assertFalse(f.iscensored(2))
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
327
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
328 with self.assertRaises(IndexError):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
329 f.iscensored(3)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
330
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
331 self.assertEqual(f.commonancestorsheads(node1, f.nullid), [])
39772
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
332 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
333 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
334 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
335 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
336 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
337
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
338 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
339 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
340 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
341
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
342 self.assertEqual(f.heads(), [node2])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
343 self.assertEqual(f.heads(node0), [node2])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
344 self.assertEqual(f.heads(node1), [node2])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
345 self.assertEqual(f.heads(node2), [node2])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
346
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
347 # 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
348 # 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
349 # behavior.
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
350 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
351 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
352 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
353
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
354 with self.assertRaises(error.LookupError):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
355 f.heads(stop=[b'\x01' * 20])
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(f.children(node0), [node1])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
358 self.assertEqual(f.children(node1), [node2])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
359 self.assertEqual(f.children(node2), [])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
360
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
361 def testmultipleheads(self):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
362 f = self._makefilefn()
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
363
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
364 with self._maketransactionfn() as tr:
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
365 node0 = f.add(b'0', None, tr, 0, f.nullid, f.nullid)
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
366 node1 = f.add(b'1', None, tr, 1, node0, f.nullid)
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
367 node2 = f.add(b'2', None, tr, 2, node1, f.nullid)
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
368 node3 = f.add(b'3', None, tr, 3, node0, f.nullid)
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
369 node4 = f.add(b'4', None, tr, 4, node3, f.nullid)
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
370 node5 = f.add(b'5', None, tr, 5, node0, f.nullid)
39772
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
371
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
372 self.assertEqual(len(f), 6)
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 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
375 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
376 self.assertEqual(list(f.descendants([2])), [])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
377 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
378 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
379 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
380
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
381 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
382 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
383 self.assertEqual(f.heads(node1), [node2])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
384 self.assertEqual(f.heads(node2), [node2])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
385 self.assertEqual(f.heads(node3), [node4])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
386 self.assertEqual(f.heads(node4), [node4])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
387 self.assertEqual(f.heads(node5), [node5])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
388
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
389 # TODO this seems wrong.
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
390 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
391 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
392
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
393 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
394 self.assertEqual(f.children(node1), [node2])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
395 self.assertEqual(f.children(node2), [])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
396 self.assertEqual(f.children(node3), [node4])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
397 self.assertEqual(f.children(node4), [])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
398 self.assertEqual(f.children(node5), [])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
399
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
400
39772
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
401 class ifiledatatests(basetestcase):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
402 """Generic tests for the ifiledata interface.
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
403
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
404 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
405 class.
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
406
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
407 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
408 """
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
409
39772
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
410 def testempty(self):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
411 f = self._makefilefn()
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
412
39869
14e500b58263 revlog: add method for obtaining storage info (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39866
diff changeset
413 self.assertEqual(f.storageinfo(), {})
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
414 self.assertEqual(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
415 f.storageinfo(revisionscount=True, trackedsize=True),
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
416 {b'revisionscount': 0, b'trackedsize': 0},
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
417 )
39869
14e500b58263 revlog: add method for obtaining storage info (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39866
diff changeset
418
39772
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
419 self.assertEqual(f.size(nullrev), 0)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
420
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
421 for i in range(-5, 5):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
422 if i == nullrev:
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
423 continue
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 with self.assertRaises(IndexError):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
426 f.size(i)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
427
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
428 self.assertEqual(f.revision(f.nullid), b'')
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
429 self.assertEqual(f.rawdata(f.nullid), b'')
39772
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
430
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
431 with self.assertRaises(error.LookupError):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
432 f.revision(b'\x01' * 20)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
433
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
434 self.assertEqual(f.read(f.nullid), b'')
39772
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
435
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
436 with self.assertRaises(error.LookupError):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
437 f.read(b'\x01' * 20)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
438
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
439 self.assertFalse(f.renamed(f.nullid))
39772
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
440
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
441 with self.assertRaises(error.LookupError):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
442 f.read(b'\x01' * 20)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
443
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
444 self.assertTrue(f.cmp(f.nullid, b''))
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
445 self.assertTrue(f.cmp(f.nullid, b'foo'))
39772
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
446
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
447 with self.assertRaises(error.LookupError):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
448 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
449
39862
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
450 # 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
451 gen = f.emitrevisions([])
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
452 with self.assertRaises(StopIteration):
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
453 next(gen)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
454
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
455 # Emitting null node yields nothing.
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
456 gen = f.emitrevisions([f.nullid])
39862
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
457 with self.assertRaises(StopIteration):
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
458 next(gen)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
459
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
460 # Requesting unknown node fails.
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
461 with self.assertRaises(error.LookupError):
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
462 list(f.emitrevisions([b'\x01' * 20]))
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
463
39772
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
464 def testsinglerevision(self):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
465 fulltext = b'initial'
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
466
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
467 f = self._makefilefn()
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
468 with self._maketransactionfn() as tr:
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
469 node = f.add(fulltext, None, tr, 0, f.nullid, f.nullid)
39772
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
470
39869
14e500b58263 revlog: add method for obtaining storage info (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39866
diff changeset
471 self.assertEqual(f.storageinfo(), {})
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
472 self.assertEqual(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
473 f.storageinfo(revisionscount=True, trackedsize=True),
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
474 {b'revisionscount': 1, b'trackedsize': len(fulltext)},
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
475 )
39869
14e500b58263 revlog: add method for obtaining storage info (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39866
diff changeset
476
39772
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
477 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
478
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
479 with self.assertRaises(IndexError):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
480 f.size(1)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
481
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
482 self.assertEqual(f.revision(node), fulltext)
42778
22e74b5aa59d rawdata: update callers in testing/storage.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 40430
diff changeset
483 self.assertEqual(f.rawdata(node), fulltext)
39772
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
484
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
485 self.assertEqual(f.read(node), fulltext)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
486
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
487 self.assertFalse(f.renamed(node))
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
488
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
489 self.assertFalse(f.cmp(node, fulltext))
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
490 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
491
39862
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
492 # Emitting a single revision works.
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
493 gen = f.emitrevisions([node])
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
494 rev = next(gen)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
495
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
496 self.assertEqual(rev.node, node)
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
497 self.assertEqual(rev.p1node, f.nullid)
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
498 self.assertEqual(rev.p2node, f.nullid)
39862
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
499 self.assertIsNone(rev.linknode)
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
500 self.assertEqual(rev.basenode, f.nullid)
39862
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
501 self.assertIsNone(rev.baserevisionsize)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
502 self.assertIsNone(rev.revision)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
503 self.assertIsNone(rev.delta)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
504
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
505 with self.assertRaises(StopIteration):
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
506 next(gen)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
507
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
508 # Requesting revision data works.
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
509 gen = f.emitrevisions([node], revisiondata=True)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
510 rev = next(gen)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
511
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
512 self.assertEqual(rev.node, node)
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
513 self.assertEqual(rev.p1node, f.nullid)
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
514 self.assertEqual(rev.p2node, f.nullid)
39862
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
515 self.assertIsNone(rev.linknode)
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
516 self.assertEqual(rev.basenode, f.nullid)
39862
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
517 self.assertIsNone(rev.baserevisionsize)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
518 self.assertEqual(rev.revision, fulltext)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
519 self.assertIsNone(rev.delta)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
520
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
521 with self.assertRaises(StopIteration):
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
522 next(gen)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
523
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
524 # 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
525 with self.assertRaises(error.LookupError):
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
526 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
527
39772
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
528 def testmultiplerevisions(self):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
529 fulltext0 = b'x' * 1024
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
530 fulltext1 = fulltext0 + b'y'
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
531 fulltext2 = b'y' + fulltext0 + b'z'
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 f = self._makefilefn()
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
534 with self._maketransactionfn() as tr:
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
535 node0 = f.add(fulltext0, None, tr, 0, f.nullid, f.nullid)
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
536 node1 = f.add(fulltext1, None, tr, 1, node0, f.nullid)
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
537 node2 = f.add(fulltext2, None, tr, 3, node1, f.nullid)
39772
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
538
39869
14e500b58263 revlog: add method for obtaining storage info (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39866
diff changeset
539 self.assertEqual(f.storageinfo(), {})
14e500b58263 revlog: add method for obtaining storage info (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39866
diff changeset
540 self.assertEqual(
14e500b58263 revlog: add method for obtaining storage info (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39866
diff changeset
541 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
542 {
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
543 b'revisionscount': 3,
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
544 b'trackedsize': len(fulltext0)
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
545 + len(fulltext1)
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
546 + len(fulltext2),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
547 },
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
548 )
39869
14e500b58263 revlog: add method for obtaining storage info (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39866
diff changeset
549
39772
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
550 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
551 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
552 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
553
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
554 with self.assertRaises(IndexError):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
555 f.size(3)
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.assertEqual(f.revision(node0), fulltext0)
42778
22e74b5aa59d rawdata: update callers in testing/storage.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 40430
diff changeset
558 self.assertEqual(f.rawdata(node0), fulltext0)
39772
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
559 self.assertEqual(f.revision(node1), fulltext1)
42778
22e74b5aa59d rawdata: update callers in testing/storage.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 40430
diff changeset
560 self.assertEqual(f.rawdata(node1), fulltext1)
39772
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
561 self.assertEqual(f.revision(node2), fulltext2)
42778
22e74b5aa59d rawdata: update callers in testing/storage.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 40430
diff changeset
562 self.assertEqual(f.rawdata(node2), fulltext2)
39772
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.revision(b'\x01' * 20)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
566
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
567 self.assertEqual(f.read(node0), fulltext0)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
568 self.assertEqual(f.read(node1), fulltext1)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
569 self.assertEqual(f.read(node2), fulltext2)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
570
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
571 with self.assertRaises(error.LookupError):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
572 f.read(b'\x01' * 20)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
573
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
574 self.assertFalse(f.renamed(node0))
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
575 self.assertFalse(f.renamed(node1))
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
576 self.assertFalse(f.renamed(node2))
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
577
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
578 with self.assertRaises(error.LookupError):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
579 f.renamed(b'\x01' * 20)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
580
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
581 self.assertFalse(f.cmp(node0, fulltext0))
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
582 self.assertFalse(f.cmp(node1, fulltext1))
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
583 self.assertFalse(f.cmp(node2, fulltext2))
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
584
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
585 self.assertTrue(f.cmp(node1, fulltext0))
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
586 self.assertTrue(f.cmp(node2, fulltext1))
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
587
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
588 with self.assertRaises(error.LookupError):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
589 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
590
39862
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
591 # Nodes should be emitted in order.
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
592 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
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, node0)
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
597 self.assertEqual(rev.p1node, f.nullid)
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
598 self.assertEqual(rev.p2node, f.nullid)
39862
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
599 self.assertIsNone(rev.linknode)
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
600 self.assertEqual(rev.basenode, f.nullid)
39862
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.assertEqual(rev.revision, fulltext0)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
603 self.assertIsNone(rev.delta)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
604
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
605 rev = next(gen)
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 self.assertEqual(rev.node, node1)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
608 self.assertEqual(rev.p1node, node0)
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
609 self.assertEqual(rev.p2node, f.nullid)
39862
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
610 self.assertIsNone(rev.linknode)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
611 self.assertEqual(rev.basenode, node0)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
612 self.assertIsNone(rev.baserevisionsize)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
613 self.assertIsNone(rev.revision)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
614 self.assertEqual(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
615 rev.delta,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
616 b'\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x04\x01' + fulltext1,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
617 )
39862
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
618
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
619 rev = next(gen)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
620
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
621 self.assertEqual(rev.node, node2)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
622 self.assertEqual(rev.p1node, node1)
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
623 self.assertEqual(rev.p2node, f.nullid)
39862
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
624 self.assertIsNone(rev.linknode)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
625 self.assertEqual(rev.basenode, node1)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
626 self.assertIsNone(rev.baserevisionsize)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
627 self.assertIsNone(rev.revision)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
628 self.assertEqual(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
629 rev.delta,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
630 b'\x00\x00\x00\x00\x00\x00\x04\x01\x00\x00\x04\x02' + fulltext2,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
631 )
39862
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
632
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
633 with self.assertRaises(StopIteration):
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
634 next(gen)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
635
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
636 # 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
637 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
638
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
639 rev = next(gen)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
640
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
641 self.assertEqual(rev.node, node0)
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
642 self.assertEqual(rev.p1node, f.nullid)
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
643 self.assertEqual(rev.p2node, f.nullid)
39862
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
644 self.assertIsNone(rev.linknode)
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
645 self.assertEqual(rev.basenode, f.nullid)
39862
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
646 self.assertIsNone(rev.baserevisionsize)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
647 self.assertEqual(rev.revision, fulltext0)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
648 self.assertIsNone(rev.delta)
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 rev = next(gen)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
651
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
652 self.assertEqual(rev.node, node1)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
653 self.assertEqual(rev.p1node, node0)
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
654 self.assertEqual(rev.p2node, f.nullid)
39862
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
655 self.assertIsNone(rev.linknode)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
656 self.assertEqual(rev.basenode, node0)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
657 self.assertIsNone(rev.baserevisionsize)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
658 self.assertIsNone(rev.revision)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
659 self.assertEqual(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
660 rev.delta,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
661 b'\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x04\x01' + fulltext1,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
662 )
39862
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 rev = next(gen)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
665
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
666 self.assertEqual(rev.node, node2)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
667 self.assertEqual(rev.p1node, node1)
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
668 self.assertEqual(rev.p2node, f.nullid)
39862
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
669 self.assertIsNone(rev.linknode)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
670 self.assertEqual(rev.basenode, node1)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
671 self.assertIsNone(rev.baserevisionsize)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
672 self.assertIsNone(rev.revision)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
673 self.assertEqual(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
674 rev.delta,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
675 b'\x00\x00\x00\x00\x00\x00\x04\x01\x00\x00\x04\x02' + fulltext2,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
676 )
39862
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
677
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
678 with self.assertRaises(StopIteration):
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
679 next(gen)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
680
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
681 # Unrecognized nodesorder value raises ProgrammingError.
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
682 with self.assertRaises(error.ProgrammingError):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
683 list(f.emitrevisions([], nodesorder=b'bad'))
39862
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
684
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
685 # 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
686 # because behavior is storage-dependent.
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
687 res = list(
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
688 f.emitrevisions([node2, node1, node0], nodesorder=b'storage')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
689 )
39862
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
690 self.assertEqual(len(res), 3)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
691 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
692
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
693 # nodesorder=nodes forces the order.
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
694 gen = f.emitrevisions(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
695 [node2, node0], nodesorder=b'nodes', revisiondata=True
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
696 )
39862
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
697
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
698 rev = next(gen)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
699 self.assertEqual(rev.node, node2)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
700 self.assertEqual(rev.p1node, node1)
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
701 self.assertEqual(rev.p2node, f.nullid)
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
702 self.assertEqual(rev.basenode, f.nullid)
39862
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
703 self.assertIsNone(rev.baserevisionsize)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
704 self.assertEqual(rev.revision, fulltext2)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
705 self.assertIsNone(rev.delta)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
706
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
707 rev = next(gen)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
708 self.assertEqual(rev.node, node0)
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
709 self.assertEqual(rev.p1node, f.nullid)
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
710 self.assertEqual(rev.p2node, f.nullid)
39862
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
711 # 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
712
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
713 with self.assertRaises(StopIteration):
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
714 next(gen)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
715
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
716 # 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
717 # the first revision.
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
718 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
719
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
720 rev = next(gen)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
721 self.assertEqual(rev.node, node1)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
722 self.assertEqual(rev.p1node, node0)
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
723 self.assertEqual(rev.p2node, f.nullid)
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
724 self.assertEqual(rev.basenode, f.nullid)
39862
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
725 self.assertIsNone(rev.baserevisionsize)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
726 self.assertEqual(rev.revision, fulltext1)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
727 self.assertIsNone(rev.delta)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
728
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
729 rev = next(gen)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
730 self.assertEqual(rev.node, node2)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
731 self.assertEqual(rev.p1node, node1)
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
732 self.assertEqual(rev.p2node, f.nullid)
39862
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
733 self.assertEqual(rev.basenode, node1)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
734 self.assertIsNone(rev.baserevisionsize)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
735 self.assertIsNone(rev.revision)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
736 self.assertEqual(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
737 rev.delta,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
738 b'\x00\x00\x00\x00\x00\x00\x04\x01\x00\x00\x04\x02' + fulltext2,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
739 )
39862
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
740
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
741 with self.assertRaises(StopIteration):
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
742 next(gen)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
743
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
744 # assumehaveparentrevisions=True allows delta against initial revision.
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
745 gen = f.emitrevisions(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
746 [node2, node1], revisiondata=True, assumehaveparentrevisions=True
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
747 )
39862
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, node1)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
751 self.assertEqual(rev.p1node, node0)
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
752 self.assertEqual(rev.p2node, f.nullid)
39862
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
753 self.assertEqual(rev.basenode, node0)
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)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
756 self.assertEqual(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
757 rev.delta,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
758 b'\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x04\x01' + fulltext1,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
759 )
39862
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
760
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
761 # 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
762 # Special case for initial revision.
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
763 gen = f.emitrevisions(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
764 [node0], revisiondata=True, deltamode=repository.CG_DELTAMODE_PREV
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
765 )
39862
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
766
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
767 rev = next(gen)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
768 self.assertEqual(rev.node, node0)
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
769 self.assertEqual(rev.p1node, f.nullid)
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
770 self.assertEqual(rev.p2node, f.nullid)
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
771 self.assertEqual(rev.basenode, f.nullid)
39862
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
772 self.assertIsNone(rev.baserevisionsize)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
773 self.assertIsNone(rev.revision)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
774 self.assertEqual(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
775 rev.delta,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
776 b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00' + fulltext0,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
777 )
39862
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
778
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
779 with self.assertRaises(StopIteration):
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
780 next(gen)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
781
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
782 gen = f.emitrevisions(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
783 [node0, node2],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
784 revisiondata=True,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
785 deltamode=repository.CG_DELTAMODE_PREV,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
786 )
39862
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
787
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
788 rev = next(gen)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
789 self.assertEqual(rev.node, node0)
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
790 self.assertEqual(rev.p1node, f.nullid)
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
791 self.assertEqual(rev.p2node, f.nullid)
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
792 self.assertEqual(rev.basenode, f.nullid)
39862
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
793 self.assertIsNone(rev.baserevisionsize)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
794 self.assertIsNone(rev.revision)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
795 self.assertEqual(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
796 rev.delta,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
797 b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00' + fulltext0,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
798 )
39862
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
799
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
800 rev = next(gen)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
801 self.assertEqual(rev.node, node2)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
802 self.assertEqual(rev.p1node, node1)
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
803 self.assertEqual(rev.p2node, f.nullid)
39862
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
804 self.assertEqual(rev.basenode, node0)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
805
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
806 with self.assertRaises(StopIteration):
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
807 next(gen)
5a9ab91e0a45 revlog: new API to emit revision data
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39785
diff changeset
808
39772
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
809 def testrenamed(self):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
810 fulltext0 = b'foo'
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
811 fulltext1 = b'bar'
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
812 fulltext2 = b'baz'
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 meta1 = {
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
815 b'copy': b'source0',
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
816 b'copyrev': b'a' * 40,
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
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
819 meta2 = {
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
820 b'copy': b'source1',
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
821 b'copyrev': b'b' * 40,
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
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
824 stored1 = b''.join(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
825 [
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
826 b'\x01\ncopy: source0\n',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
827 b'copyrev: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n\x01\n',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
828 fulltext1,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
829 ]
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
830 )
39772
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
831
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
832 stored2 = b''.join(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
833 [
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
834 b'\x01\ncopy: source1\n',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
835 b'copyrev: bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\n\x01\n',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
836 fulltext2,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
837 ]
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
838 )
39772
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
839
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
840 f = self._makefilefn()
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
841 with self._maketransactionfn() as tr:
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
842 node0 = f.add(fulltext0, None, tr, 0, f.nullid, f.nullid)
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
843 node1 = f.add(fulltext1, meta1, tr, 1, node0, f.nullid)
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
844 node2 = f.add(fulltext2, meta2, tr, 2, f.nullid, f.nullid)
39772
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
845
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
846 # Metadata header isn't recognized when parent isn't f.nullid.
39772
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(stored1))
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
848 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
849
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
850 self.assertEqual(f.revision(node1), stored1)
42778
22e74b5aa59d rawdata: update callers in testing/storage.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 40430
diff changeset
851 self.assertEqual(f.rawdata(node1), stored1)
39772
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
852 self.assertEqual(f.revision(node2), stored2)
42778
22e74b5aa59d rawdata: update callers in testing/storage.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 40430
diff changeset
853 self.assertEqual(f.rawdata(node2), stored2)
39772
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(node1), fulltext1)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
856 self.assertEqual(f.read(node2), fulltext2)
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 # 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
859 self.assertFalse(f.renamed(node1))
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
860 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
861
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
862 self.assertTrue(f.cmp(node1, fulltext1))
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
863 self.assertTrue(f.cmp(node1, stored1))
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
864 self.assertFalse(f.cmp(node2, fulltext2))
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
865 self.assertTrue(f.cmp(node2, stored2))
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
866
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
867 def testmetadataprefix(self):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
868 # 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
869 fulltext0 = b'\x01\nfoo'
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
870 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
871
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
872 fulltext1 = b'\x01\nbar'
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
873 meta1 = {
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
874 b'copy': b'source0',
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
875 b'copyrev': b'b' * 40,
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
876 }
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
877 stored1 = b''.join(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
878 [
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
879 b'\x01\ncopy: source0\n',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
880 b'copyrev: %s\n' % (b'b' * 40),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
881 b'\x01\n\x01\nbar',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
882 ]
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
883 )
39772
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
884
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
885 f = self._makefilefn()
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
886 with self._maketransactionfn() as tr:
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
887 node0 = f.add(fulltext0, {}, tr, 0, f.nullid, f.nullid)
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
888 node1 = f.add(fulltext1, meta1, tr, 1, f.nullid, f.nullid)
39772
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
889
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
890 # TODO this is buggy.
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
891 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
892
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
893 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
894
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
895 self.assertEqual(f.revision(node0), stored0)
42778
22e74b5aa59d rawdata: update callers in testing/storage.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 40430
diff changeset
896 self.assertEqual(f.rawdata(node0), stored0)
39772
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
897
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
898 self.assertEqual(f.revision(node1), stored1)
42778
22e74b5aa59d rawdata: update callers in testing/storage.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 40430
diff changeset
899 self.assertEqual(f.rawdata(node1), stored1)
39772
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
900
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
901 self.assertEqual(f.read(node0), fulltext0)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
902 self.assertEqual(f.read(node1), fulltext1)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
903
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
904 self.assertFalse(f.cmp(node0, fulltext0))
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
905 self.assertTrue(f.cmp(node0, stored0))
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
906
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
907 self.assertFalse(f.cmp(node1, fulltext1))
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
908 self.assertTrue(f.cmp(node1, stored0))
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
909
40051
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
910 def testbadnoderead(self):
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
911 f = self._makefilefn()
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
912
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
913 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
914 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
915
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
916 with self._maketransactionfn() as tr:
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
917 node0 = f.add(fulltext0, None, tr, 0, f.nullid, f.nullid)
40051
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
918 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
919
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
920 self._addrawrevisionfn(
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
921 f, tr, node1, node0, f.nullid, 1, rawtext=fulltext1
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
922 )
40051
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
923
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
924 self.assertEqual(len(f), 2)
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
925 self.assertEqual(f.parents(node1), (node0, f.nullid))
40051
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
926
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
927 # 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
928 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
929 f.revision(node1)
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
930
42778
22e74b5aa59d rawdata: update callers in testing/storage.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 40430
diff changeset
931 # rawdata() still verifies because there are no special storage
40054
801ccd8e67c0 revlog: clear revision cache on hash verification failure
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40051
diff changeset
932 # settings.
801ccd8e67c0 revlog: clear revision cache on hash verification failure
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40051
diff changeset
933 with self.assertRaises(error.StorageError):
42778
22e74b5aa59d rawdata: update callers in testing/storage.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 40430
diff changeset
934 f.rawdata(node1)
40051
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
935
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
936 # read() behaves like revision().
40054
801ccd8e67c0 revlog: clear revision cache on hash verification failure
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40051
diff changeset
937 with self.assertRaises(error.StorageError):
801ccd8e67c0 revlog: clear revision cache on hash verification failure
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40051
diff changeset
938 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
939
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
940 # 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
941 # 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
942
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
943 def testbadnoderevisionraw(self):
42778
22e74b5aa59d rawdata: update callers in testing/storage.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 40430
diff changeset
944 # Like above except we test rawdata() first to isolate
40051
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
945 # revision caching behavior.
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
946 f = self._makefilefn()
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
947
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
948 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
949 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
950
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
951 with self._maketransactionfn() as tr:
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
952 node0 = f.add(fulltext0, None, tr, 0, f.nullid, f.nullid)
40051
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
953 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
954
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
955 self._addrawrevisionfn(
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
956 f, tr, node1, node0, f.nullid, 1, rawtext=fulltext1
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
957 )
40051
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 with self.assertRaises(error.StorageError):
42778
22e74b5aa59d rawdata: update callers in testing/storage.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 40430
diff changeset
960 f.rawdata(node1)
40051
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
961
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
962 with self.assertRaises(error.StorageError):
42778
22e74b5aa59d rawdata: update callers in testing/storage.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 40430
diff changeset
963 f.rawdata(node1)
40051
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
964
44024
a1ee825fc6c5 tests: fix a copy/paste name duplication in storage.py
Matt Harbison <matt_harbison@yahoo.com>
parents: 43506
diff changeset
965 def testbadnoderevision(self):
40051
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
966 # 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
967 # behavior.
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
968 f = self._makefilefn()
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
969
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
970 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
971 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
972
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
973 with self._maketransactionfn() as tr:
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
974 node0 = f.add(fulltext0, None, tr, 0, f.nullid, f.nullid)
40051
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
975 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
976
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
977 self._addrawrevisionfn(
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
978 f, tr, node1, node0, f.nullid, 1, rawtext=fulltext1
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
979 )
40051
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
980
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
981 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
982 f.read(node1)
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
983
40054
801ccd8e67c0 revlog: clear revision cache on hash verification failure
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40051
diff changeset
984 with self.assertRaises(error.StorageError):
801ccd8e67c0 revlog: clear revision cache on hash verification failure
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40051
diff changeset
985 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
986
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
987 def testbadnodedelta(self):
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
988 f = self._makefilefn()
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
989
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
990 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
991 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
992 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
993
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
994 with self._maketransactionfn() as tr:
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
995 node0 = f.add(fulltext0, None, tr, 0, f.nullid, f.nullid)
40051
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
996 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
997
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
998 self._addrawrevisionfn(
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
999 f, tr, node1, node0, f.nullid, 1, rawtext=fulltext1
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
1000 )
40051
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 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
1003 f.read(node1)
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
1004
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
1005 node2 = storageutil.hashrevisionsha1(fulltext2, node1, f.nullid)
40051
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
1006
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
1007 with self._maketransactionfn() as tr:
40323
2c0aa02ecd5a testing: switch to inserting deltas
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40322
diff changeset
1008 delta = mdiff.textdiff(fulltext1, fulltext2)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
1009 self._addrawrevisionfn(
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
1010 f, tr, node2, node1, f.nullid, 2, delta=(1, delta)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
1011 )
40051
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
1012
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
1013 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
1014
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
1015 # 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
1016 # 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
1017 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
1018
39772
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1019 def testcensored(self):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1020 f = self._makefilefn()
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1021
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45788
diff changeset
1022 stored1 = storageutil.packmeta(
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45788
diff changeset
1023 {
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45788
diff changeset
1024 b'censored': b'tombstone',
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45788
diff changeset
1025 },
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45788
diff changeset
1026 b'',
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45788
diff changeset
1027 )
39772
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1028
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1029 with self._maketransactionfn() as tr:
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
1030 node0 = f.add(b'foo', None, tr, 0, f.nullid, f.nullid)
40051
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
1031
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
1032 # 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
1033 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
1034
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
1035 self._addrawrevisionfn(
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
1036 f, tr, node1, node0, f.nullid, 1, stored1, censored=True
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
1037 )
39772
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1038
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1039 self.assertTrue(f.iscensored(1))
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1040
40051
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
1041 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
1042 f.revision(1)
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
1043
40054
801ccd8e67c0 revlog: clear revision cache on hash verification failure
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40051
diff changeset
1044 with self.assertRaises(error.CensoredNodeError):
42778
22e74b5aa59d rawdata: update callers in testing/storage.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 40430
diff changeset
1045 f.rawdata(1)
39772
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1046
40051
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
1047 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
1048 f.read(1)
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
1049
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
1050 def testcensoredrawrevision(self):
42778
22e74b5aa59d rawdata: update callers in testing/storage.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 40430
diff changeset
1051 # Like above, except we do the rawdata() request first to
40051
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
1052 # 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
1053
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
1054 f = self._makefilefn()
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
1055
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45788
diff changeset
1056 stored1 = storageutil.packmeta(
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45788
diff changeset
1057 {
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45788
diff changeset
1058 b'censored': b'tombstone',
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45788
diff changeset
1059 },
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45788
diff changeset
1060 b'',
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45788
diff changeset
1061 )
40051
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
1062
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
1063 with self._maketransactionfn() as tr:
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
1064 node0 = f.add(b'foo', None, tr, 0, f.nullid, f.nullid)
40051
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
1065
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
1066 # 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
1067 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
1068
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
1069 self._addrawrevisionfn(
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
1070 f, tr, node1, node0, f.nullid, 1, stored1, censored=True
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
1071 )
40051
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
1072
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
1073 with self.assertRaises(error.CensoredNodeError):
42778
22e74b5aa59d rawdata: update callers in testing/storage.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 40430
diff changeset
1074 f.rawdata(1)
39772
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1075
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
1076
39772
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1077 class ifilemutationtests(basetestcase):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1078 """Generic tests for the ifilemutation interface.
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1079
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1080 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
1081 interface.
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1082
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1083 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
1084 """
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
1085
39772
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1086 def testaddnoop(self):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1087 f = self._makefilefn()
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1088 with self._maketransactionfn() as tr:
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
1089 node0 = f.add(b'foo', None, tr, 0, f.nullid, f.nullid)
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
1090 node1 = f.add(b'foo', None, tr, 0, f.nullid, f.nullid)
39772
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1091 # Varying by linkrev shouldn't impact hash.
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
1092 node2 = f.add(b'foo', None, tr, 1, f.nullid, f.nullid)
39772
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1093
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1094 self.assertEqual(node1, node0)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1095 self.assertEqual(node2, node0)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1096 self.assertEqual(len(f), 1)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1097
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1098 def testaddrevisionbadnode(self):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1099 f = self._makefilefn()
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1100 with self._maketransactionfn() as tr:
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1101 # Adding a revision with bad node value fails.
39776
cb65d4b7e429 error: introduce StorageError
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39772
diff changeset
1102 with self.assertRaises(error.StorageError):
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
1103 f.addrevision(
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
1104 b'foo', tr, 0, f.nullid, f.nullid, node=b'\x01' * 20
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
1105 )
39772
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 def testaddrevisionunknownflag(self):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1108 f = self._makefilefn()
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 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
1111 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
1112 flags = 1 << i
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1113 break
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1114
39776
cb65d4b7e429 error: introduce StorageError
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39772
diff changeset
1115 with self.assertRaises(error.StorageError):
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
1116 f.addrevision(b'foo', tr, 0, f.nullid, f.nullid, flags=flags)
39772
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 def testaddgroupsimple(self):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1119 f = self._makefilefn()
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1120
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1121 callbackargs = []
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
1122
39772
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1123 def cb(*args, **kwargs):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1124 callbackargs.append((args, kwargs))
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1125
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1126 def linkmapper(node):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1127 return 0
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1128
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1129 with self._maketransactionfn() as tr:
45788
a5206e71c536 revlog: extend addgroup() with callback for duplicates
Joerg Sonnenberger <joerg@bec.de>
parents: 44024
diff changeset
1130 nodes = []
a5206e71c536 revlog: extend addgroup() with callback for duplicates
Joerg Sonnenberger <joerg@bec.de>
parents: 44024
diff changeset
1131
46509
7a93b7b3dc2d revlog: change addgroup callbacks to take revision numbers
Joerg Sonnenberger <joerg@bec.de>
parents: 45942
diff changeset
1132 def onchangeset(cl, rev):
7a93b7b3dc2d revlog: change addgroup callbacks to take revision numbers
Joerg Sonnenberger <joerg@bec.de>
parents: 45942
diff changeset
1133 node = cl.node(rev)
45788
a5206e71c536 revlog: extend addgroup() with callback for duplicates
Joerg Sonnenberger <joerg@bec.de>
parents: 44024
diff changeset
1134 nodes.append(node)
a5206e71c536 revlog: extend addgroup() with callback for duplicates
Joerg Sonnenberger <joerg@bec.de>
parents: 44024
diff changeset
1135 cb(cl, node)
a5206e71c536 revlog: extend addgroup() with callback for duplicates
Joerg Sonnenberger <joerg@bec.de>
parents: 44024
diff changeset
1136
46509
7a93b7b3dc2d revlog: change addgroup callbacks to take revision numbers
Joerg Sonnenberger <joerg@bec.de>
parents: 45942
diff changeset
1137 def ondupchangeset(cl, rev):
7a93b7b3dc2d revlog: change addgroup callbacks to take revision numbers
Joerg Sonnenberger <joerg@bec.de>
parents: 45942
diff changeset
1138 nodes.append(cl.node(rev))
45788
a5206e71c536 revlog: extend addgroup() with callback for duplicates
Joerg Sonnenberger <joerg@bec.de>
parents: 44024
diff changeset
1139
a5206e71c536 revlog: extend addgroup() with callback for duplicates
Joerg Sonnenberger <joerg@bec.de>
parents: 44024
diff changeset
1140 f.addgroup(
a5206e71c536 revlog: extend addgroup() with callback for duplicates
Joerg Sonnenberger <joerg@bec.de>
parents: 44024
diff changeset
1141 [],
a5206e71c536 revlog: extend addgroup() with callback for duplicates
Joerg Sonnenberger <joerg@bec.de>
parents: 44024
diff changeset
1142 None,
a5206e71c536 revlog: extend addgroup() with callback for duplicates
Joerg Sonnenberger <joerg@bec.de>
parents: 44024
diff changeset
1143 tr,
a5206e71c536 revlog: extend addgroup() with callback for duplicates
Joerg Sonnenberger <joerg@bec.de>
parents: 44024
diff changeset
1144 addrevisioncb=onchangeset,
a5206e71c536 revlog: extend addgroup() with callback for duplicates
Joerg Sonnenberger <joerg@bec.de>
parents: 44024
diff changeset
1145 duplicaterevisioncb=ondupchangeset,
a5206e71c536 revlog: extend addgroup() with callback for duplicates
Joerg Sonnenberger <joerg@bec.de>
parents: 44024
diff changeset
1146 )
39772
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1147
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1148 self.assertEqual(nodes, [])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1149 self.assertEqual(callbackargs, [])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1150 self.assertEqual(len(f), 0)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1151
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1152 fulltext0 = b'foo'
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1153 delta0 = mdiff.trivialdiffheader(len(fulltext0)) + fulltext0
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1154
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1155 with self._maketransactionfn() as tr:
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
1156 node0 = f.add(fulltext0, None, tr, 0, f.nullid, f.nullid)
39772
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1157
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1158 f = self._makefilefn()
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1159
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1160 deltas = [
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
1161 (node0, f.nullid, f.nullid, f.nullid, f.nullid, delta0, 0, {}),
39772
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1162 ]
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1163
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1164 with self._maketransactionfn() as tr:
45788
a5206e71c536 revlog: extend addgroup() with callback for duplicates
Joerg Sonnenberger <joerg@bec.de>
parents: 44024
diff changeset
1165 nodes = []
a5206e71c536 revlog: extend addgroup() with callback for duplicates
Joerg Sonnenberger <joerg@bec.de>
parents: 44024
diff changeset
1166
46509
7a93b7b3dc2d revlog: change addgroup callbacks to take revision numbers
Joerg Sonnenberger <joerg@bec.de>
parents: 45942
diff changeset
1167 def onchangeset(cl, rev):
7a93b7b3dc2d revlog: change addgroup callbacks to take revision numbers
Joerg Sonnenberger <joerg@bec.de>
parents: 45942
diff changeset
1168 node = cl.node(rev)
45788
a5206e71c536 revlog: extend addgroup() with callback for duplicates
Joerg Sonnenberger <joerg@bec.de>
parents: 44024
diff changeset
1169 nodes.append(node)
a5206e71c536 revlog: extend addgroup() with callback for duplicates
Joerg Sonnenberger <joerg@bec.de>
parents: 44024
diff changeset
1170 cb(cl, node)
a5206e71c536 revlog: extend addgroup() with callback for duplicates
Joerg Sonnenberger <joerg@bec.de>
parents: 44024
diff changeset
1171
46509
7a93b7b3dc2d revlog: change addgroup callbacks to take revision numbers
Joerg Sonnenberger <joerg@bec.de>
parents: 45942
diff changeset
1172 def ondupchangeset(cl, rev):
7a93b7b3dc2d revlog: change addgroup callbacks to take revision numbers
Joerg Sonnenberger <joerg@bec.de>
parents: 45942
diff changeset
1173 nodes.append(cl.node(rev))
45788
a5206e71c536 revlog: extend addgroup() with callback for duplicates
Joerg Sonnenberger <joerg@bec.de>
parents: 44024
diff changeset
1174
a5206e71c536 revlog: extend addgroup() with callback for duplicates
Joerg Sonnenberger <joerg@bec.de>
parents: 44024
diff changeset
1175 f.addgroup(
a5206e71c536 revlog: extend addgroup() with callback for duplicates
Joerg Sonnenberger <joerg@bec.de>
parents: 44024
diff changeset
1176 deltas,
a5206e71c536 revlog: extend addgroup() with callback for duplicates
Joerg Sonnenberger <joerg@bec.de>
parents: 44024
diff changeset
1177 linkmapper,
a5206e71c536 revlog: extend addgroup() with callback for duplicates
Joerg Sonnenberger <joerg@bec.de>
parents: 44024
diff changeset
1178 tr,
a5206e71c536 revlog: extend addgroup() with callback for duplicates
Joerg Sonnenberger <joerg@bec.de>
parents: 44024
diff changeset
1179 addrevisioncb=onchangeset,
a5206e71c536 revlog: extend addgroup() with callback for duplicates
Joerg Sonnenberger <joerg@bec.de>
parents: 44024
diff changeset
1180 duplicaterevisioncb=ondupchangeset,
a5206e71c536 revlog: extend addgroup() with callback for duplicates
Joerg Sonnenberger <joerg@bec.de>
parents: 44024
diff changeset
1181 )
39772
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1182
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
1183 self.assertEqual(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
1184 nodes,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
1185 [
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
1186 b'\x49\xd8\xcb\xb1\x5c\xe2\x57\x92\x04\x47'
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
1187 b'\x00\x6b\x46\x97\x8b\x7a\xf9\x80\xa9\x79'
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
1188 ],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
1189 )
39772
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1190
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1191 self.assertEqual(len(callbackargs), 1)
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1192 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
1193
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1194 self.assertEqual(list(f.revs()), [0])
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1195 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
1196 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
1197
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1198 def testaddgroupmultiple(self):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1199 f = self._makefilefn()
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1200
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1201 fulltexts = [
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1202 b'foo',
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1203 b'bar',
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1204 b'x' * 1024,
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1205 ]
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1206
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1207 nodes = []
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1208 with self._maketransactionfn() as tr:
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1209 for fulltext in fulltexts:
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
1210 nodes.append(f.add(fulltext, None, tr, 0, f.nullid, f.nullid))
39772
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1211
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1212 f = self._makefilefn()
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1213 deltas = []
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1214 for i, fulltext in enumerate(fulltexts):
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1215 delta = mdiff.trivialdiffheader(len(fulltext)) + fulltext
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1216
46712
e8c11a2c96c0 delta: add sidedata field to revision delta
Raphaël Gomès <rgomes@octobus.net>
parents: 46509
diff changeset
1217 deltas.append(
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
1218 (nodes[i], f.nullid, f.nullid, f.nullid, f.nullid, delta, 0, {})
46712
e8c11a2c96c0 delta: add sidedata field to revision delta
Raphaël Gomès <rgomes@octobus.net>
parents: 46509
diff changeset
1219 )
39772
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1220
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1221 with self._maketransactionfn() as tr:
45788
a5206e71c536 revlog: extend addgroup() with callback for duplicates
Joerg Sonnenberger <joerg@bec.de>
parents: 44024
diff changeset
1222 newnodes = []
a5206e71c536 revlog: extend addgroup() with callback for duplicates
Joerg Sonnenberger <joerg@bec.de>
parents: 44024
diff changeset
1223
46509
7a93b7b3dc2d revlog: change addgroup callbacks to take revision numbers
Joerg Sonnenberger <joerg@bec.de>
parents: 45942
diff changeset
1224 def onchangeset(cl, rev):
7a93b7b3dc2d revlog: change addgroup callbacks to take revision numbers
Joerg Sonnenberger <joerg@bec.de>
parents: 45942
diff changeset
1225 newnodes.append(cl.node(rev))
45788
a5206e71c536 revlog: extend addgroup() with callback for duplicates
Joerg Sonnenberger <joerg@bec.de>
parents: 44024
diff changeset
1226
a5206e71c536 revlog: extend addgroup() with callback for duplicates
Joerg Sonnenberger <joerg@bec.de>
parents: 44024
diff changeset
1227 f.addgroup(
a5206e71c536 revlog: extend addgroup() with callback for duplicates
Joerg Sonnenberger <joerg@bec.de>
parents: 44024
diff changeset
1228 deltas,
a5206e71c536 revlog: extend addgroup() with callback for duplicates
Joerg Sonnenberger <joerg@bec.de>
parents: 44024
diff changeset
1229 lambda x: 0,
a5206e71c536 revlog: extend addgroup() with callback for duplicates
Joerg Sonnenberger <joerg@bec.de>
parents: 44024
diff changeset
1230 tr,
a5206e71c536 revlog: extend addgroup() with callback for duplicates
Joerg Sonnenberger <joerg@bec.de>
parents: 44024
diff changeset
1231 addrevisioncb=onchangeset,
a5206e71c536 revlog: extend addgroup() with callback for duplicates
Joerg Sonnenberger <joerg@bec.de>
parents: 44024
diff changeset
1232 duplicaterevisioncb=onchangeset,
a5206e71c536 revlog: extend addgroup() with callback for duplicates
Joerg Sonnenberger <joerg@bec.de>
parents: 44024
diff changeset
1233 )
a5206e71c536 revlog: extend addgroup() with callback for duplicates
Joerg Sonnenberger <joerg@bec.de>
parents: 44024
diff changeset
1234 self.assertEqual(newnodes, nodes)
39772
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1235
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1236 self.assertEqual(len(f), len(deltas))
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1237 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
1238 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
1239 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
1240 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
1241 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
1242 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
1243 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
1244
40051
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
1245 def testdeltaagainstcensored(self):
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
1246 # 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
1247 f = self._makefilefn()
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
1248
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45788
diff changeset
1249 stored1 = storageutil.packmeta(
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45788
diff changeset
1250 {
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45788
diff changeset
1251 b'censored': b'tombstone',
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45788
diff changeset
1252 },
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45788
diff changeset
1253 b'',
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45788
diff changeset
1254 )
40051
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
1255
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
1256 with self._maketransactionfn() as tr:
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
1257 node0 = f.add(b'foo\n' * 30, None, tr, 0, f.nullid, f.nullid)
40051
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
1258
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
1259 # 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
1260 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
1261
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
1262 self._addrawrevisionfn(
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
1263 f, tr, node1, node0, f.nullid, 1, stored1, censored=True
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
1264 )
40051
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
1265
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
1266 delta = mdiff.textdiff(b'bar\n' * 30, (b'bar\n' * 30) + b'baz\n')
46712
e8c11a2c96c0 delta: add sidedata field to revision delta
Raphaël Gomès <rgomes@octobus.net>
parents: 46509
diff changeset
1267 deltas = [
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
1268 (b'\xcc' * 20, node1, f.nullid, b'\x01' * 20, node1, delta, 0, {})
46712
e8c11a2c96c0 delta: add sidedata field to revision delta
Raphaël Gomès <rgomes@octobus.net>
parents: 46509
diff changeset
1269 ]
40051
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
1270
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
1271 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
1272 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
1273 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
1274
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
1275 def testcensorrevisionbasic(self):
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
1276 f = self._makefilefn()
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
1277
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
1278 with self._maketransactionfn() as tr:
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
1279 node0 = f.add(b'foo\n' * 30, None, tr, 0, f.nullid, f.nullid)
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
1280 node1 = f.add(b'foo\n' * 31, None, tr, 1, node0, f.nullid)
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
1281 node2 = f.add(b'foo\n' * 32, None, tr, 2, node1, f.nullid)
40051
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
1282
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
1283 with self._maketransactionfn() as tr:
51270
ceeb8fa23cc8 censor: accept multiple revision in a single call
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50929
diff changeset
1284 f.censorrevision(tr, [node1])
40051
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
1285
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
1286 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
1287 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
1288
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
1289 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
1290 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
1291
40056
324b4b10351e revlog: rewrite censoring logic
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40054
diff changeset
1292 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
1293 f.read(node1)
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
1294
40050
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
1295 def testgetstrippointnoparents(self):
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
1296 # 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
1297 f = self._makefilefn()
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
1298
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
1299 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
1300 for rev in range(10):
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
1301 f.add(b'%d' % rev, None, tr, rev, f.nullid, f.nullid)
40050
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
1302
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
1303 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
1304 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
1305
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
1306 def testgetstrippointlinear(self):
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
1307 # 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
1308 f = self._makefilefn()
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
1309
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
1310 with self._maketransactionfn() as tr:
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
1311 p1 = f.nullid
40050
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
1312
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
1313 for rev in range(10):
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
1314 f.add(b'%d' % rev, None, tr, rev, p1, f.nullid)
40050
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
1315
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
1316 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
1317 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
1318
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
1319 def testgetstrippointmultipleheads(self):
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
1320 f = self._makefilefn()
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
1321
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
1322 with self._maketransactionfn() as tr:
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
1323 node0 = f.add(b'0', None, tr, 0, f.nullid, f.nullid)
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
1324 node1 = f.add(b'1', None, tr, 1, node0, f.nullid)
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
1325 f.add(b'2', None, tr, 2, node1, f.nullid)
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
1326 f.add(b'3', None, tr, 3, node0, f.nullid)
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
1327 f.add(b'4', None, tr, 4, node0, f.nullid)
40050
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
1328
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
1329 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
1330 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
1331
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
1332 def testgetstrippointearlierlinkrevs(self):
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
1333 f = self._makefilefn()
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
1334
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
1335 with self._maketransactionfn() as tr:
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
1336 node0 = f.add(b'0', None, tr, 0, f.nullid, f.nullid)
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
1337 f.add(b'1', None, tr, 10, node0, f.nullid)
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
1338 f.add(b'2', None, tr, 5, node0, f.nullid)
40050
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
1339
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
1340 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
1341 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
1342 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
1343 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
1344 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
1345 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
1346 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
1347 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
1348 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
1349 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
1350 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
1351 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
1352
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
1353 def teststripempty(self):
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
1354 f = self._makefilefn()
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
1355
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
1356 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
1357 f.strip(0, tr)
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
1358
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
1359 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
1360
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
1361 def teststripall(self):
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
1362 f = self._makefilefn()
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
1363
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
1364 with self._maketransactionfn() as tr:
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
1365 p1 = f.nullid
40050
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
1366 for rev in range(10):
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
1367 p1 = f.add(b'%d' % rev, None, tr, rev, p1, f.nullid)
40050
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
1368
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
1369 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
1370
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
1371 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
1372 f.strip(0, tr)
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
1373
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
1374 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
1375
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
1376 def teststrippartial(self):
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
1377 f = self._makefilefn()
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
1378
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
1379 with self._maketransactionfn() as tr:
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
1380 f.add(b'0', None, tr, 0, f.nullid, f.nullid)
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
1381 node1 = f.add(b'1', None, tr, 5, f.nullid, f.nullid)
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46712
diff changeset
1382 node2 = f.add(b'2', None, tr, 10, f.nullid, f.nullid)
40050
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
1383
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
1384 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
1385
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
1386 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
1387 f.strip(11, tr)
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
1388
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
1389 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
1390
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
1391 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
1392 f.strip(10, tr)
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
1393
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
1394 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
1395
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
1396 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
1397 f.rev(node2)
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
1398
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
1399 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
1400 f.strip(6, tr)
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
1401
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
1402 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
1403
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
1404 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
1405 f.strip(3, tr)
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
1406
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
1407 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
1408
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
1409 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
1410 f.rev(node1)
8e136940c0e6 testing: add file storage tests for getstrippoint() and strip()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40047
diff changeset
1411
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
1412
40051
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
1413 def makeifileindextests(makefilefn, maketransactionfn, addrawrevisionfn):
39772
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1414 """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
1415
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1416 ``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
1417 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
1418
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1419 ``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
1420 argument and returns a transaction object.
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1421
40051
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
1422 ``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
1423 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
1424 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
1425
39772
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1426 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
1427 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
1428 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
1429 should find and run it automatically.
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1430 """
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1431 d = {
43506
9f70512ae2cf cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents: 43103
diff changeset
1432 '_makefilefn': makefilefn,
9f70512ae2cf cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents: 43103
diff changeset
1433 '_maketransactionfn': maketransactionfn,
9f70512ae2cf cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents: 43103
diff changeset
1434 '_addrawrevisionfn': addrawrevisionfn,
39772
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1435 }
43506
9f70512ae2cf cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents: 43103
diff changeset
1436 return type('ifileindextests', (ifileindextests,), d)
39772
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1437
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
1438
40051
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
1439 def makeifiledatatests(makefilefn, maketransactionfn, addrawrevisionfn):
39772
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1440 d = {
43506
9f70512ae2cf cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents: 43103
diff changeset
1441 '_makefilefn': makefilefn,
9f70512ae2cf cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents: 43103
diff changeset
1442 '_maketransactionfn': maketransactionfn,
9f70512ae2cf cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents: 43103
diff changeset
1443 '_addrawrevisionfn': addrawrevisionfn,
39772
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1444 }
43506
9f70512ae2cf cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents: 43103
diff changeset
1445 return type('ifiledatatests', (ifiledatatests,), d)
39772
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1446
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42813
diff changeset
1447
40051
cdf61ab1f54c testing: add file storage integration for bad hashes and censoring
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40050
diff changeset
1448 def makeifilemutationtests(makefilefn, maketransactionfn, addrawrevisionfn):
39772
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1449 d = {
43506
9f70512ae2cf cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents: 43103
diff changeset
1450 '_makefilefn': makefilefn,
9f70512ae2cf cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents: 43103
diff changeset
1451 '_maketransactionfn': maketransactionfn,
9f70512ae2cf cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents: 43103
diff changeset
1452 '_addrawrevisionfn': addrawrevisionfn,
39772
ae531f5e583c testing: add interface unit tests for file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1453 }
43506
9f70512ae2cf cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents: 43103
diff changeset
1454 return type('ifilemutationtests', (ifilemutationtests,), d)