# HG changeset patch # User Jeff Hammel # Date 1293947914 28800 # Node ID 7e47ff4b0cd3d2086e7a6e93f75766dc2089904a # Parent 46c2d0a7335af5edff9e855b3b1de59475d77249 started writing tests; what a surprise, everything is broken ;) diff -r 46c2d0a7335a -r 7e47ff4b0cd3 examples/doctest.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/doctest.txt Sat Jan 01 21:58:34 2011 -0800 @@ -0,0 +1,26 @@ +MakeItSo! +========= + +Boilerplate: + + >>> import makeitso + >>> import os + >>> from StringIO import StringIO + >>> example = os.path.join(here, 'example.txt') + +Basic functionality: + + >>> template = makeitso.PolyTemplate([example], interactive=False) + >>> template.missing() + set(['name']) + >>> template.substitute(name='foo') + None + +Substitute to a buffer: + + >>> buffer = StringIO() + >>> template = makeitso.PolyTemplate([example], output=buffer, interactive=False) + >>> template.substitute(name='bar') + None + >>> buffer.getvalue() + diff -r 46c2d0a7335a -r 7e47ff4b0cd3 examples/test.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/test.py Sat Jan 01 21:58:34 2011 -0800 @@ -0,0 +1,18 @@ +#!/usr/bin/env python + +""" +doctest runner +""" + +import doctest +import os + +def run_tests(): + directory = os.path.dirname(os.path.abspath(__file__)) + extraglobs = {'here': directory} + tests = [ 'doctest.txt' ] + for test in tests: + doctest.testfile(test, extraglobs=extraglobs, raise_on_error=False) + +if __name__ == '__main__': + run_tests() diff -r 46c2d0a7335a -r 7e47ff4b0cd3 makeitso/__init__.py --- a/makeitso/__init__.py Sat Jan 01 21:21:53 2011 -0800 +++ b/makeitso/__init__.py Sat Jan 01 21:58:34 2011 -0800 @@ -1,1 +1,2 @@ # +from makeitso import * diff -r 46c2d0a7335a -r 7e47ff4b0cd3 makeitso/makeitso.py --- a/makeitso/makeitso.py Sat Jan 01 21:21:53 2011 -0800 +++ b/makeitso/makeitso.py Sat Jan 01 21:58:34 2011 -0800 @@ -155,7 +155,7 @@ """interactive (for now) substitution""" vars = self.defaults.copy() vars.update(variables) - missing = self.missing(vars) + missing = self.missing(**vars) if missing: if self.interactive: vars.update(self.read_variables(missing)) @@ -180,8 +180,7 @@ """template for a file or URL""" def __init__(self, uri, output=None, interactive=True, **variables): - self.output = output or sys.stdout - + self.output = output or sys.stdout content = include(uri) # remove makeitso shebang if it has one @@ -270,7 +269,8 @@ def __init__(self, templates, output=None, interactive=True, **variables): assert templates, "No templates given!" - + + self._templates = templates[:] self.templates = [] self.output = output for template in templates: @@ -292,7 +292,7 @@ # determine where the hell to put these things if self.output is None: - dirs = [i for i in templates if os.path.isdir(i)] + dirs = [i for i in self._templates if os.path.isdir(i)] if not ((len(dirs) == 0) or len(dirs) == len(templates)): raise AssertionError("Must specify output when mixing directories and URIs") @@ -355,7 +355,7 @@ return # template variables - _vars = [] + variables = {} _args = [] for arg in args: if '=' in arg: