[Distutils] test resources with setup tools
Baiju M
mbaiju at zeomega.com
Mon Apr 26 19:35:44 CEST 2010
On Mon, Apr 26, 2010 at 10:23 PM, Manlio Perillo
<manlio.perillo at gmail.com> wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> P.J. Eby ha scritto:
>> At 12:19 PM 4/23/2010 +0200, Manlio Perillo wrote:
>>> Hi.
>>>
>>> In a project test suite I need some external resources, that must be
>>> downloaded from internet.
>>>
>>> Is this directly supported by setuptools, or it is better if I write an
>>> additional script that does the job?
>>
>> If the resources can be accessed in the form of an .egg file (or
>> directory) added to sys.path, setuptools can handle it.
>
> The resources are archives that must be downloaded from internet,
> decompressed and processed.
>
> Right now I'm using a shell script that must be manually executed.
> The data is copied to a test/resources directory.
>
> The test directory contains the test suite and it is in the top level
> directory of the Python project. It is not installed on the system by
> the setup.py script.
>
> Test functions access the the data using __file__.
>
> I was just wondering if there is a better method.
You can use Buildout something like this:
1. Get bootstrap script
wget http://svn.zope.org/*checkout*/zc.buildout/trunk/bootstrap/bootstrap.py
2. Create a buildout conf with appropriate parts
[buildout]
parts = resource
extract_resource
test
[resource]
recipe = hexagonit.recipe.download
url = http://example.com/resource.tar.bz2
location = ${buildout:directory}/downloads
download-only = true
[extract_resource]
recipe = iw.recipe.cmd
on_install = true
on_update = true
shell = bash
cmds =
cd ${buildout:directory};tar jxvf
${buildout:directory}/downloads/resource.tar.bz2
[test]
recipe = zc.recipe.testrunner
eggs = mypkg
defaults = ['-v', '-k']
3. Run bootstrap.py
python bootstrap.py
4. Run buildout
./bin/buildout
5. Run test
./bin/test
So many assumptions are made here about the requirements.
You can change the recipes and parts as you required.
There are nearly 200 recipes and extensions available in PyPI,
creating one yourself is also very easy:
http://pypi.python.org/pypi?:action=browse&c=512
Basically Buildout provides an isolated-repeatable environment.
Regards,
Baiju M
More information about the Distutils-SIG
mailing list