view tests/doctest.txt @ 29:1c963875e6cd

add a test for manifest and fix resulting bugs
author Jeff Hammel <jhammel@mozilla.com>
date Tue, 15 Nov 2011 10:13:47 -0800
parents 63ff1b00ec05
children
line wrap: on
line source

Test fetch
==========

The obligatory imports::

    >>> import fetch
    >>> import os
    >>> import shutil
    >>> import tempfile
    >>> from StringIO import StringIO

Create a staging directory::

    >>> stage = tempfile.mkdtemp()

Create a Fetch object::

    >>> f = fetch.Fetch(relative_to=stage, strict=True)

Call Fetch directly::

    >>> def url(*args):
    ...     return 'file://' + os.path.join(*([here] + list(args)))
    >>> f(url=url('sample1.txt'), destination=stage, type='file')
    >>> dest = os.path.join(stage, 'sample1.txt')
    >>> file(dest).read().strip()
    'sample1'
    >>> os.remove(dest)

Parse a Fetch "manifest"::

    >>> dest = os.path.join(stage, 'example1.txt')
    >>> manifest = '%s %s file' % (url('sample1.txt'), 'example1.txt') # SOURCE DEST TYPE
    >>> buffer = StringIO()
    >>> buffer.write(manifest)
    >>> buffer.seek(0)
    >>> contents = fetch.read_manifests(buffer)
    >>> len(contents)
    1
    >>> f.fetch(*contents)
    >>> file(dest).read().strip()
    'sample1'
    >>> os.remove(dest)

Cleanup::

    >>> shutil.rmtree(stage)