48 |
48 |
49 Algorithmic correctness is asserted by the Rust unit tests. |
49 Algorithmic correctness is asserted by the Rust unit tests. |
50 """ |
50 """ |
51 |
51 |
52 def testiteratorrevlist(self): |
52 def testiteratorrevlist(self): |
53 idx = self.parseindex() |
53 idx = self.parserustindex() |
54 # checking test assumption about the index binary data: |
54 # checking test assumption about the index binary data: |
55 self.assertEqual( |
55 self.assertEqual( |
56 {i: (r[5], r[6]) for i, r in enumerate(idx)}, |
56 {i: (r[5], r[6]) for i, r in enumerate(idx)}, |
57 {0: (-1, -1), 1: (0, -1), 2: (1, -1), 3: (2, -1)}, |
57 {0: (-1, -1), 1: (0, -1), 2: (1, -1), 3: (2, -1)}, |
58 ) |
58 ) |
61 |
61 |
62 ait = AncestorsIterator(idx, [3], 0, False) |
62 ait = AncestorsIterator(idx, [3], 0, False) |
63 self.assertEqual([r for r in ait], [2, 1, 0]) |
63 self.assertEqual([r for r in ait], [2, 1, 0]) |
64 |
64 |
65 def testlazyancestors(self): |
65 def testlazyancestors(self): |
66 idx = self.parseindex() |
66 idx = self.parserustindex() |
67 start_count = sys.getrefcount(idx) # should be 2 (see Python doc) |
67 start_count = sys.getrefcount(idx) # should be 2 (see Python doc) |
68 self.assertEqual( |
68 self.assertEqual( |
69 {i: (r[5], r[6]) for i, r in enumerate(idx)}, |
69 {i: (r[5], r[6]) for i, r in enumerate(idx)}, |
70 {0: (-1, -1), 1: (0, -1), 2: (1, -1), 3: (2, -1)}, |
70 {0: (-1, -1), 1: (0, -1), 2: (1, -1), 3: (2, -1)}, |
71 ) |
71 ) |
108 revs = {0, 1, 2, 3} |
108 revs = {0, 1, 2, 3} |
109 missanc.removeancestorsfrom(revs) |
109 missanc.removeancestorsfrom(revs) |
110 self.assertEqual(revs, {2, 3}) |
110 self.assertEqual(revs, {2, 3}) |
111 |
111 |
112 def testrefcount(self): |
112 def testrefcount(self): |
113 idx = self.parseindex() |
113 idx = self.parserustindex() |
114 start_count = sys.getrefcount(idx) |
114 start_count = sys.getrefcount(idx) |
115 |
115 |
116 # refcount increases upon iterator init... |
116 # refcount increases upon iterator init... |
117 ait = AncestorsIterator(idx, [3], 0, True) |
117 ait = AncestorsIterator(idx, [3], 0, True) |
118 self.assertEqual(sys.getrefcount(idx), start_count + 1) |
118 self.assertEqual(sys.getrefcount(idx), start_count + 1) |
125 # and removing ref to the index after iterator init is no issue |
125 # and removing ref to the index after iterator init is no issue |
126 ait = AncestorsIterator(idx, [3], 0, True) |
126 ait = AncestorsIterator(idx, [3], 0, True) |
127 del idx |
127 del idx |
128 self.assertEqual(list(ait), [3, 2, 1, 0]) |
128 self.assertEqual(list(ait), [3, 2, 1, 0]) |
129 |
129 |
|
130 # the index is not tracked by the GC, hence there is nothing more |
|
131 # we can assert to check that it is properly deleted once its refcount |
|
132 # drops to 0 |
|
133 |
130 def testgrapherror(self): |
134 def testgrapherror(self): |
131 data = ( |
135 data = ( |
132 revlogtesting.data_non_inlined[: 64 + 27] |
136 revlogtesting.data_non_inlined[: 64 + 27] |
133 + b'\xf2' |
137 + b'\xf2' |
134 + revlogtesting.data_non_inlined[64 + 28 :] |
138 + revlogtesting.data_non_inlined[64 + 28 :] |
135 ) |
139 ) |
136 idx = cparsers.parse_index2(data, False)[0] |
140 idx = self.parserustindex(data=data) |
137 with self.assertRaises(rustext.GraphError) as arc: |
141 with self.assertRaises(rustext.GraphError) as arc: |
138 AncestorsIterator(idx, [1], -1, False) |
142 AncestorsIterator(idx, [1], -1, False) |
139 exc = arc.exception |
143 exc = arc.exception |
140 self.assertIsInstance(exc, ValueError) |
144 self.assertIsInstance(exc, ValueError) |
141 # rust-cpython issues appropriate str instances for Python 2 and 3 |
145 # rust-cpython issues appropriate str instances for Python 2 and 3 |
142 self.assertEqual(exc.args, ('ParentOutOfRange', 1)) |
146 self.assertEqual(exc.args, ('ParentOutOfRange', 1)) |
143 |
147 |
144 def testwdirunsupported(self): |
148 def testwdirunsupported(self): |
145 # trying to access ancestors of the working directory raises |
149 # trying to access ancestors of the working directory raises |
146 idx = self.parseindex() |
150 idx = self.parserustindex() |
147 with self.assertRaises(rustext.GraphError) as arc: |
151 with self.assertRaises(rustext.GraphError) as arc: |
148 list(AncestorsIterator(idx, [wdirrev], -1, False)) |
152 list(AncestorsIterator(idx, [wdirrev], -1, False)) |
149 |
153 |
150 exc = arc.exception |
154 exc = arc.exception |
151 self.assertIsInstance(exc, ValueError) |
155 self.assertIsInstance(exc, ValueError) |