Mercurial > hg > fetch
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 |
rev | line source |
---|---|
0 | 1 Test fetch |
22 | 2 ========== |
0 | 3 |
21 | 4 The obligatory imports:: |
0 | 5 |
6 >>> import fetch | |
22 | 7 >>> import os |
8 >>> import shutil | |
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 | 11 |
12 Create a staging directory:: | |
13 | |
14 >>> stage = tempfile.mkdtemp() | |
0 | 15 |
21 | 16 Create a Fetch object:: |
0 | 17 |
22 | 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 | 20 Call Fetch directly:: |
0 | 21 |
22 | 22 >>> def url(*args): |
23 ... return 'file://' + os.path.join(*([here] + list(args))) | |
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 | 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 | 44 |
45 Cleanup:: | |
46 | |
47 >>> shutil.rmtree(stage) |