comparison 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
comparison
equal deleted inserted replaced
28:5ecb6507931b 29:1c963875e6cd
5 5
6 >>> import fetch 6 >>> import fetch
7 >>> import os 7 >>> import os
8 >>> import shutil 8 >>> import shutil
9 >>> import tempfile 9 >>> import tempfile
10 >>> from StringIO import StringIO
10 11
11 Create a staging directory:: 12 Create a staging directory::
12 13
13 >>> stage = tempfile.mkdtemp() 14 >>> stage = tempfile.mkdtemp()
14 15
15 Create a Fetch object:: 16 Create a Fetch object::
16 17
17 >>> f = fetch.Fetch(relative_to=stage, strict=True) 18 >>> f = fetch.Fetch(relative_to=stage, strict=True)
18 19
19 Call Fetch directly:: 20 Call Fetch directly::
20 21
21 >>> def url(*args): 22 >>> def url(*args):
22 ... return 'file://' + os.path.join(*([here] + list(args))) 23 ... return 'file://' + os.path.join(*([here] + list(args)))
23 >>> f(url=url('sample1.txt'), destination=stage, type='file') 24 >>> f(url=url('sample1.txt'), destination=stage, type='file')
24 >>> file(os.path.join(stage, 'sample1.txt')).read().strip() 25 >>> dest = os.path.join(stage, 'sample1.txt')
26 >>> file(dest).read().strip()
25 'sample1' 27 'sample1'
28 >>> os.remove(dest)
29
30 Parse a Fetch "manifest"::
31
32 >>> dest = os.path.join(stage, 'example1.txt')
33 >>> manifest = '%s %s file' % (url('sample1.txt'), 'example1.txt') # SOURCE DEST TYPE
34 >>> buffer = StringIO()
35 >>> buffer.write(manifest)
36 >>> buffer.seek(0)
37 >>> contents = fetch.read_manifests(buffer)
38 >>> len(contents)
39 1
40 >>> f.fetch(*contents)
41 >>> file(dest).read().strip()
42 'sample1'
43 >>> os.remove(dest)
26 44
27 Cleanup:: 45 Cleanup::
28 46
29 >>> shutil.rmtree(stage) 47 >>> shutil.rmtree(stage)