annotate examples/doctest.txt @ 91:672d2d3ee322

document a bit and add a test for an include example
author Jeff Hammel <jhammel@mozilla.com>
date Mon, 10 Jan 2011 21:42:32 -0800
parents 26b9c3bba04e
children e74baa8e6df4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
35
7e47ff4b0cd3 started writing tests; what a surprise, everything is broken ;)
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
1 MakeItSo!
7e47ff4b0cd3 started writing tests; what a surprise, everything is broken ;)
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
2 =========
7e47ff4b0cd3 started writing tests; what a surprise, everything is broken ;)
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
3
88
712a6d358083 fixed output broke other things
Jeff Hammel <jhammel@mozilla.com>
parents: 87
diff changeset
4 A filesystem templating system for rapid deploy of projects
712a6d358083 fixed output broke other things
Jeff Hammel <jhammel@mozilla.com>
parents: 87
diff changeset
5
712a6d358083 fixed output broke other things
Jeff Hammel <jhammel@mozilla.com>
parents: 87
diff changeset
6 Boilerplate::
35
7e47ff4b0cd3 started writing tests; what a surprise, everything is broken ;)
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
7
7e47ff4b0cd3 started writing tests; what a surprise, everything is broken ;)
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
8 >>> import makeitso
7e47ff4b0cd3 started writing tests; what a surprise, everything is broken ;)
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
9 >>> import os
37
7cee2869bd7b stub out directory example
Jeff Hammel <jhammel@mozilla.com>
parents: 36
diff changeset
10 >>> import shutil
7cee2869bd7b stub out directory example
Jeff Hammel <jhammel@mozilla.com>
parents: 36
diff changeset
11 >>> import tempfile
35
7e47ff4b0cd3 started writing tests; what a surprise, everything is broken ;)
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
12 >>> from StringIO import StringIO
7e47ff4b0cd3 started writing tests; what a surprise, everything is broken ;)
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
13
87
3571417ef92e interpolate file permissions
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
14 Basic functionality::
35
7e47ff4b0cd3 started writing tests; what a surprise, everything is broken ;)
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
15
37
7cee2869bd7b stub out directory example
Jeff Hammel <jhammel@mozilla.com>
parents: 36
diff changeset
16 >>> example = os.path.join(here, 'example.txt')
35
7e47ff4b0cd3 started writing tests; what a surprise, everything is broken ;)
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
17 >>> template = makeitso.PolyTemplate([example], interactive=False)
7e47ff4b0cd3 started writing tests; what a surprise, everything is broken ;)
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
18 >>> template.missing()
7e47ff4b0cd3 started writing tests; what a surprise, everything is broken ;)
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
19 set(['name'])
90
26b9c3bba04e make the api for substitute() variables, output
Jeff Hammel <jhammel@mozilla.com>
parents: 88
diff changeset
20 >>> template.substitute(dict(name='foo'))
36
0cba953a03ca fixed single-file test case
Jeff Hammel <jhammel@mozilla.com>
parents: 35
diff changeset
21 Hello foo
35
7e47ff4b0cd3 started writing tests; what a surprise, everything is broken ;)
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
22
87
3571417ef92e interpolate file permissions
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
23 Substitute to a buffer::
35
7e47ff4b0cd3 started writing tests; what a surprise, everything is broken ;)
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
24
7e47ff4b0cd3 started writing tests; what a surprise, everything is broken ;)
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
25 >>> buffer = StringIO()
88
712a6d358083 fixed output broke other things
Jeff Hammel <jhammel@mozilla.com>
parents: 87
diff changeset
26 >>> template = makeitso.PolyTemplate([example], interactive=False)
90
26b9c3bba04e make the api for substitute() variables, output
Jeff Hammel <jhammel@mozilla.com>
parents: 88
diff changeset
27 >>> template.substitute(dict(name='bar'), output=buffer)
36
0cba953a03ca fixed single-file test case
Jeff Hammel <jhammel@mozilla.com>
parents: 35
diff changeset
28 >>> buffer.getvalue().strip()
0cba953a03ca fixed single-file test case
Jeff Hammel <jhammel@mozilla.com>
parents: 35
diff changeset
29 'Hello bar'
37
7cee2869bd7b stub out directory example
Jeff Hammel <jhammel@mozilla.com>
parents: 36
diff changeset
30
87
3571417ef92e interpolate file permissions
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
31 Substitute to a file::
37
7cee2869bd7b stub out directory example
Jeff Hammel <jhammel@mozilla.com>
parents: 36
diff changeset
32
7cee2869bd7b stub out directory example
Jeff Hammel <jhammel@mozilla.com>
parents: 36
diff changeset
33 >>> buffer = tempfile.mktemp()
88
712a6d358083 fixed output broke other things
Jeff Hammel <jhammel@mozilla.com>
parents: 87
diff changeset
34 >>> template = makeitso.PolyTemplate([example], interactive=False)
90
26b9c3bba04e make the api for substitute() variables, output
Jeff Hammel <jhammel@mozilla.com>
parents: 88
diff changeset
35 >>> template.substitute(dict(name='fleem'), buffer)
37
7cee2869bd7b stub out directory example
Jeff Hammel <jhammel@mozilla.com>
parents: 36
diff changeset
36 >>> file(buffer).read().strip()
7cee2869bd7b stub out directory example
Jeff Hammel <jhammel@mozilla.com>
parents: 36
diff changeset
37 'Hello fleem'
7cee2869bd7b stub out directory example
Jeff Hammel <jhammel@mozilla.com>
parents: 36
diff changeset
38 >>> os.remove(buffer)
7cee2869bd7b stub out directory example
Jeff Hammel <jhammel@mozilla.com>
parents: 36
diff changeset
39
91
672d2d3ee322 document a bit and add a test for an include example
Jeff Hammel <jhammel@mozilla.com>
parents: 90
diff changeset
40 Including a file::
672d2d3ee322 document a bit and add a test for an include example
Jeff Hammel <jhammel@mozilla.com>
parents: 90
diff changeset
41
672d2d3ee322 document a bit and add a test for an include example
Jeff Hammel <jhammel@mozilla.com>
parents: 90
diff changeset
42 >>> include_example = os.path.join(here, 'include-example.txt')
672d2d3ee322 document a bit and add a test for an include example
Jeff Hammel <jhammel@mozilla.com>
parents: 90
diff changeset
43 >>> buffer = tempfile.mktemp()
672d2d3ee322 document a bit and add a test for an include example
Jeff Hammel <jhammel@mozilla.com>
parents: 90
diff changeset
44 >>> template = makeitso.PolyTemplate([include_example], interactive=False)
672d2d3ee322 document a bit and add a test for an include example
Jeff Hammel <jhammel@mozilla.com>
parents: 90
diff changeset
45 >>> template.substitute({}, buffer)
672d2d3ee322 document a bit and add a test for an include example
Jeff Hammel <jhammel@mozilla.com>
parents: 90
diff changeset
46 >>> os.remove(buffer)
672d2d3ee322 document a bit and add a test for an include example
Jeff Hammel <jhammel@mozilla.com>
parents: 90
diff changeset
47
65
0152741621c1 check in a failing test wrt location
Jeff Hammel <jhammel@mozilla.com>
parents: 51
diff changeset
48 Directory case::
37
7cee2869bd7b stub out directory example
Jeff Hammel <jhammel@mozilla.com>
parents: 36
diff changeset
49
7cee2869bd7b stub out directory example
Jeff Hammel <jhammel@mozilla.com>
parents: 36
diff changeset
50 >>> exampledir = os.path.join(here, 'directory-example')
7cee2869bd7b stub out directory example
Jeff Hammel <jhammel@mozilla.com>
parents: 36
diff changeset
51 >>> tempdir = tempfile.mkdtemp()
88
712a6d358083 fixed output broke other things
Jeff Hammel <jhammel@mozilla.com>
parents: 87
diff changeset
52 >>> template = makeitso.PolyTemplate([exampledir], interactive=False)
37
7cee2869bd7b stub out directory example
Jeff Hammel <jhammel@mozilla.com>
parents: 36
diff changeset
53 >>> sorted(template.missing())
7cee2869bd7b stub out directory example
Jeff Hammel <jhammel@mozilla.com>
parents: 36
diff changeset
54 ['bar', 'foo', 'subdir']
90
26b9c3bba04e make the api for substitute() variables, output
Jeff Hammel <jhammel@mozilla.com>
parents: 88
diff changeset
55 >>> template.substitute(dict(foo='It', bar='life', subdir='mysubdir'), output=tempdir)
39
a2cdce0108e1 get directory substitution sorta working; start stubbing mixed case
Jeff Hammel <jhammel@mozilla.com>
parents: 38
diff changeset
56 >>> sorted(os.listdir(tempdir))
a2cdce0108e1 get directory substitution sorta working; start stubbing mixed case
Jeff Hammel <jhammel@mozilla.com>
parents: 38
diff changeset
57 ['foo.txt', 'mysubdir']
a2cdce0108e1 get directory substitution sorta working; start stubbing mixed case
Jeff Hammel <jhammel@mozilla.com>
parents: 38
diff changeset
58 >>> file(os.path.join(tempdir, 'foo.txt')).read().strip()
a2cdce0108e1 get directory substitution sorta working; start stubbing mixed case
Jeff Hammel <jhammel@mozilla.com>
parents: 38
diff changeset
59 'It is a wonderful life'
a2cdce0108e1 get directory substitution sorta working; start stubbing mixed case
Jeff Hammel <jhammel@mozilla.com>
parents: 38
diff changeset
60 >>> os.listdir(os.path.join(tempdir, 'mysubdir'))
a2cdce0108e1 get directory substitution sorta working; start stubbing mixed case
Jeff Hammel <jhammel@mozilla.com>
parents: 38
diff changeset
61 ['life.txt']
a2cdce0108e1 get directory substitution sorta working; start stubbing mixed case
Jeff Hammel <jhammel@mozilla.com>
parents: 38
diff changeset
62 >>> file(os.path.join(tempdir, 'mysubdir', 'life.txt')).read().strip()
a2cdce0108e1 get directory substitution sorta working; start stubbing mixed case
Jeff Hammel <jhammel@mozilla.com>
parents: 38
diff changeset
63 'It'
a2cdce0108e1 get directory substitution sorta working; start stubbing mixed case
Jeff Hammel <jhammel@mozilla.com>
parents: 38
diff changeset
64 >>> shutil.rmtree(tempdir)
a2cdce0108e1 get directory substitution sorta working; start stubbing mixed case
Jeff Hammel <jhammel@mozilla.com>
parents: 38
diff changeset
65
65
0152741621c1 check in a failing test wrt location
Jeff Hammel <jhammel@mozilla.com>
parents: 51
diff changeset
66 Mixed case::
39
a2cdce0108e1 get directory substitution sorta working; start stubbing mixed case
Jeff Hammel <jhammel@mozilla.com>
parents: 38
diff changeset
67
51
9a0014a760d1 missed an interactive=False
Jeff Hammel <jhammel@mozilla.com>
parents: 40
diff changeset
68 >>> template = makeitso.PolyTemplate([example, exampledir], interactive=False)
40
6b4c8f23192f test and fix mixed output case
Jeff Hammel <jhammel@mozilla.com>
parents: 39
diff changeset
69 >>> variables = sorted(template.missing())
6b4c8f23192f test and fix mixed output case
Jeff Hammel <jhammel@mozilla.com>
parents: 39
diff changeset
70 >>> variables
6b4c8f23192f test and fix mixed output case
Jeff Hammel <jhammel@mozilla.com>
parents: 39
diff changeset
71 ['bar', 'foo', 'name', 'subdir']
39
a2cdce0108e1 get directory substitution sorta working; start stubbing mixed case
Jeff Hammel <jhammel@mozilla.com>
parents: 38
diff changeset
72
65
0152741621c1 check in a failing test wrt location
Jeff Hammel <jhammel@mozilla.com>
parents: 51
diff changeset
73 You need to provide output for mixing files and directory templates::
40
6b4c8f23192f test and fix mixed output case
Jeff Hammel <jhammel@mozilla.com>
parents: 39
diff changeset
74
6b4c8f23192f test and fix mixed output case
Jeff Hammel <jhammel@mozilla.com>
parents: 39
diff changeset
75 >>> variables = dict([(i, i.title()) for i in variables])
6b4c8f23192f test and fix mixed output case
Jeff Hammel <jhammel@mozilla.com>
parents: 39
diff changeset
76 >>> try:
90
26b9c3bba04e make the api for substitute() variables, output
Jeff Hammel <jhammel@mozilla.com>
parents: 88
diff changeset
77 ... template.substitute(variables)
40
6b4c8f23192f test and fix mixed output case
Jeff Hammel <jhammel@mozilla.com>
parents: 39
diff changeset
78 ... except AssertionError, e:
6b4c8f23192f test and fix mixed output case
Jeff Hammel <jhammel@mozilla.com>
parents: 39
diff changeset
79 ... pass
6b4c8f23192f test and fix mixed output case
Jeff Hammel <jhammel@mozilla.com>
parents: 39
diff changeset
80 >>> e
88
712a6d358083 fixed output broke other things
Jeff Hammel <jhammel@mozilla.com>
parents: 87
diff changeset
81 AssertionError()
40
6b4c8f23192f test and fix mixed output case
Jeff Hammel <jhammel@mozilla.com>
parents: 39
diff changeset
82
65
0152741621c1 check in a failing test wrt location
Jeff Hammel <jhammel@mozilla.com>
parents: 51
diff changeset
83 Provide an output::
40
6b4c8f23192f test and fix mixed output case
Jeff Hammel <jhammel@mozilla.com>
parents: 39
diff changeset
84
88
712a6d358083 fixed output broke other things
Jeff Hammel <jhammel@mozilla.com>
parents: 87
diff changeset
85 >>> template = makeitso.PolyTemplate([example, exampledir], interactive=False)
90
26b9c3bba04e make the api for substitute() variables, output
Jeff Hammel <jhammel@mozilla.com>
parents: 88
diff changeset
86 >>> template.substitute(variables, tempdir)
40
6b4c8f23192f test and fix mixed output case
Jeff Hammel <jhammel@mozilla.com>
parents: 39
diff changeset
87 >>> sorted(os.listdir(tempdir))
6b4c8f23192f test and fix mixed output case
Jeff Hammel <jhammel@mozilla.com>
parents: 39
diff changeset
88 ['Subdir', 'example.txt', 'foo.txt']
6b4c8f23192f test and fix mixed output case
Jeff Hammel <jhammel@mozilla.com>
parents: 39
diff changeset
89 >>> shutil.rmtree(tempdir)
65
0152741621c1 check in a failing test wrt location
Jeff Hammel <jhammel@mozilla.com>
parents: 51
diff changeset
90
0152741621c1 check in a failing test wrt location
Jeff Hammel <jhammel@mozilla.com>
parents: 51
diff changeset
91 Test API templates::
0152741621c1 check in a failing test wrt location
Jeff Hammel <jhammel@mozilla.com>
parents: 51
diff changeset
92
0152741621c1 check in a failing test wrt location
Jeff Hammel <jhammel@mozilla.com>
parents: 51
diff changeset
93 >>> from makeitso.template import MakeItSoTemplate, Variable
0152741621c1 check in a failing test wrt location
Jeff Hammel <jhammel@mozilla.com>
parents: 51
diff changeset
94 >>> class MyTemplate(MakeItSoTemplate):
0152741621c1 check in a failing test wrt location
Jeff Hammel <jhammel@mozilla.com>
parents: 51
diff changeset
95 ... name = 'foo'
0152741621c1 check in a failing test wrt location
Jeff Hammel <jhammel@mozilla.com>
parents: 51
diff changeset
96 ... templates = ['example.txt']
0152741621c1 check in a failing test wrt location
Jeff Hammel <jhammel@mozilla.com>
parents: 51
diff changeset
97 ... vars = [Variable(name='name', default='bar')]
67
a0f7bfa98755 API templates now hobble along on their own two feet
Jeff Hammel <jhammel@mozilla.com>
parents: 65
diff changeset
98 >>> buffer = tempfile.mktemp()
88
712a6d358083 fixed output broke other things
Jeff Hammel <jhammel@mozilla.com>
parents: 87
diff changeset
99 >>> apitemplate = MyTemplate(interactive=False)
90
26b9c3bba04e make the api for substitute() variables, output
Jeff Hammel <jhammel@mozilla.com>
parents: 88
diff changeset
100 >>> apitemplate.substitute({}, buffer)
67
a0f7bfa98755 API templates now hobble along on their own two feet
Jeff Hammel <jhammel@mozilla.com>
parents: 65
diff changeset
101 >>> file(buffer).read().strip()
a0f7bfa98755 API templates now hobble along on their own two feet
Jeff Hammel <jhammel@mozilla.com>
parents: 65
diff changeset
102 'Hello bar'
a0f7bfa98755 API templates now hobble along on their own two feet
Jeff Hammel <jhammel@mozilla.com>
parents: 65
diff changeset
103 >>> os.remove(buffer)
87
3571417ef92e interpolate file permissions
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
104
3571417ef92e interpolate file permissions
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
105 Test to make sure permissions are preserved. This won't work on windows::
3571417ef92e interpolate file permissions
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
106
3571417ef92e interpolate file permissions
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
107 >>> buffer = tempfile.mktemp()
3571417ef92e interpolate file permissions
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
108 >>> f = file(buffer, 'w')
3571417ef92e interpolate file permissions
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
109 >>> print >> f, '#!/bin/bash\necho foo'
3571417ef92e interpolate file permissions
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
110 >>> f.close()
3571417ef92e interpolate file permissions
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
111 >>> os.chmod(buffer, 0755)
88
712a6d358083 fixed output broke other things
Jeff Hammel <jhammel@mozilla.com>
parents: 87
diff changeset
112 >>> uritemplate = makeitso.URITemplate(example, interactive=False)
90
26b9c3bba04e make the api for substitute() variables, output
Jeff Hammel <jhammel@mozilla.com>
parents: 88
diff changeset
113 >>> uritemplate.substitute(dict(name='bar'), buffer)
87
3571417ef92e interpolate file permissions
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
114 >>> ('%o' % os.stat(buffer).st_mode).endswith('755')
3571417ef92e interpolate file permissions
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
115 True
3571417ef92e interpolate file permissions
Jeff Hammel <jhammel@mozilla.com>
parents: 67
diff changeset
116 >>> os.remove(buffer)