Ejemplo n.º 1
0
def test_line_separators_preserved(source_with_newline, newline):
    options = OPTIONS[0]
    options = attr.evolve(options, write_back=core.WriteBackMode.INPLACE)

    source = source_with_newline(newline)

    core.reformat_single_file(source, options=options)

    with open(source, "rb") as buf:
        _newline = core.decode_bytes(buf.read())[2]

        assert _newline == newline
Ejemplo n.º 2
0
def test_change_line_separators(source_with_newline, old_newline_mode,
                                new_newline_mode):
    options = OPTIONS[0]
    options = attr.evolve(options,
                          write_back=core.WriteBackMode.INPLACE,
                          newline=old_newline_mode)

    source = source_with_newline(core.NEWLINE_FROM_OPTION[old_newline_mode])

    core.reformat_single_file(source, options=options)

    options = attr.evolve(options,
                          write_back=core.WriteBackMode.INPLACE,
                          newline=new_newline_mode)

    core.reformat_single_file(source, options=options)

    with open(source, "rb") as buf:
        _newline = core.decode_bytes(buf.read())[2]

        assert _newline == core.NEWLINE_FROM_OPTION[new_newline_mode]