Commits

Ronny Pfannschmidt committed 1b69138

test and fix for newline appending on metadata

  • Participants
  • Parent commits 92efb23

Comments (0)

Files changed (2)

genscript/module_maker.py

 def update_script(source, metadata):
     lines = source.splitlines(True)
     for index, line in enumerate(lines):
-        line = line.strip()
+        line = line.lstrip()
         if line and line[0] == '#' and 'Genscript Metadata' in line:
             if not line[-1] == '\n':
                 lines[index] = line + '\n'

testing/test_module_maker.py

     assert "\nversion = '1.3'\n" in result
     assert 'ending' in result
 
+def test_append_missing_newline():
+    script = '# Genscript Metadata'
+    result = update_script(script, {})
+    assert result == '# Genscript Metadata\n'
+
+    script = '# Genscript Metadata\n'
+    result = update_script(script, {})
+    assert result == '# Genscript Metadata\n'
+
+
 def test_update_fails_for_missing():
     py.test.raises(ValueError, update_script, 'test_line\n', {})