annotate tests/doctest.txt @ 36:d3558b202acb

whitespace
author Jeff Hammel <jhammel@mozilla.com>
date Tue, 15 Nov 2011 12:19:38 -0800
parents 1c963875e6cd
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
3497a30190d2 initial commit of fetch, WIP
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
1 Test fetch
22
63ff1b00ec05 first passing test
Jeff Hammel <jhammel@mozilla.com>
parents: 21
diff changeset
2 ==========
0
3497a30190d2 initial commit of fetch, WIP
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
3
21
0706968f01bb stub testing
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
4 The obligatory imports::
0
3497a30190d2 initial commit of fetch, WIP
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
5
3497a30190d2 initial commit of fetch, WIP
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
6 >>> import fetch
22
63ff1b00ec05 first passing test
Jeff Hammel <jhammel@mozilla.com>
parents: 21
diff changeset
7 >>> import os
63ff1b00ec05 first passing test
Jeff Hammel <jhammel@mozilla.com>
parents: 21
diff changeset
8 >>> import shutil
63ff1b00ec05 first passing test
Jeff Hammel <jhammel@mozilla.com>
parents: 21
diff changeset
9 >>> import tempfile
29
1c963875e6cd add a test for manifest and fix resulting bugs
Jeff Hammel <jhammel@mozilla.com>
parents: 22
diff changeset
10 >>> from StringIO import StringIO
22
63ff1b00ec05 first passing test
Jeff Hammel <jhammel@mozilla.com>
parents: 21
diff changeset
11
63ff1b00ec05 first passing test
Jeff Hammel <jhammel@mozilla.com>
parents: 21
diff changeset
12 Create a staging directory::
63ff1b00ec05 first passing test
Jeff Hammel <jhammel@mozilla.com>
parents: 21
diff changeset
13
63ff1b00ec05 first passing test
Jeff Hammel <jhammel@mozilla.com>
parents: 21
diff changeset
14 >>> stage = tempfile.mkdtemp()
0
3497a30190d2 initial commit of fetch, WIP
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
15
21
0706968f01bb stub testing
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
16 Create a Fetch object::
0
3497a30190d2 initial commit of fetch, WIP
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
17
22
63ff1b00ec05 first passing test
Jeff Hammel <jhammel@mozilla.com>
parents: 21
diff changeset
18 >>> f = fetch.Fetch(relative_to=stage, strict=True)
29
1c963875e6cd add a test for manifest and fix resulting bugs
Jeff Hammel <jhammel@mozilla.com>
parents: 22
diff changeset
19
22
63ff1b00ec05 first passing test
Jeff Hammel <jhammel@mozilla.com>
parents: 21
diff changeset
20 Call Fetch directly::
0
3497a30190d2 initial commit of fetch, WIP
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
21
22
63ff1b00ec05 first passing test
Jeff Hammel <jhammel@mozilla.com>
parents: 21
diff changeset
22 >>> def url(*args):
63ff1b00ec05 first passing test
Jeff Hammel <jhammel@mozilla.com>
parents: 21
diff changeset
23 ... return 'file://' + os.path.join(*([here] + list(args)))
63ff1b00ec05 first passing test
Jeff Hammel <jhammel@mozilla.com>
parents: 21
diff changeset
24 >>> f(url=url('sample1.txt'), destination=stage, type='file')
29
1c963875e6cd add a test for manifest and fix resulting bugs
Jeff Hammel <jhammel@mozilla.com>
parents: 22
diff changeset
25 >>> dest = os.path.join(stage, 'sample1.txt')
1c963875e6cd add a test for manifest and fix resulting bugs
Jeff Hammel <jhammel@mozilla.com>
parents: 22
diff changeset
26 >>> file(dest).read().strip()
22
63ff1b00ec05 first passing test
Jeff Hammel <jhammel@mozilla.com>
parents: 21
diff changeset
27 'sample1'
29
1c963875e6cd add a test for manifest and fix resulting bugs
Jeff Hammel <jhammel@mozilla.com>
parents: 22
diff changeset
28 >>> os.remove(dest)
1c963875e6cd add a test for manifest and fix resulting bugs
Jeff Hammel <jhammel@mozilla.com>
parents: 22
diff changeset
29
1c963875e6cd add a test for manifest and fix resulting bugs
Jeff Hammel <jhammel@mozilla.com>
parents: 22
diff changeset
30 Parse a Fetch "manifest"::
1c963875e6cd add a test for manifest and fix resulting bugs
Jeff Hammel <jhammel@mozilla.com>
parents: 22
diff changeset
31
1c963875e6cd add a test for manifest and fix resulting bugs
Jeff Hammel <jhammel@mozilla.com>
parents: 22
diff changeset
32 >>> dest = os.path.join(stage, 'example1.txt')
1c963875e6cd add a test for manifest and fix resulting bugs
Jeff Hammel <jhammel@mozilla.com>
parents: 22
diff changeset
33 >>> manifest = '%s %s file' % (url('sample1.txt'), 'example1.txt') # SOURCE DEST TYPE
1c963875e6cd add a test for manifest and fix resulting bugs
Jeff Hammel <jhammel@mozilla.com>
parents: 22
diff changeset
34 >>> buffer = StringIO()
1c963875e6cd add a test for manifest and fix resulting bugs
Jeff Hammel <jhammel@mozilla.com>
parents: 22
diff changeset
35 >>> buffer.write(manifest)
1c963875e6cd add a test for manifest and fix resulting bugs
Jeff Hammel <jhammel@mozilla.com>
parents: 22
diff changeset
36 >>> buffer.seek(0)
1c963875e6cd add a test for manifest and fix resulting bugs
Jeff Hammel <jhammel@mozilla.com>
parents: 22
diff changeset
37 >>> contents = fetch.read_manifests(buffer)
1c963875e6cd add a test for manifest and fix resulting bugs
Jeff Hammel <jhammel@mozilla.com>
parents: 22
diff changeset
38 >>> len(contents)
1c963875e6cd add a test for manifest and fix resulting bugs
Jeff Hammel <jhammel@mozilla.com>
parents: 22
diff changeset
39 1
1c963875e6cd add a test for manifest and fix resulting bugs
Jeff Hammel <jhammel@mozilla.com>
parents: 22
diff changeset
40 >>> f.fetch(*contents)
1c963875e6cd add a test for manifest and fix resulting bugs
Jeff Hammel <jhammel@mozilla.com>
parents: 22
diff changeset
41 >>> file(dest).read().strip()
1c963875e6cd add a test for manifest and fix resulting bugs
Jeff Hammel <jhammel@mozilla.com>
parents: 22
diff changeset
42 'sample1'
1c963875e6cd add a test for manifest and fix resulting bugs
Jeff Hammel <jhammel@mozilla.com>
parents: 22
diff changeset
43 >>> os.remove(dest)
22
63ff1b00ec05 first passing test
Jeff Hammel <jhammel@mozilla.com>
parents: 21
diff changeset
44
63ff1b00ec05 first passing test
Jeff Hammel <jhammel@mozilla.com>
parents: 21
diff changeset
45 Cleanup::
63ff1b00ec05 first passing test
Jeff Hammel <jhammel@mozilla.com>
parents: 21
diff changeset
46
63ff1b00ec05 first passing test
Jeff Hammel <jhammel@mozilla.com>
parents: 21
diff changeset
47 >>> shutil.rmtree(stage)