[hgext] add a new "start-test" command

authorDavid Douard <david.douard@logilab.fr>
changeset9073ca7274f5
branchdefault
phasedraft
hiddenyes
parent revision#5bed420e8c98 Added tag logilab-devtools-version-0.24.0, logilab-devtools-debian-version-0.24.0-1 for changeset 17078cc48fc0
child revision#044f54d4ea5e [hgext] make show-review able to display apycot test results
files modified by this revision
hgext/jpl/__init__.py
hgext/jpl/apycot.py
# HG changeset patch
# User David Douard <david.douard@logilab.fr>
# Date 1428621492 -7200
# Fri Apr 10 01:18:12 2015 +0200
# Node ID 9073ca7274f5b0eb3226ea6e9b7a449bdb63fe9b
# Parent 5bed420e8c98b098494c596239ff7a3b0624c69e
[hgext] add a new "start-test" command

diff --git a/hgext/jpl/__init__.py b/hgext/jpl/__init__.py
@@ -55,10 +55,11 @@
1      enabled = demandimport._import is __import__
2  demandimport.disable()
3  from .jplproxy import build_proxy, RequestError
4  from .tasks import print_tasks
5  from .review import ask_review, show_review, sudo_make_me_a_ticket
6 +from .apycot import create_test_execution
7  if enabled:
8      demandimport.enable()
9 
10  cmdtable = {}
11  command = cmdutil.command(cmdtable)
@@ -316,5 +317,39 @@
12 
13      with build_proxy(ui, opts) as client:
14          for rev in revs:
15              ticket = sudo_make_me_a_ticket(client, repo, rev, opts.get('done_in', ''))
16              ui.write("{0} {1}\n".format(rev, ticket[0][0]))
17 +
18 +
19 +@command('^start-test', [
20 +    ('r', 'rev', [], _('start apycot tests on the given revision(s)'), _('REV')),
21 +    ('l', 'label', 'quick python tests', _("the TestConfig's label to execute"), _('LABEL')),
22 +    ]  + cnxopts,
23 +    _('[OPTION]... [-r] REV...'))
24 +def runapycot(ui, repo, *changesets, **opts):
25 +    """start Apycot tests for the given revisions.
26 +
27 +    By default, the revision used is the parent of the working
28 +    directory: use -r/--rev to specify a different revision.
29 +
30 +    """
31 +    changesets += tuple(opts.get('rev', []))
32 +    if not changesets:
33 +        changesets = ('.')
34 +    revs = scmutil.revrange(repo, changesets)
35 +    if not revs:
36 +        raise util.Abort(_('no working directory: please specify a revision'))
37 +    ctxhexs = [node.short(repo.lookup(rev)) for rev in revs]
38 +    label = opts.get('label', 'quick python tests')
39 +    with build_proxy(ui, opts) as client:
40 +        results = create_test_execution(client, ctxhexs, label)
41 +        rset = [x[0][0] if x else None for x in results]
42 +        if all(rset):
43 +            ui.write('OK\n')
44 +        else:
45 +            if any(rset):
46 +                ui.write('PARTIAL\n')
47 +            else:
48 +                ui.write('FAILED\n')
49 +            failed = (cset for cset, result in zip(ctxhexs, rset) if not result)
50 +            ui.write('  could not create tests for {}\n'.format(', '.join(failed)))
diff --git a/hgext/jpl/apycot.py b/hgext/jpl/apycot.py
@@ -0,0 +1,21 @@
51 +#!/usr/bin/python
52 +# -*- coding: utf-8
53 +
54 +START_TE_RQL = """
55 +INSERT TestExecution TE:
56 +  TE branch %(changeset)s,
57 +  TE using_environment PE,
58 +  TE using_config TC,
59 +  TE execution_of R
60 +WHERE
61 +  TC use_recipe R,
62 +  PE local_repository REPO,
63 +  CS from_repository REPO,
64 +  CS changeset %(changeset)s ,
65 +  TC label %(label)s
66 +"""
67 +
68 +def create_test_execution(client, changesets, label):
69 +    queries = [(START_TE_RQL, {'changeset': cs, 'label': label})
70 +               for cs in changesets]
71 +    return client.rqlio(queries)