示例#1
0
    def test(self):
        # Check handling of a single patch...
        patches = cros_patch.PrepareRemotePatches([self.MkRemote()])
        self.assertEqual(len(patches), 1)
        self.assertRemote(patches[0])

        # Check handling of a multiple...
        patches = cros_patch.PrepareRemotePatches(
            [self.MkRemote(), self.MkRemote(project='foon')])
        self.assertEqual(len(patches), 2)
        self.assertRemote(patches[0])
        self.assertRemote(patches[1], project='foon')

        # Ensure basic validation occurs:
        chunks = self.MkRemote().split(':')
        self.assertRaises(ValueError, cros_patch.PrepareRemotePatches,
                          ':'.join(chunks[:-1]))
        self.assertRaises(ValueError, cros_patch.PrepareRemotePatches,
                          ':'.join(chunks[:-1] + ['monkeys']))
        self.assertRaises(ValueError, cros_patch.PrepareRemotePatches,
                          ':'.join(chunks + [':']))
示例#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)