/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/tests/per_repository/test_fetch.py

  • Committer: Breezy landing bot
  • Author(s): Jelmer Vernooij
  • Date: 2018-11-16 18:59:44 UTC
  • mfrom: (7143.15.15 more-cleanups)
  • Revision ID: breezy.the.bot@gmail.com-20181116185944-biefv1sub37qfybm
Sprinkle some PEP8iness.

Merged from https://code.launchpad.net/~jelmer/brz/more-cleanups/+merge/358611

Show diffs side-by-side

added added

removed removed

Lines of Context:
46
46
        # fetch with a default limit (grab everything)
47
47
        repo = self.make_repository('b')
48
48
        if (tree_a.branch.repository.supports_rich_root() and not
49
 
            repo.supports_rich_root()):
 
49
                repo.supports_rich_root()):
50
50
            raise TestSkipped('Cannot fetch from model2 to model1')
51
51
        repo.fetch(tree_a.branch.repository,
52
52
                   revision_id=None)
97
97
                tree_b = b_branch.create_checkout('b', lightweight=True)
98
98
            except errors.NotLocalUrl:
99
99
                raise TestSkipped("cannot make working tree with transport %r"
100
 
                              % b_bzrdir.transport)
 
100
                                  % b_bzrdir.transport)
101
101
        rev2 = tree_b.commit('no change')
102
102
        rev2_tree = knit3_repo.revision_tree(rev2)
103
103
        self.assertEqual(rev1, rev2_tree.get_file_revision(u''))
104
104
 
105
105
    def do_test_fetch_to_rich_root_sets_parents_correctly(self, result,
106
 
        snapshots, root_id=ROOT_ID, allow_lefthand_ghost=False):
 
106
                                                          snapshots, root_id=ROOT_ID, allow_lefthand_ghost=False):
