Mercurial > hg > fetch
view tests/doctest.txt @ 42:6e978ddf5135
self._export vs self.export, the function
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Tue, 15 Nov 2011 14:24:51 -0800 |
parents | 1c963875e6cd |
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)