view examples/doctest.txt @ 38:9739212a63c3

found a serious problem: directories stubbornly substitute into themselves
author Jeff Hammel <jhammel@mozilla.com>
date Sat, 01 Jan 2011 22:34:29 -0800
parents 7cee2869bd7b
children a2cdce0108e1
line wrap: on
line source

MakeItSo!
=========

Boilerplate:

    >>> import makeitso
    >>> import os
    >>> import shutil
    >>> import tempfile
    >>> from StringIO import StringIO

Basic functionality:

    >>> example = os.path.join(here, 'example.txt')
    >>> template = makeitso.PolyTemplate([example], interactive=False)
    >>> template.missing()
    set(['name'])
    >>> template.substitute(name='foo')
    Hello foo
    
Substitute to a buffer:

    >>> buffer = StringIO()
    >>> template = makeitso.PolyTemplate([example], output=buffer, interactive=False)
    >>> template.substitute(name='bar')
    >>> buffer.getvalue().strip()
    'Hello bar'

Substitute to a file:

    >>> buffer = tempfile.mktemp()
    >>> template = makeitso.PolyTemplate([example], output=buffer, interactive=False)
    >>> template.substitute(name='fleem')
    >>> file(buffer).read().strip()
    'Hello fleem'
    >>> os.remove(buffer)

Directory case:

    >>> exampledir = os.path.join(here, 'directory-example')
    >>> tempdir = tempfile.mkdtemp()
    >>> template = makeitso.PolyTemplate([exampledir], output=tempdir, interactive=False)
    >>> sorted(template.missing())
    ['bar', 'foo', 'subdir']
    >>> template.substitute(foo='myfoo', bar='mybar', subdir='mysubdir')
    >>> os.listdir(tempdir)