# HG changeset patch # User Jeff Hammel # Date 1322177345 28800 # Node ID d3e3a506dd29645645afe5a35c195e83296a0168 # Parent ba47f936e9f6aa325c153244a7132773435adcf0 tests now pass diff -r ba47f936e9f6 -r d3e3a506dd29 licenser/licenses.py --- 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: diff -r ba47f936e9f6 -r d3e3a506dd29 tests/doctest.txt --- 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 diff -r ba47f936e9f6 -r d3e3a506dd29 tests/test.py --- 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