changeset 35:7e47ff4b0cd3

started writing tests; what a surprise, everything is broken ;)
author Jeff Hammel <jhammel@mozilla.com>
date Sat, 01 Jan 2011 21:58:34 -0800
parents 46c2d0a7335a
children 0cba953a03ca
files examples/doctest.txt examples/test.py makeitso/__init__.py makeitso/makeitso.py
diffstat 4 files changed, 51 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- /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()
+    
--- /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()
--- 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 *
--- 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: