def test_decrease_indentation_brackets_2(): code = """ a = (fun() .filter()) """ red = RedBaron(code) red.decrease_indentation(" ") assert red.dumps() == deindent_str(code, " ")
def test_decrease_indentation_assignement_and_atom_node_2(): code = """ a = fun(). \\ more() """ red = RedBaron(code) red.decrease_indentation(" ") assert red.dumps() == deindent_str(code, " ")
def test_decrease_indentation_assignement_backslash(): code = """ a = \\ 1 """ red = RedBaron(code) red.decrease_indentation(" ") assert red.dumps() == deindent_str(code, " ")
def test_decrease_indentation_atom_node(): code = """ fun() \\ .more() """ red = RedBaron(code) red.decrease_indentation(" ") assert red.dumps() == deindent_str(code, " ")
def decrease_indentation(self, indent=None): if indent is None: indent = self.indent_unit if "\n" not in self.value: return super().decrease_indentation(indent=indent) self.value = deindent_str(indent + self.value, indent) # pylint: disable=attribute-defined-outside-init
def test_decrease_indentation_for_else(): code = """ for a in b: pass else: pass """ red = RedBaron(code) red.decrease_indentation(" ") assert red.dumps() == deindent_str(code, " ")
def test_decrease_indentation_try_finally(): code = """ try: pass finally: pass """ red = RedBaron(code) red.decrease_indentation(" ") assert red.dumps() == deindent_str(code, " ")
def test_decrease_indentation_while_else(): code = """ while cond: pass else: pass """ red = RedBaron(code) red.decrease_indentation(" ") assert red.dumps() == deindent_str(code, " ")
def test_decrease_indentation_try_except_else(): code = """ try: pass except: pass else: pass """ red = RedBaron(code) red.decrease_indentation(" ") assert red.dumps() == deindent_str(code, " ")
def test_deindent_str(): test_indent_code = """ def a(): # plop 1 + 2 if caramba: plop pouf """ indented_code = """ def a(): # plop 1 + 2 if caramba: plop pouf """ assert deindent_str(test_indent_code, " ") == indented_code
def decrease_indentation(self, indent=None): if indent is None: indent = self.indent_unit super().decrease_indentation(indent=indent) self.indent = deindent_str(self.indent, indent) # pylint: disable=attribute-defined-outside-init
def test_decrease_indentation(): red = RedBaron(test_indent_code) red.decrease_indentation(" ") assert red.dumps() == deindent_str(test_indent_code, " ")