Mercurial > hg > MakeItSo
comparison examples/doctest.txt @ 37:7cee2869bd7b
stub out directory example
| author | Jeff Hammel <jhammel@mozilla.com> |
|---|---|
| date | Sat, 01 Jan 2011 22:28:35 -0800 |
| parents | 0cba953a03ca |
| children | 9739212a63c3 |
comparison
equal
deleted
inserted
replaced
| 36:0cba953a03ca | 37:7cee2869bd7b |
|---|---|
| 3 | 3 |
| 4 Boilerplate: | 4 Boilerplate: |
| 5 | 5 |
| 6 >>> import makeitso | 6 >>> import makeitso |
| 7 >>> import os | 7 >>> import os |
| 8 >>> import shutil | |
| 9 >>> import tempfile | |
| 8 >>> from StringIO import StringIO | 10 >>> from StringIO import StringIO |
| 9 >>> example = os.path.join(here, 'example.txt') | |
| 10 | 11 |
| 11 Basic functionality: | 12 Basic functionality: |
| 12 | 13 |
| 14 >>> example = os.path.join(here, 'example.txt') | |
| 13 >>> template = makeitso.PolyTemplate([example], interactive=False) | 15 >>> template = makeitso.PolyTemplate([example], interactive=False) |
| 14 >>> template.missing() | 16 >>> template.missing() |
| 15 set(['name']) | 17 set(['name']) |
| 16 >>> template.substitute(name='foo') | 18 >>> template.substitute(name='foo') |
| 17 Hello foo | 19 Hello foo |
| 21 >>> buffer = StringIO() | 23 >>> buffer = StringIO() |
| 22 >>> template = makeitso.PolyTemplate([example], output=buffer, interactive=False) | 24 >>> template = makeitso.PolyTemplate([example], output=buffer, interactive=False) |
| 23 >>> template.substitute(name='bar') | 25 >>> template.substitute(name='bar') |
| 24 >>> buffer.getvalue().strip() | 26 >>> buffer.getvalue().strip() |
| 25 'Hello bar' | 27 'Hello bar' |
| 26 | 28 |
| 29 Substitute to a file: | |
| 30 | |
| 31 >>> buffer = tempfile.mktemp() | |
| 32 >>> template = makeitso.PolyTemplate([example], output=buffer, interactive=False) | |
| 33 >>> template.substitute(name='fleem') | |
| 34 >>> file(buffer).read().strip() | |
| 35 'Hello fleem' | |
| 36 >>> os.remove(buffer) | |
| 37 | |
| 38 Directory case: | |
| 39 | |
| 40 >>> exampledir = os.path.join(here, 'directory-example') | |
| 41 >>> tempdir = tempfile.mkdtemp() | |
| 42 >>> template = makeitso.PolyTemplate([exampledir], output=tempdir, interactive=False) | |
| 43 >>> sorted(template.missing()) | |
| 44 ['bar', 'foo', 'subdir'] | |
| 45 >>> shutil.rmtree(tempdir) |
