def setUp(self): super(TestCaseWithCorruptRepository, self).setUp() # a inventory with no parents and the revision has parents.. # i.e. a ghost. repo = self.make_repository('inventory_with_unnecessary_ghost') repo.lock_write() repo.start_write_group() inv = inventory.Inventory(revision_id=b'ghost') inv.root.revision = b'ghost' if repo.supports_rich_root(): root_id = inv.root.file_id repo.texts.add_lines((root_id, b'ghost'), [], []) sha1 = repo.add_inventory(b'ghost', inv, []) rev = _mod_revision.Revision(timestamp=0, timezone=None, committer="Foo Bar <*****@*****.**>", message="Message", inventory_sha1=sha1, revision_id=b'ghost') rev.parent_ids = [b'the_ghost'] try: repo.add_revision(b'ghost', rev) except (errors.NoSuchRevision, errors.RevisionNotPresent): raise tests.TestNotApplicable( "Cannot test with ghosts for this format.") inv = inventory.Inventory(revision_id=b'the_ghost') inv.root.revision = b'the_ghost' if repo.supports_rich_root(): root_id = inv.root.file_id repo.texts.add_lines((root_id, b'the_ghost'), [], []) sha1 = repo.add_inventory(b'the_ghost', inv, []) rev = _mod_revision.Revision(timestamp=0, timezone=None, committer="Foo Bar <*****@*****.**>", message="Message", inventory_sha1=sha1, revision_id=b'the_ghost') rev.parent_ids = [] repo.add_revision(b'the_ghost', rev) # check its setup usefully inv_weave = repo.inventories possible_parents = (None, ((b'ghost', ), )) self.assertSubset( inv_weave.get_parent_map([(b'ghost', )])[(b'ghost', )], possible_parents) repo.commit_write_group() repo.unlock()
def create_branch_with_ghost_text(self): builder = self.make_branch_builder('ghost') builder.build_snapshot( None, [('add', ('', b'root-id', 'directory', None)), ('add', ('a', b'a-file-id', 'file', b'some content\n'))], revision_id=b'A-id') b = builder.get_branch() old_rt = b.repository.revision_tree(b'A-id') new_inv = inventory.mutable_inventory_from_tree(old_rt) new_inv.revision_id = b'B-id' new_inv.get_entry(b'a-file-id').revision = b'ghost-id' new_rev = _mod_revision.Revision( b'B-id', timestamp=time.time(), timezone=0, message='Committing against a ghost', committer='Joe Foo <*****@*****.**>', properties={}, parent_ids=(b'A-id', b'ghost-id'), ) b.lock_write() self.addCleanup(b.unlock) b.repository.start_write_group() b.repository.add_revision(b'B-id', new_rev, new_inv) self.disable_commit_write_group_paranoia(b.repository) b.repository.commit_write_group() return b
def test_add_revision_inventory_sha1(self): inv = inventory.Inventory(revision_id=b'A') inv.root.revision = b'A' inv.root.file_id = b'fixed-root' # Insert the inventory on its own to an identical repository, to get # its sha1. reference_repo = self.make_repository('reference_repo') reference_repo.lock_write() reference_repo.start_write_group() inv_sha1 = reference_repo.add_inventory(b'A', inv, []) reference_repo.abort_write_group() reference_repo.unlock() # Now insert a revision with this inventory, and it should get the same # sha1. repo = self.make_repository('repo') repo.lock_write() repo.start_write_group() root_id = inv.root.file_id repo.texts.add_lines((b'fixed-root', b'A'), [], []) repo.add_revision(b'A', _mod_revision.Revision(b'A', committer='B', timestamp=0, timezone=0, message='C'), inv=inv) repo.commit_write_group() repo.unlock() repo.lock_read() self.assertEqual(inv_sha1, repo.get_revision(b'A').inventory_sha1) repo.unlock()
def test_get_apparent_authors(self): r = revision.Revision('1') r.committer = 'A' self.assertEqual(['A'], r.get_apparent_authors()) r.properties[u'author'] = 'B' self.assertEqual(['B'], r.get_apparent_authors()) r.properties[u'authors'] = 'C\nD' self.assertEqual(['C', 'D'], r.get_apparent_authors())
def test_get_summary(self): r = revision.Revision('1') r.message = 'a' self.assertEqual('a', r.get_summary()) r.message = 'a\nb' self.assertEqual('a', r.get_summary()) r.message = '\na\nb' self.assertEqual('a', r.get_summary()) r.message = None self.assertEqual('', r.get_summary())
def test_some_bugs(self): r = revision.Revision('1', properties={ u'bugs': bugtracker.encode_fixes_bug_urls([ ('http://example.com/bugs/1', 'fixed'), ('http://launchpad.net/bugs/1234', 'fixed') ]) }) self.assertEqual( [('http://example.com/bugs/1', bugtracker.FIXED), ('http://launchpad.net/bugs/1234', bugtracker.FIXED)], list(r.iter_bugs()))
def test_invalid_status(self): r = revision.Revision( '1', properties={u'bugs': 'http://example.com/bugs/1 faxed'}) self.assertRaises(bugtracker.InvalidBugStatus, list, r.iter_bugs())
def test_too_much_information(self): r = revision.Revision( '1', properties={u'bugs': 'http://example.com/bugs/1 fixed bar'}) self.assertRaises(bugtracker.InvalidLineInBugsProperty, list, r.iter_bugs())
def test_no_status(self): r = revision.Revision( '1', properties={u'bugs': 'http://example.com/bugs/1'}) self.assertRaises(bugtracker.InvalidLineInBugsProperty, list, r.iter_bugs())
def test_no_bugs(self): r = revision.Revision('1') self.assertEqual([], list(r.iter_bugs()))
def test_get_apparent_authors_no_committer(self): r = revision.Revision('1') self.assertEqual([], r.get_apparent_authors())