On Thu, 2009-04-16 at 22:28 +0000, Robert Collins wrote:
> On Thu, 2009-04-16 at 20:30 +0000, James Westby wrote:
> > Hi,
> >
> > Having a better solution for this would be great, but with the help of
> > jam and vila I just knocked this up:
> >
> > if __name__ == '__main__':
>
> ug.
>
> from bzrlib import option, commands
> commands.Command.hooks.install_named_hook('extend_command',
> test_coverage, 'test_plugin')
>
>
> def test_plugin(cmd):
> if cmd.name() != 'selftest':
> return
> def handle_test_plugin(option, name, value, parser):
> cmd.additional_selftest_args['starting_with'] = \
> 'bzrlib.plugins.%s' % value
> cmd.takes_options = list(cmd.takes_options)
> cmd.takes_options.append(
> option.Option('test-plugin',
> help='Run tests for a single named plugin',
> custom_callback=handle_test_plugin))
Thanks,
However, as far as I can see this doesn't cover all the things
that I need to make this useful.
Allow me to be more explicit about the requirements that I have.
I have written the following hook:
import os
import shutil
import subprocess
import tempfile
from bzrlib import (
branch,
errors,
export,
trace,
)
branch.Branch.hooks.install_named_hook('pre_change_branch_tip', run_test_suite_hook, "Check the testsuite passes before the "
"change is made.")
which looks for a configuration option giving the command to run to
validate the commit, for a poor-man's PQM for my local work.
I'd like to use this for my bzr plugins, however the usual way
I test those is "bzr selftest -s bp.<plugin name>". However,
that requires the tree I am committing is the one that bzr will
load, which isn't always going to be the case. In particular,
the above code exports to a temporary directory to run the tests,
so it won't be something loaded by bzr.
So, I need a way to run the tests for a plugin, but also pass
an arbitrary filesystem location to use the tests from, and have
the plugin appear as the correct name to bzr.
My code does this by setting BZR_PLUGIN_PATH based on __file__,
so that it will always be testing the code that you are running
it from, as well as a symlink to get it to appear as the correct
name, regardless of the directory name.
Running the particular tests of a plugins isn't hard thanks to
"-s", but loading a plugin from an arbitrary location with a specific
name still is (As Jelmer stated as well, BZR_PLUGIN_PATH isn't
ideal because you often have many branches of the same code in
adjacent directories).
Perhaps this bug can be considered fixed by "-s" and we should
open a second about loading a plugin in the desired way, as while
most commenters here seem to want that for running tests it
would also be useful in other situations.
On Thu, 2009-04-16 at 22:28 +0000, Robert Collins wrote: Command. hooks.install_ named_hook( 'extend_ command' , test_plugin( option, name, value, parser): selftest_ args['starting_ with'] = \ takes_options) options. append( Option( 'test-plugin' , callback= handle_ test_plugin) )
> On Thu, 2009-04-16 at 20:30 +0000, James Westby wrote:
> > Hi,
> >
> > Having a better solution for this would be great, but with the help of
> > jam and vila I just knocked this up:
> >
> > if __name__ == '__main__':
>
> ug.
>
> from bzrlib import option, commands
> commands.
> test_coverage, 'test_plugin')
>
>
> def test_plugin(cmd):
> if cmd.name() != 'selftest':
> return
> def handle_
> cmd.additional_
> 'bzrlib.plugins.%s' % value
> cmd.takes_options = list(cmd.
> cmd.takes_
> option.
> help='Run tests for a single named plugin',
> custom_
Thanks,
However, as far as I can see this doesn't cover all the things
that I need to make this useful.
Allow me to be more explicit about the requirements that I have.
I have written the following hook:
import os
import shutil
import subprocess
import tempfile
from bzrlib import (
branch,
errors,
export,
trace,
)
def run_test_ suite_hook( params) : branch. get_config( ) _get_location_ config( )._get_ user_option( "pre_change_ branch_ tip_test_ command" ) note("Running the testsuite: %s" % command) branch. repository. revision_ tree(revid) join(tempdir, "export")
export. export( revtree, export_dir, format="dir") call(command, cwd=export_dir, shell=True) TipChangeReject ed("The testsuite failed")
shutil. rmtree( tempdir)
config = params.
command = config.
if command is None:
return
trace.
revid = params.new_revid
revtree = params.
tempdir = tempfile.mkdtemp()
try:
export_dir = os.path.
retcode = subprocess.
if retcode != 0:
raise errors.
finally:
branch. Branch. hooks.install_ named_hook( 'pre_change_ branch_ tip',
run_test_ suite_hook, "Check the testsuite passes before the "
"change is made.")
which looks for a configuration option giving the command to run to
validate the commit, for a poor-man's PQM for my local work.
I'd like to use this for my bzr plugins, however the usual way
I test those is "bzr selftest -s bp.<plugin name>". However,
that requires the tree I am committing is the one that bzr will
load, which isn't always going to be the case. In particular,
the above code exports to a temporary directory to run the tests,
so it won't be something loaded by bzr.
So, I need a way to run the tests for a plugin, but also pass
an arbitrary filesystem location to use the tests from, and have
the plugin appear as the correct name to bzr.
My code does this by setting BZR_PLUGIN_PATH based on __file__,
so that it will always be testing the code that you are running
it from, as well as a symlink to get it to appear as the correct
name, regardless of the directory name.
Running the particular tests of a plugins isn't hard thanks to
"-s", but loading a plugin from an arbitrary location with a specific
name still is (As Jelmer stated as well, BZR_PLUGIN_PATH isn't
ideal because you often have many branches of the same code in
adjacent directories).
Perhaps this bug can be considered fixed by "-s" and we should
open a second about loading a plugin in the desired way, as while
most commenters here seem to want that for running tests it
would also be useful in other situations.
Thanks,
James