def run(self): """See `IRunnableJob`.""" self.checkReady() if self.branch_merge_proposal.source_branch is not None: server_context = server(get_ro_server(), no_replace=True) else: # A no-op context manager. (This could be simplified with # contextlib.ExitStack from Python 3.3.) server_context = contextmanager(lambda: (None for _ in [None]))() # Update related bug links based on commits in the source branch. self.branch_merge_proposal.updateRelatedBugsFromSource() with server_context: with BranchMergeProposalDelta.monitor(self.branch_merge_proposal): PreviewDiff.fromBranchMergeProposal(self.branch_merge_proposal)
def test_fromBranchMergeProposal_does_not_warn_on_conflicts(self): """PreviewDiff generation emits no conflict warnings.""" reload(trace) bmp, source_rev_id, target_rev_id = self.createExampleMerge() handler = RecordLister() logger = logging.getLogger('bzr') logger.addHandler(handler) try: PreviewDiff.fromBranchMergeProposal(bmp) self.assertEqual(handler.records, []) # check that our handler would normally intercept warnings. trace.warning('foo!') self.assertNotEqual(handler.records, []) finally: logger.removeHandler(handler)
def test_fromBranchMergeProposal(self): # Correctly generates a PreviewDiff from a BranchMergeProposal. bmp, source_rev_id, target_rev_id = self.createExampleMerge() preview = PreviewDiff.fromBranchMergeProposal(bmp) self.assertEqual(source_rev_id, preview.source_revision_id) self.assertEqual(target_rev_id, preview.target_revision_id) transaction.commit() self.checkExampleMerge(preview.text) self.assertEqual({'foo': (5, 0)}, preview.diffstat)
def test_fromBranchMergeProposal_with_prerequisite(self): # Correctly generates a PreviewDiff from a BranchMergeProposal. prerequisite_branch = self.factory.makeProductBranch() bmp = self.factory.makeBranchMergeProposal( prerequisite_branch=prerequisite_branch) self.preparePrerequisiteMerge(bmp) preview = PreviewDiff.fromBranchMergeProposal(bmp) transaction.commit() self.assertIn('+source text\n', preview.text) self.assertNotIn('+prerequisite text\n', preview.text)
def test_fromPreviewDiff_with_no_conflicts(self): """Test fromPreviewDiff when no conflicts are present.""" self.useBzrBranches(direct_database=True) bmp = self.factory.makeBranchMergeProposal() bzr_target = self.createBzrBranch(bmp.target_branch) commit_file(bmp.target_branch, 'foo', 'a\n') self.createBzrBranch(bmp.source_branch, bzr_target) commit_file(bmp.source_branch, 'foo', 'a\nb\n') commit_file(bmp.target_branch, 'foo', 'c\na\n') diff = PreviewDiff.fromBranchMergeProposal(bmp) self.assertEqual('', diff.conflicts) self.assertFalse(diff.has_conflicts)
def test_fromBranchMergeProposal_sets_conflicts(self): """Conflicts are set on the PreviewDiff.""" bmp, source_rev_id, target_rev_id = self.createExampleMerge() preview = PreviewDiff.fromBranchMergeProposal(bmp) self.assertEqual('Text conflict in foo\n', preview.conflicts) self.assertTrue(preview.has_conflicts)
def run(self): """See `IRunnableJob`.""" self.checkReady() with server(get_ro_server(), no_replace=True): with BranchMergeProposalDelta.monitor(self.branch_merge_proposal): PreviewDiff.fromBranchMergeProposal(self.branch_merge_proposal)
def test_fromBranchMergeProposalForGit_sets_conflicts(self): # Conflicts are set on the PreviewDiff. bmp, source_rev_id, target_rev_id, _ = self.createExampleGitMerge() preview = PreviewDiff.fromBranchMergeProposal(bmp) self.assertEqual('Conflict in foo\n', preview.conflicts) self.assertTrue(preview.has_conflicts)