107
107
        """Assert that result is the parents of b'tip' after fetching snapshots.
108
108
 
109
109
        This helper constructs a 1.9 format source, and a test-format target
120
120
        repo = self.make_repository('target')
121
121
        remote_format = isinstance(repo, remote.RemoteRepository)
122
122
        if not repo._format.rich_root_data and not remote_format:
123
 
            return # not relevant
 
123
            return  # not relevant
124
124
        if not repo._format.supports_full_versioned_files:
125
125
            raise TestNotApplicable(
126
126
                'format does not support full versioned files')
128
128
        builder.start_series()
129
129
        for revision_id, parent_ids, actions in snapshots:
130
130
            builder.build_snapshot(parent_ids, actions,
131
 
            allow_leftmost_as_ghost=allow_lefthand_ghost,
132
 
            revision_id=revision_id)
 
131
                                   allow_leftmost_as_ghost=allow_lefthand_ghost,
 
132
                                   revision_id=revision_id)
133
133
        builder.finish_series()
134
134
        source = builder.get_branch()
135
135
        if remote_format and not repo._format.rich_root_data:
136
136
            # use a manual rich root format to ensure the code path is tested.
137
137
            repo = self.make_repository('remote-target',
138
 
                format='1.9-rich-root')
 
138
                                        format='1.9-rich-root')
139
139
        repo.lock_write()
140
140
        self.addCleanup(repo.unlock)
141
141
        repo.fetch(source.repository)
142
142
        graph = repo.get_file_graph()
143
143
        self.assertEqual(result,
144
 
            graph.get_parent_map([(root_id, b'tip')])[(root_id, b'tip')])
 
144
                         graph.get_parent_map([(root_id, b'tip')])[(root_id, b'tip')])
145
145
 
146
146
    def test_fetch_to_rich_root_set_parent_no_parents(self):
147
147
        # No parents rev -> No parents
148
148
        self.do_test_fetch_to_rich_root_sets_parents_correctly((),
149
 
            [(b'tip', None, [('add', ('', ROOT_ID, 'directory', ''))]),
150
 
            ])
 
149
                                                               [(b'tip', None, [('add', ('', ROOT_ID, 'directory', ''))]),
 
150
                                                                ])
151
151
 
152
152
    def test_fetch_to_rich_root_set_parent_1_parent(self):
153
153
        # 1 parent rev -> 1 parent
155
155
            ((ROOT_ID, b'base'),),
156
156
            [(b'base', None, [('add', ('', ROOT_ID, 'directory', ''))]),
157
157
             (b'tip', None, []),
158
 
            ])
 
158
             ])
159
159
 
160
160
    def test_fetch_to_rich_root_set_parent_1_ghost_parent(self):
161
161
        # 1 ghost parent -> No parents
162
162
        if not self.repository_format.supports_ghosts:
163
163
            raise TestNotApplicable("repository format does not support "
164
 
                 "ghosts")
 
164
                                    "ghosts")
165
165
        self.do_test_fetch_to_rich_root_sets_parents_correctly((),
166
 
            [(b'tip', [b'ghost'], [('add', ('', ROOT_ID, 'directory', ''))]),
167
 
            ], allow_lefthand_ghost=True)
 
166
                                                               [(b'tip', [b'ghost'], [('add', ('', ROOT_ID, 'directory', ''))]),
 
167
                                                                ], allow_lefthand_ghost=True)
168
168
 
169
169
    def test_fetch_to_rich_root_set_parent_2_head_parents(self):
170
170
        # 2 parents both heads -> 2 parents
174
174
             (b'left', None, []),
175
175
             (b'right', [b'base'], []),
176
176
             (b'tip', [b'left', b'right'], []),
177
 
            ])
 
177
             ])
178
178
 
179
179
    def test_fetch_to_rich_root_set_parent_2_parents_1_head(self):
180
180
        # 2 parents one head -> 1 parent
183
183
            [(b'left', None, [('add', ('', ROOT_ID, 'directory', ''))]),
184
184
             (b'right', None, []),
185
185
             (b'tip', [b'left', b'right'], []),
186
 
            ])
 
186
             ])
187
187
 
188
188
    def test_fetch_to_rich_root_set_parent_1_parent_different_id_gone(self):
189
189
        # 1 parent different fileid, ours missing -> no parents
191
191
            (),
192
192
            [(b'base', None, [('add', ('', ROOT_ID, 'directory', ''))]),
193
193
             (b'tip', None, [('unversion', ''),
194
 
                            ('add', ('', b'my-root', 'directory', '')),
195
 
                            ]),
196
 
            ], root_id=b'my-root')
 
194
                             ('add', ('', b'my-root', 'directory', '')),
 
195
                             ]),
 
196
             ], root_id=b'my-root')
197
197
 
198
198
    def test_fetch_to_rich_root_set_parent_1_parent_different_id_moved(self):
199
199
        # 1 parent different fileid, ours moved -> 1 parent
201
201
        self.do_test_fetch_to_rich_root_sets_parents_correctly(
202
202
            ((b'my-root', b'origin'),),
203
203
            [(b'origin', None, [('add', ('', ROOT_ID, 'directory', '')),
204
 
                             ('add', ('child', b'my-root', 'directory', ''))]),
 
204
                                ('add', ('child', b'my-root', 'directory', ''))]),
205
205
             (b'base', None, []),
206
206
             (b'tip', None, [('unversion', 'child'),
207
 
                            ('unversion', ''),
208
 
                            ('flush', None),
209
 
                            ('add', ('', b'my-root', 'directory', '')),
210
 
                            ]),
211
 
            ], root_id=b'my-root')
 
207
                             ('unversion', ''),
 
208
                             ('flush', None),
 
209
                             ('add', ('', b'my-root', 'directory', '')),
 
210
                             ]),
 
211
             ], root_id=b'my-root')
212
212
 
213
213
    def test_fetch_to_rich_root_set_parent_2_parent_1_different_id_gone(self):
214
214
        # 2 parents, 1 different fileid, our second missing -> 1 parent
216
216
            ((b'my-root', b'right'),),
217
217
            [(b'base', None, [('add', ('', ROOT_ID, 'directory', ''))]),
218
218
             (b'right', None, [('unversion', ''),
219
 
                              ('add', ('', b'my-root', 'directory', ''))]),
 
219
                               ('add', ('', b'my-root', 'directory', ''))]),
220
220
             (b'tip', [b'base', b'right'], [('unversion', ''),
221
 
                            ('add', ('', b'my-root', 'directory', '')),
222
 
                            ]),
223
 
            ], root_id=b'my-root')
 
221
                                            ('add', ('', b'my-root', 'directory', '')),
 
222
                                            ]),
 
223
             ], root_id=b'my-root')
224
224
 
225
225
    def test_fetch_to_rich_root_set_parent_2_parent_2_different_id_moved(self):
226
226
        # 2 parents, 1 different fileid, our second moved -> 2 parent
229
229
            ((b'my-root', b'right'),),
230
230
            # b'my-root' at 'child'.
231
231
            [(b'origin', None, [('add', ('', ROOT_ID, 'directory', '')),
232
 
                             ('add', ('child', b'my-root', 'directory', ''))]),
 
232
                                ('add', ('child', b'my-root', 'directory', ''))]),
233
233
             (b'base', None, []),
234
 
            # b'my-root' at root
 
234
             # b'my-root' at root
235
235
             (b'right', None, [('unversion', 'child'),
236
 
                              ('unversion', ''),
237
 
                              ('flush', None),
238
 
                              ('add', ('', b'my-root', 'directory', ''))]),
 
236
                               ('unversion', ''),
 
237
                               ('flush', None),
 
238
                               ('add', ('', b'my-root', 'directory', ''))]),
239
239
             (b'tip', [b'base', b'right'], [('unversion', ''),
240
 
                            ('unversion', 'child'),
241
 
                            ('flush', None),
242
 
                            ('add', ('', b'my-root', 'directory', '')),
243
 
                            ]),
244
 
            ], root_id=b'my-root')
 
240
                                            ('unversion', 'child'),
 
241
                                            ('flush', None),
 
242
                                            ('add', ('', b'my-root', 'directory', '')),
 
243
                                            ]),
 
244
             ], root_id=b'my-root')
245
245
 
246
246
    def test_fetch_all_from_self(self):
247
247
        tree = self.make_branch_and_tree('.')
278
278
            repo.sign_revision(rev1, gpg.LoopbackGPGStrategy(None))
279
279
        except errors.UnsupportedOperation:
280
280
            self.assertFalse(repo._format.supports_revision_signatures)
281
 
            raise TestNotApplicable("repository format does not support signatures")
 
281
            raise TestNotApplicable(
 
282
                "repository format does not support signatures")
282
283
        repo.commit_write_group()
283
284
        repo.unlock()
284
285
        return repo, rev1
318
319
    def make_simple_branch_with_ghost(self):
319
320
        if not self.repository_format.supports_ghosts:
320
321
            raise TestNotApplicable("repository format does not support "
321
 
                 "ghosts")
 
322
                                    "ghosts")
322
323
        builder = self.make_branch_builder('source')
323
324
        builder.start_series()
324
325
        a_revid = builder.build_snapshot(None, [
355
356
            # causes weird problems with 'lock_not_held' later on...
356
357
            target.lock_read()
357
358
            self.knownFailure('some repositories fail to fetch'
358
 
                ' via the smart server because of locking issues.')
 
359
                              ' via the smart server because of locking issues.')
359
360
 
360
361
    def test_fetch_from_smart_with_ghost(self):
361
362
        trans = self.make_smart_server('source')
370
371
        source.lock_read()
371
372
        self.addCleanup(source.unlock)
372
373
        target.fetch(source, revision_id=b_revid)
373