Esempio n. 1
0
 def PrepareLocalPatches(self, output):
   """Check the returned GitRepoPatchInfo against golden values."""
   output_obj = mock.MagicMock()
   output_obj.output = output
   self.PatchObject(cros_patch.LocalPatch, 'Fetch', return_value=output_obj)
   self.PatchObject(git, 'RunGit', return_value=output_obj)
   patch_info = cros_patch.PrepareLocalPatches(self.manifest, self.patches)[0]
   self.assertEquals(patch_info.project, self.project)
   self.assertEquals(patch_info.ref, self.branch)
   self.assertEquals(patch_info.tracking_branch, self.tracking_branch)
Esempio n. 2
0
    def FromOptions(cls,
                    gerrit_patches=None,
                    local_patches=None,
                    sourceroot=None,
                    remote_patches=None):
        """Generate patch objects from passed in options.

    Args:
      gerrit_patches: Gerrit ids that gerrit.GetGerritPatchInfo accepts.
      local_patches: Local ids that cros_patch.PrepareLocalPatches accepts.
      sourceroot: The source repository to look up |local_patches|.
      remote_patches: Remote ids that cros_patch.PrepareRemotePatches accepts.

    Returns:
      A TrybotPatchPool object.

    Raises:
      gerrit.GerritException, cros_patch.PatchException
    """
        if gerrit_patches:
            gerrit_patches = gerrit.GetGerritPatchInfo(gerrit_patches)
            for patch in gerrit_patches:
                if patch.IsAlreadyMerged():
                    logging.warning('Patch %s has already been merged.', patch)
        else:
            gerrit_patches = ()

        if local_patches:
            manifest = git.ManifestCheckout.Cached(sourceroot)
            local_patches = cros_patch.PrepareLocalPatches(
                manifest, local_patches)
        else:
            local_patches = ()

        if remote_patches:
            remote_patches = cros_patch.PrepareRemotePatches(remote_patches)
        else:
            remote_patches = ()

        return cls(gerrit_patches=gerrit_patches,
                   local_patches=local_patches,
                   remote_patches=remote_patches)
Esempio n. 3
0
    def testBranchSpecifiedSuccessRun(self):
        """Test success with branch specified by user."""
        output_obj = self.mox.CreateMock(cros_build_lib.CommandResult)
        output_obj.output = '12345'.rjust(40, '0')
        self.manifest.GetProjectPath('my/project', True).AndReturn('mydir')
        self.manifest.GetProjectsLocalRevision('my/project').AndReturn(
            'm/kernel')
        self.manifest.GetAttributeForProject('my/project',
                                             'remote').AndReturn('cros')
        git.RunGit('mydir', mox.In('m/kernel..mybranch')).AndReturn(output_obj)

        # Suppress the normal parse machinery.
        self.mox.StubOutWithMock(cros_patch.LocalPatch, 'Fetch')
        # pylint: disable=E1120
        cros_patch.LocalPatch.Fetch('mydir/.git').AndReturn(output_obj)
        self.mox.ReplayAll()

        patch_info = cros_patch.PrepareLocalPatches(self.manifest,
                                                    self.patches)
        self.VerifyPatchInfo(patch_info[0], 'my/project', 'mybranch', 'kernel')
        self.mox.VerifyAll()