annotate tests/doctest.txt @ 32:00ca88ef1c33

more documentation
author Jeff Hammel <jhammel@mozilla.com>
date Mon, 11 Jul 2011 12:59:49 -0700
parents dace84448c25
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5
7ea2b5f12b2d stub tests
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
1 Test carton
7ea2b5f12b2d stub tests
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
2 ===========
7ea2b5f12b2d stub tests
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
3
7ea2b5f12b2d stub tests
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
4 The obligatory imports:
7ea2b5f12b2d stub tests
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
5
7ea2b5f12b2d stub tests
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
6 >>> import carton
8
5905459d4ebe now have a passing if somewhat rudimentary test
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
7 >>> import os
7
111ffe84f66a more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
8
111ffe84f66a more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
9 Make a temporary directory::
111ffe84f66a more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
10
5
7ea2b5f12b2d stub tests
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
11 >>> import tempfile
7
111ffe84f66a more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
12 >>> directory = tempfile.mkdtemp()
5
7ea2b5f12b2d stub tests
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
13
9
aa673036ecc1 correct string
Jeff Hammel <jhammel@mozilla.com>
parents: 8
diff changeset
14 Invoke carton::
5
7ea2b5f12b2d stub tests
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
15
8
5905459d4ebe now have a passing if somewhat rudimentary test
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
16 >>> os.chdir(directory)
13
f522620c6a78 now works properly with tarballs
Jeff Hammel <jhammel@mozilla.com>
parents: 10
diff changeset
17 >>> packages = [os.path.join(here, i) for i in 'packageC.tar.gz', 'packageB', 'packageA']
8
5905459d4ebe now have a passing if somewhat rudimentary test
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
18 >>> carton.main(['foo'] + packages)
5905459d4ebe now have a passing if somewhat rudimentary test
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
19 >>> os.listdir('.')
5905459d4ebe now have a passing if somewhat rudimentary test
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
20 ['foo.py']
5
7ea2b5f12b2d stub tests
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
21
10
d1f090c5f291 lets make some more tests
Jeff Hammel <jhammel@mozilla.com>
parents: 9
diff changeset
22 Invoke the foo.py it creates::
d1f090c5f291 lets make some more tests
Jeff Hammel <jhammel@mozilla.com>
parents: 9
diff changeset
23
d1f090c5f291 lets make some more tests
Jeff Hammel <jhammel@mozilla.com>
parents: 9
diff changeset
24 >>> import subprocess
d1f090c5f291 lets make some more tests
Jeff Hammel <jhammel@mozilla.com>
parents: 9
diff changeset
25 >>> subprocess.call([python, 'foo.py'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
d1f090c5f291 lets make some more tests
Jeff Hammel <jhammel@mozilla.com>
parents: 9
diff changeset
26 0
d1f090c5f291 lets make some more tests
Jeff Hammel <jhammel@mozilla.com>
parents: 9
diff changeset
27 >>> sorted(os.listdir('.'))
d1f090c5f291 lets make some more tests
Jeff Hammel <jhammel@mozilla.com>
parents: 9
diff changeset
28 ['foo', 'foo.py']
d1f090c5f291 lets make some more tests
Jeff Hammel <jhammel@mozilla.com>
parents: 9
diff changeset
29 >>> os.path.isdir('foo')
d1f090c5f291 lets make some more tests
Jeff Hammel <jhammel@mozilla.com>
parents: 9
diff changeset
30 True
d1f090c5f291 lets make some more tests
Jeff Hammel <jhammel@mozilla.com>
parents: 9
diff changeset
31 >>> sorted(os.listdir(os.path.join('foo', 'src')))
13
f522620c6a78 now works properly with tarballs
Jeff Hammel <jhammel@mozilla.com>
parents: 10
diff changeset
32 ['packageA', 'packageB', 'packageC']
10
d1f090c5f291 lets make some more tests
Jeff Hammel <jhammel@mozilla.com>
parents: 9
diff changeset
33
19
996d579f0dc3 test for --package and --env
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
34 Find a console script. This shows installation went well::
996d579f0dc3 test for --package and --env
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
35
24
bb19d3dac4c5 fix tests
Jeff Hammel <jhammel@mozilla.com>
parents: 20
diff changeset
36 >>> bin = [os.path.join('foo', i) for i in ('bin', 'Scripts') if os.path.exists(os.path.join('foo', i))][0]
bb19d3dac4c5 fix tests
Jeff Hammel <jhammel@mozilla.com>
parents: 20
diff changeset
37 >>> os.path.isdir(bin)
bb19d3dac4c5 fix tests
Jeff Hammel <jhammel@mozilla.com>
parents: 20
diff changeset
38 True
19
996d579f0dc3 test for --package and --env
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
39 >>> os.path.exists(os.path.join(bin, 'packageA')) or os.path.exists(os.path.join(bin, 'packageA.exe'))
996d579f0dc3 test for --package and --env
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
40 True
996d579f0dc3 test for --package and --env
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
41
25
e2db2913123d test to ensure we are bringing along virtualenv
Jeff Hammel <jhammel@mozilla.com>
parents: 24
diff changeset
42 Ensure you're bringing along virtualenv::
e2db2913123d test to ensure we are bringing along virtualenv
Jeff Hammel <jhammel@mozilla.com>
parents: 24
diff changeset
43
e2db2913123d test to ensure we are bringing along virtualenv
Jeff Hammel <jhammel@mozilla.com>
parents: 24
diff changeset
44 >>> os.path.exists(os.path.join(bin, 'virtualenv')) or os.path.exists(os.path.join(bin, 'virtualenv.exe'))
e2db2913123d test to ensure we are bringing along virtualenv
Jeff Hammel <jhammel@mozilla.com>
parents: 24
diff changeset
45 True
e2db2913123d test to ensure we are bringing along virtualenv
Jeff Hammel <jhammel@mozilla.com>
parents: 24
diff changeset
46
27
dace84448c25 carry carton along with carton
Jeff Hammel <jhammel@mozilla.com>
parents: 25
diff changeset
47 Ensure you're bringing along carton::
dace84448c25 carry carton along with carton
Jeff Hammel <jhammel@mozilla.com>
parents: 25
diff changeset
48
dace84448c25 carry carton along with carton
Jeff Hammel <jhammel@mozilla.com>
parents: 25
diff changeset
49 >>> packaged_carton = os.path.join(bin, 'carton.py')
dace84448c25 carry carton along with carton
Jeff Hammel <jhammel@mozilla.com>
parents: 25
diff changeset
50 >>> os.path.exists(packaged_carton)
dace84448c25 carry carton along with carton
Jeff Hammel <jhammel@mozilla.com>
parents: 25
diff changeset
51 True
dace84448c25 carry carton along with carton
Jeff Hammel <jhammel@mozilla.com>
parents: 25
diff changeset
52 >>> carton_module = carton.__file__.rstrip('c')
dace84448c25 carry carton along with carton
Jeff Hammel <jhammel@mozilla.com>
parents: 25
diff changeset
53 >>> os.path.exists(carton_module)
dace84448c25 carry carton along with carton
Jeff Hammel <jhammel@mozilla.com>
parents: 25
diff changeset
54 True
dace84448c25 carry carton along with carton
Jeff Hammel <jhammel@mozilla.com>
parents: 25
diff changeset
55 >>> file(packaged_carton).read() == file(carton_module).read()
dace84448c25 carry carton along with carton
Jeff Hammel <jhammel@mozilla.com>
parents: 25
diff changeset
56 True
dace84448c25 carry carton along with carton
Jeff Hammel <jhammel@mozilla.com>
parents: 25
diff changeset
57
19
996d579f0dc3 test for --package and --env
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
58 Show that non-package files get carried along too::
996d579f0dc3 test for --package and --env
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
59
996d579f0dc3 test for --package and --env
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
60 >>> os.path.exists(os.path.join('foo', 'src', 'packageA', 'foo.txt'))
996d579f0dc3 test for --package and --env
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
61 True
996d579f0dc3 test for --package and --env
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
62
996d579f0dc3 test for --package and --env
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
63 Invoke carton again. This time, package the source so that
996d579f0dc3 test for --package and --env
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
64 stragglers don't come along::
996d579f0dc3 test for --package and --env
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
65
996d579f0dc3 test for --package and --env
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
66 >>> carton.main(['bar', '--package'] + packages)
996d579f0dc3 test for --package and --env
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
67 >>> 'bar.py' in os.listdir('.')
996d579f0dc3 test for --package and --env
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
68 True
996d579f0dc3 test for --package and --env
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
69 >>> subprocess.call([python, 'bar.py', '--env', 'fleem'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
996d579f0dc3 test for --package and --env
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
70 0
996d579f0dc3 test for --package and --env
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
71 >>> os.path.exists('fleem') and os.path.isdir('fleem')
996d579f0dc3 test for --package and --env
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
72 True
996d579f0dc3 test for --package and --env
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
73 >>> srcdir = os.path.join('fleem', 'src')
996d579f0dc3 test for --package and --env
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
74 >>> packageA = os.path.join(srcdir, [i for i in os.listdir(srcdir) if i.startswith('packageA')][0])
24
bb19d3dac4c5 fix tests
Jeff Hammel <jhammel@mozilla.com>
parents: 20
diff changeset
75 >>> os.path.exists(os.path.join(packageA, 'foo.txt'))
20
e2c9a9a4d524 ...except i fuxored my logic
Jeff Hammel <jhammel@mozilla.com>
parents: 19
diff changeset
76 False
19
996d579f0dc3 test for --package and --env
Jeff Hammel <jhammel@mozilla.com>
parents: 13
diff changeset
77
7
111ffe84f66a more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
78 Clean up::
111ffe84f66a more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
79
111ffe84f66a more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
80 >>> import shutil
111ffe84f66a more stubbing
Jeff Hammel <jhammel@mozilla.com>
parents: 5
diff changeset
81 >>> shutil.rmtree(directory)