changeset 40:6b4c8f23192f

test and fix mixed output case
author Jeff Hammel <jhammel@mozilla.com>
date Sun, 02 Jan 2011 00:48:58 -0800
parents a2cdce0108e1
children 9956e13558dd
files examples/doctest.txt examples/test.py makeitso/makeitso.py
diffstat 3 files changed, 25 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/examples/doctest.txt	Sat Jan 01 23:00:59 2011 -0800
+++ b/examples/doctest.txt	Sun Jan 02 00:48:58 2011 -0800
@@ -56,4 +56,24 @@
 Mixed case:
 
     >>> template = makeitso.PolyTemplate([example, exampledir])
+    >>> variables = sorted(template.missing())
+    >>> variables
+    ['bar', 'foo', 'name', 'subdir']
 
+You need to provide output for mixing files and directory templates:
+
+    >>> variables = dict([(i, i.title()) for i in variables])
+    >>> try:
+    ...    template.substitute(**variables)
+    ... except AssertionError, e:
+    ...    pass
+    >>> e
+    AssertionError('Must specify output ...
+
+Provide an output:
+
+    >>> template = makeitso.PolyTemplate([example, exampledir], output=tempdir, interactive=False)
+    >>> template.substitute(**variables)
+    >>> sorted(os.listdir(tempdir))
+    ['Subdir', 'example.txt', 'foo.txt']
+    >>> shutil.rmtree(tempdir)
--- a/examples/test.py	Sat Jan 01 23:00:59 2011 -0800
+++ b/examples/test.py	Sun Jan 02 00:48:58 2011 -0800
@@ -12,7 +12,10 @@
     extraglobs = {'here': directory}
     tests =  [ 'doctest.txt' ]
     for test in tests:
-        doctest.testfile(test, extraglobs=extraglobs, raise_on_error=False)
+        doctest.testfile(test,
+                         optionflags=doctest.ELLIPSIS,
+                         extraglobs=extraglobs,
+                         raise_on_error=False)
 
 if __name__ == '__main__':
     run_tests()
--- a/makeitso/makeitso.py	Sat Jan 01 23:00:59 2011 -0800
+++ b/makeitso/makeitso.py	Sun Jan 02 00:48:58 2011 -0800
@@ -315,7 +315,7 @@
         # determine where the hell to put these things
         if self.output is None:
             dirs = [i for i in self._templates if os.path.isdir(i)]
-            if not ((len(dirs) == 0) or len(dirs) == len(templates)):
+            if not ((len(dirs) == 0) or len(dirs) == len(self.templates)):
                 raise AssertionError("Must specify output when mixing directories and URIs")
         
         # TODO: check for missing