[hgext] add a new "start-test" command (closes #291697)

authorDavid Douard <david.douard@logilab.fr>
changeset714c89c4fdca
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#1497d79f4547 [hgext] make show-review able to display apycot test results (closes #291700)
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 714c89c4fdca0762f2e020fe4c57f48547ef7c6e
# Parent 5bed420e8c98b098494c596239ff7a3b0624c69e
[hgext] add a new "start-test" command (closes #291697)

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,43 @@
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 +    ('o', 'option', [], _("options to add to the TestExecution"), _('OPTIONS')),
23 +    ]  + cnxopts,
24 +    _('[OPTION]... [-r] REV...'))
25 +def runapycot(ui, repo, *changesets, **opts):
26 +    """start Apycot tests for the given revisions.
27 +
28 +    By default, the revision used is the parent of the working
29 +    directory: use -r/--rev to specify a different revision.
30 +
31 +    """
32 +    changesets += tuple(opts.get('rev', []))
33 +    if not changesets:
34 +        changesets = ('.')
35 +    revs = scmutil.revrange(repo, changesets)
36 +    if not revs:
37 +        raise util.Abort(_('no working directory: please specify a revision'))
38 +    ctxhexs = [node.short(repo.lookup(rev)) for rev in revs]
39 +    label = opts.get('label', 'quick python tests')
40 +    options = dict(o.split('=') for o in opts.get('option', []))
41 +    
42 +    with build_proxy(ui, opts) as client:
43 +        results = create_test_execution(client, ctxhexs, label, **options)
44 +        rset = [x[0][0] if x else None for x in results]
45 +        if all(rset):
46 +            ui.write('OK ({})\n'.format(', '.join(str(eid) for eid in rset)))
47 +        else:
48 +            if any(rset):
49 +                ui.write('PARTIAL ({})\n'.format(', '.join(str(eid)
50 +                                                  for eid in rset if eid)))
51 +            else:
52 +                ui.write('FAILED\n')
53 +            failed = (cset for cset, result in zip(ctxhexs, rset) if not result)
54 +            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,29 @@
55 +#!/usr/bin/python
56 +# -*- coding: utf-8
57 +
58 +START_TE_RQL = """\
59 +INSERT TestExecution TE:
60 +  TE branch %(changeset)s,
61 +  TE using_environment PE,
62 +  TE using_config TC,
63 +  TE execution_of R
64 +WHERE
65 +  TC use_recipe R,
66 +  PE local_repository REPO,
67 +  CS from_repository REPO,
68 +  CS changeset %(changeset)s ,
69 +  TC label %(label)s
70 +"""
71 +
72 +def create_test_execution(client, changesets, label, **kwargs):
73 +    rql = START_TE_RQL
74 +    args = {'label': label}
75 +    if kwargs:
76 +        options = u'\n'.join(u"%s=%s" % kv for kv in kwargs.items())
77 +        rql1, rql2 = rql.split('WHERE')
78 +        rql = '{0}, TE options %(options)s WHERE {1}'.format(rql1, rql2)
79 +        args['options'] = options
80 +
81 +    queries = [(rql, dict(changeset=cs, **args))
82 +               for cs in changesets]
83 +    return client.rqlio(queries)