Commits

Anonymous committed a971189

Added more 2 tests on comment issues: if we have just comment inside a template tag it should return an empty string

  • Participants
  • Parent commits d584acd

Comments (0)

Files changed (2)

 
 def should_unindent_before(parsed_line):
     unindentation_words = ('else', 'elif', 'except')
-    return parsed_line.split()[0].replace(':', '').strip() in unindentation_words
+    if parsed_line.strip():
+        return parsed_line.split()[0].replace(':', '').strip() in unindentation_words
+    else:
+        return ''
 
 
 def should_unindent_after(parsed_line):
     unindentation_words = ('pass', 'break', 'continue', 'return')
-    return parsed_line.split()[0].replace(':', '').strip() in unindentation_words
+    if parsed_line.strip():
+        return parsed_line.split()[0].replace(':', '').strip() in unindentation_words
+    else:
+        return ''
 
 
 def parse_python_code(python_code, indentation_level=0):
             if parsed_line:
                 if should_unindent_before(parsed_line):
                     indentation_level -= 1
-                if parsed_line.strip() != 'pass':
+                if parsed_line.strip() != 'pass' and parsed_line.strip():
                     response.append(indentation_level * '    ' + parsed_line)
                 if should_unindent_after(parsed_line):
                     indentation_level -= 1
         if parsed_line:
             if should_unindent_before(parsed_line):
                 indentation_level -= 1
-            if parsed_line.strip() != 'pass':
+            if parsed_line.strip() != 'pass' and parsed_line.strip():
                 response.append(indentation_level * '    ' + parsed_line)
             if should_unindent_after(parsed_line):
                 indentation_level -= 1

test_new_template.py

 class TestParsePythonTemplateTag(unittest.TestCase):
     do_it = do_it
 
+    def test_parse_none_should_return_empty_string(self):
+        self.input_ = '''{{}}'''
+        self.expected_output = ''
+        self.do_it()
+
+
     def test_parse_plain_text_should_return_one_response_write_with_the_text(self):
         self.input_ = 'just plain text'
         self.expected_output = 'response.write("%s", escape=False)' % \
         self.do_it()
 
 
+    def test_parse_a_code_with_just_one_comment_should_return_empty_string(self):
+        self.input_ = '''{{ #bla bla bla}}'''
+        self.expected_output = ''
+        self.do_it()
+
+
     def test_python_comments_used_inside_template_tags_should_not_be_returned(self):
         self.input_ = """some plain text {{='hi' # some comment
 ='hello'}}"""