Commits

Anonymous committed d4d590e

I think reindention is working fine. :)

  • Participants
  • Parent commits b9e67cc

Comments (0)

Files changed (2)

File new_template.py

         return line
 
 def should_unindent(parsed_line):
-    unindentation_words = ('pass', 'else', 'elif')
+    unindentation_words = ('pass', 'else', 'elif', 'except')
     return parsed_line.split()[0].replace(':', '').strip() in unindentation_words
 
 
         if parsed_line:
             if should_unindent(parsed_line):
                 indentation_level -= 1
-            response.append(indentation_level * '    ' + parsed_line)
+            if parsed_line.strip() != 'pass':
+                response.append(indentation_level * '    ' + parsed_line)
 
     return response
 

File test_new_template.py

         self.do_it()
 
 
-    def test_if_elif_and_else_in_python_code_should_indent_only_block_lines(self):
+    def test_if_elif_else_for_else_try_except_with_in_python_code_should_indent_only_block_lines(self):
         self.input_ = '''{{if something:
 some_code
 other_code
 code_on_else
 other_code_on_else
 pass
-code_outside}}'''
+code_outside
+for a in b:
+code_on_for
+other_code
+pass
+some_code_outsite
+for c in d:
+code_on_second_for
+other_code_on_second_for
+else:
+code_on_else
+other_code_on_else
+pass
+other_code_outside
+try:
+something
+code_to_try
+except:
+code_on_the_exception
+blablabla
+pass
+code_outside
+try:
+other_try_code
+more_one_line
+except SomeExcetion, e:
+lets_solve_this_exception
+more_code
+except:
+code_to_general_exception
+goes_here
+pass
+more_code_outside_all_blocks}}'''
         self.expected_output = '''if something:
     some_code
     other_code
 else:
     code_on_else
     other_code_on_else
-code_outside'''
+code_outside
+for a in b:
+    code_on_for
+    other_code
+some_code_outsite
+for c in d:
+    code_on_second_for
+    other_code_on_second_for
+else:
+    code_on_else
+    other_code_on_else
+other_code_outside
+try:
+    something
+    code_to_try
+except:
+    code_on_the_exception
+    blablabla
+code_outside
+try:
+    other_try_code
+    more_one_line
+except SomeExcetion, e:
+    lets_solve_this_exception
+    more_code
+except:
+    code_to_general_exception
+    goes_here
+more_code_outside_all_blocks'''
         self.do_it()
 
 
+    def test_a_lot_of_indentation_levels(self):
+        self.input_ = '''{{if a:
+for b in c:
+try:
+if something:
+do_nothing
+pass
+pass
+pass
+pass}}'''
+        self.expected_output = '''if a:
+    for b in c:
+        try:
+            if something:
+                do_nothing'''
+        self.do_it()
+
 if __name__ == '__main__':
     if len(argv) == 1:
         import new_template