Exemplo n.º 1
0
def test_decrease_indentation_brackets_2():
    code = """
  a = (fun()
    .filter())
"""
    red = RedBaron(code)
    red.decrease_indentation("  ")
    assert red.dumps() == deindent_str(code, "  ")
Exemplo n.º 2
0
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, "  ")
Exemplo n.º 3
0
def test_decrease_indentation_assignement_backslash():
    code = """
    a = \\
        1
"""
    red = RedBaron(code)
    red.decrease_indentation("  ")
    assert red.dumps() == deindent_str(code, "  ")
Exemplo n.º 4
0
def test_decrease_indentation_atom_node():
    code = """
    fun() \\
        .more()
"""
    red = RedBaron(code)
    red.decrease_indentation("  ")
    assert red.dumps() == deindent_str(code, "  ")
Exemplo n.º 5
0
    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
Exemplo n.º 6
0
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, "  ")
Exemplo n.º 7
0
def test_decrease_indentation_try_finally():
    code = """
    try:
        pass
    finally:
        pass
"""
    red = RedBaron(code)
    red.decrease_indentation("  ")
    assert red.dumps() == deindent_str(code, "  ")
Exemplo n.º 8
0
def test_decrease_indentation_while_else():
    code = """
    while cond:
        pass
    else:
        pass
"""
    red = RedBaron(code)
    red.decrease_indentation("  ")
    assert red.dumps() == deindent_str(code, "  ")
Exemplo n.º 9
0
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, "  ")
Exemplo n.º 10
0
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
Exemplo n.º 11
0
    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
Exemplo n.º 12
0
def test_decrease_indentation():
    red = RedBaron(test_indent_code)
    red.decrease_indentation("  ")
    assert red.dumps() == deindent_str(test_indent_code, "  ")