# HG changeset patch # User Gregory Szorc # Date 2014-05-05 05:48:07 # Node ID 51e5c793a9f4d873b494422076914621c3b3ee1f # Parent d2ce7a20fe8610ebc068acdbba25eb45d6931d75 tests: declare commands using decorator diff --git a/tests/autodiff.py b/tests/autodiff.py --- a/tests/autodiff.py +++ b/tests/autodiff.py @@ -1,8 +1,14 @@ # Extension dedicated to test patch.diff() upgrade modes # # -from mercurial import scmutil, patch, util +from mercurial import cmdutil, scmutil, patch, util +cmdtable = {} +command = cmdutil.command(cmdtable) + +@command('autodiff', + [('', 'git', '', 'git upgrade mode (yes/no/auto/warn/abort)')], + '[OPTION]... [FILE]...') def autodiff(ui, repo, *pats, **opts): diffopts = patch.diffopts(ui, opts) git = opts.get('git', 'no') @@ -36,11 +42,3 @@ def autodiff(ui, repo, *pats, **opts): ui.write(chunk) for fn in sorted(brokenfiles): ui.write(('data lost for: %s\n' % fn)) - -cmdtable = { - "autodiff": - (autodiff, - [('', 'git', '', 'git upgrade mode (yes/no/auto/warn/abort)'), - ], - '[OPTION]... [FILE]...'), -} diff --git a/tests/test-encoding-align.t b/tests/test-encoding-align.t --- a/tests/test-encoding-align.t +++ b/tests/test-encoding-align.t @@ -16,19 +16,18 @@ Test alignment of multibyte characters > f = file('l', 'w'); f.write(l); f.close() > # instant extension to show list of options > f = file('showoptlist.py', 'w'); f.write("""# encoding: utf-8 + > from mercurial import cmdutil + > cmdtable = {} + > command = cmdutil.command(cmdtable) + > + > @command('showoptlist', + > [('s', 'opt1', '', 'short width' + ' %(s)s' * 8, '%(s)s'), + > ('m', 'opt2', '', 'middle width' + ' %(m)s' * 8, '%(m)s'), + > ('l', 'opt3', '', 'long width' + ' %(l)s' * 8, '%(l)s')], + > '') > def showoptlist(ui, repo, *pats, **opts): > '''dummy command to show option descriptions''' > return 0 - > cmdtable = { - > 'showoptlist': - > (showoptlist, - > [('s', 'opt1', '', 'short width' + ' %(s)s' * 8, '%(s)s'), - > ('m', 'opt2', '', 'middle width' + ' %(m)s' * 8, '%(m)s'), - > ('l', 'opt3', '', 'long width' + ' %(l)s' * 8, '%(l)s') - > ], - > "" - > ) - > } > """ % globals()) > f.close() > EOF diff --git a/tests/test-encoding-textwrap.t b/tests/test-encoding-textwrap.t --- a/tests/test-encoding-textwrap.t +++ b/tests/test-encoding-textwrap.t @@ -6,7 +6,13 @@ Test text wrapping for multibyte charact define commands to display help text $ cat << EOF > show.py + > from mercurial import cmdutil + > + > cmdtable = {} + > command = cmdutil.command(cmdtable) + > > # Japanese full-width characters: + > @command('show_full_ja', [], '') > def show_full_ja(ui, **opts): > u'''\u3042\u3044\u3046\u3048\u304a\u304b\u304d\u304f\u3051 \u3042\u3044\u3046\u3048\u304a\u304b\u304d\u304f\u3051 \u3042\u3044\u3046\u3048\u304a\u304b\u304d\u304f\u3051 > @@ -16,6 +22,7 @@ define commands to display help text > ''' > > # Japanese half-width characters: + > @command('show_half_ja', [], '') > def show_half_ja(ui, *opts): > u'''\uff71\uff72\uff73\uff74\uff75\uff76\uff77\uff78\uff79 \uff71\uff72\uff73\uff74\uff75\uff76\uff77\uff78\uff79 \uff71\uff72\uff73\uff74\uff75\uff76\uff77\uff78\uff79 \uff71\uff72\uff73\uff74\uff75\uff76\uff77\uff78\uff79 > @@ -25,6 +32,7 @@ define commands to display help text > ''' > > # Japanese ambiguous-width characters: + > @command('show_ambig_ja', [], '') > def show_ambig_ja(ui, **opts): > u'''\u03b1\u03b2\u03b3\u03b4\u03c5\u03b6\u03b7\u03b8\u25cb \u03b1\u03b2\u03b3\u03b4\u03c5\u03b6\u03b7\u03b8\u25cb \u03b1\u03b2\u03b3\u03b4\u03c5\u03b6\u03b7\u03b8\u25cb > @@ -34,6 +42,7 @@ define commands to display help text > ''' > > # Russian ambiguous-width characters: + > @command('show_ambig_ru', [], '') > def show_ambig_ru(ui, **opts): > u'''\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 > @@ -41,13 +50,6 @@ define commands to display help text > > \u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 > ''' - > - > cmdtable = { - > 'show_full_ja': (show_full_ja, [], ""), - > 'show_half_ja': (show_half_ja, [], ""), - > 'show_ambig_ja': (show_ambig_ja, [], ""), - > 'show_ambig_ru': (show_ambig_ru, [], ""), - > } > EOF "COLUMNS=60" means that there is no lines which has grater than 58 width diff --git a/tests/test-extension.t b/tests/test-extension.t --- a/tests/test-extension.t +++ b/tests/test-extension.t @@ -2,7 +2,10 @@ Test basic extension support $ cat > foobar.py < import os - > from mercurial import commands + > from mercurial import cmdutil, commands + > + > cmdtable = {} + > command = cmdutil.command(cmdtable) > > def uisetup(ui): > ui.write("uisetup called\\n") @@ -11,17 +14,14 @@ Test basic extension support > ui.write("reposetup called for %s\\n" % os.path.basename(repo.root)) > ui.write("ui %s= repo.ui\\n" % (ui == repo.ui and "=" or "!")) > + > @command('foo', [], 'hg foo') > def foo(ui, *args, **kwargs): > ui.write("Foo\\n") > + > @command('bar', [], 'hg bar') > def bar(ui, *args, **kwargs): > ui.write("Bar\\n") > - > cmdtable = { - > "foo": (foo, [], "hg foo"), - > "bar": (bar, [], "hg bar"), - > } - > > commands.norepo += ' bar' > EOF $ abspath=`pwd`/foobar.py @@ -288,21 +288,22 @@ hide outer repo $ cat > debugextension.py < '''only debugcommands > ''' + > from mercurial import cmdutil + > cmdtable = {} + > command = cmdutil.command(cmdtable) + > + > @command('debugfoobar', [], 'hg debugfoobar') > def debugfoobar(ui, repo, *args, **opts): > "yet another debug command" > pass > + > @command('foo', [], 'hg foo') > def foo(ui, repo, *args, **opts): > """yet another foo command > > This command has been DEPRECATED since forever. > """ > pass - > - > cmdtable = { - > "debugfoobar": (debugfoobar, (), "hg debugfoobar"), - > "foo": (foo, (), "hg foo") - > } > EOF $ debugpath=`pwd`/debugextension.py $ echo "debugextension = $debugpath" >> $HGRCPATH @@ -475,15 +476,15 @@ Extension module help vs command help: Test help topic with same name as extension $ cat > multirevs.py < from mercurial import commands + > from mercurial import cmdutil, commands + > cmdtable = {} + > command = cmdutil.command(cmdtable) > """multirevs extension > Big multi-line module docstring.""" + > @command('multirevs', [], 'ARG') > def multirevs(ui, repo, arg, *args, **opts): > """multirevs command""" > pass - > cmdtable = { - > "multirevs": (multirevs, [], 'ARG') - > } > commands.norepo += ' multirevs' > EOF $ echo "multirevs = multirevs.py" >> $HGRCPATH @@ -532,13 +533,15 @@ Issue811: Problem loading extensions twi $ cat > debugissue811.py < '''show all loaded extensions > ''' - > from mercurial import extensions, commands + > from mercurial import cmdutil, commands, extensions + > cmdtable = {} + > command = cmdutil.command(cmdtable) > + > @command('debugextensions', [], 'hg debugextensions') > def debugextensions(ui): > "yet another debug command" > ui.write("%s\n" % '\n'.join([x for x, y in extensions.extensions()])) > - > cmdtable = {"debugextensions": (debugextensions, (), "hg debugextensions")} > commands.norepo += " debugextensions" > EOF $ echo "debugissue811 = $debugpath" >> $HGRCPATH diff --git a/tests/test-help.t b/tests/test-help.t --- a/tests/test-help.t +++ b/tests/test-help.t @@ -652,19 +652,20 @@ Test command without options $ cat > helpext.py < import os - > from mercurial import commands + > from mercurial import cmdutil, commands + > + > cmdtable = {} + > command = cmdutil.command(cmdtable) > + > @command('nohelp', + > [('', 'longdesc', 3, 'x'*90), + > ('n', '', None, 'normal desc'), + > ('', 'newline', '', 'line1\nline2')], + > 'hg nohelp') + > @command('debugoptDEP', [('', 'dopt', None, 'option is DEPRECATED')]) > def nohelp(ui, *args, **kwargs): > pass > - > cmdtable = { - > "debugoptDEP": (nohelp, [('', 'dopt', None, 'option is DEPRECATED')],), - > "nohelp": (nohelp, [('', 'longdesc', 3, 'x'*90), - > ('n', '', None, 'normal desc'), - > ('', 'newline', '', 'line1\nline2'), - > ], "hg nohelp"), - > } - > > commands.norepo += ' nohelp' > EOF $ echo '[extensions]' >> $HGRCPATH diff --git a/tests/test-progress.t b/tests/test-progress.t --- a/tests/test-progress.t +++ b/tests/test-progress.t @@ -1,7 +1,11 @@ $ cat > loop.py < from mercurial import commands + > from mercurial import cmdutil, commands > import time + > + > cmdtable = {} + > command = cmdutil.command(cmdtable) + > > class incrementingtime(object): > def __init__(self): > self._time = 0.0 @@ -10,6 +14,11 @@ > return self._time > time.time = incrementingtime() > + > @command('loop', + > [('', 'total', '', 'override for total'), + > ('', 'nested', False, 'show nested results'), + > ('', 'parallel', False, 'show parallel sets of results')], + > 'hg loop LOOPS') > def loop(ui, loops, **opts): > loops = int(loops) > total = None @@ -38,14 +47,6 @@ > ui.progress('loop', None, 'loop.done', 'loopnum', total) > > commands.norepo += " loop" - > - > cmdtable = { - > "loop": (loop, [('', 'total', '', 'override for total'), - > ('', 'nested', False, 'show nested results'), - > ('', 'parallel', False, 'show parallel sets of results'), - > ], - > 'hg loop LOOPS'), - > } > EOF $ cp $HGRCPATH $HGRCPATH.orig