changeset 24:d3e3a506dd29

tests now pass
author Jeff Hammel <jhammel@mozilla.com>
date Thu, 24 Nov 2011 15:29:05 -0800
parents ba47f936e9f6
children 8729685a2cf6
files licenser/licenses.py tests/doctest.txt tests/test.py
diffstat 3 files changed, 24 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/licenser/licenses.py	Thu Nov 24 15:11:31 2011 -0800
+++ b/licenser/licenses.py	Thu Nov 24 15:29:05 2011 -0800
@@ -57,7 +57,7 @@
         self.filename = filename
 
     def isempty(self):
-        return bool(file(self.filename).read().strip)
+        return not bool(file(self.filename).read().strip)
 
     def lines(self):
         if hasattr(self, '_lines'):
@@ -80,7 +80,7 @@
 
         # print the license
         license_lines = license.splitlines()
-        for index, line in license_lines:
+        for index, line in enumerate(license_lines):
             prefix = ' *'
             suffix = ''
             if index == len(license_lines) - 1:
@@ -88,6 +88,7 @@
             if not index:
                 prefix = '/*'
             print >> f, '%s %s%s' % (prefix, line, suffix)
+        print >> f
 
         # print the rest of the file
         for line in lines:
--- a/tests/doctest.txt	Thu Nov 24 15:11:31 2011 -0800
+++ b/tests/doctest.txt	Thu Nov 24 15:29:05 2011 -0800
@@ -10,10 +10,23 @@
 Sanity check::
 
     >>> assert os.path.exists(directory)
+    >>> files = ['main.c', 'python_script.py']
+    >>> files = [os.path.join(directory, f) for f in files]    
 
 Test MPL license::
 
     >>> license = licenses.MPL()
+    >>> for f in files:
+    ...     license.has_license(f)
+    False
+    False
     >>> variables = {'author': 'Jeff Hammel', 'email': 'k0s@k0s.org'}
     >>> variables = license.obtain_variables(**variables)
     >>> license.interpolate(directory, variables)
+
+Assert files get licensed::
+
+    >>> for f in files:
+    ...     license.has_license(f)
+    True
+    True
--- a/tests/test.py	Thu Nov 24 15:11:31 2011 -0800
+++ b/tests/test.py	Thu Nov 24 15:29:05 2011 -0800
@@ -11,7 +11,7 @@
 import tempfile
 from optparse import OptionParser
 
-def run_tests(raise_on_error=False, report_first=False):
+def run_tests(raise_on_error=False, report_first=False, cleanup=True):
 
     # add results here
     results = {}
@@ -43,7 +43,10 @@
             raise failure.exc_info[0], failure.exc_info[1], failure.exc_info[2]
         finally:
             # cleanup
-            shutil.rmtree(tempdir)
+            if cleanup:
+                shutil.rmtree(tempdir)
+            else:
+                print '%s: %s' % (test, tempdir)
 
     return results
 
@@ -57,6 +60,9 @@
     parser.add_option('--report-first', dest='report_first',
                       default=False, action='store_true',
                       help="report the first error only (all tests will still run)")
+    parser.add_option('--no-cleanup', dest='cleanup',
+                      action='store_false', default=True,
+                      help="don't cleanup following the tests")
     options, args = parser.parse_args(args)
 
     # run the tests