Exemplo n.º 1
0
def _black_roundtrip(path):
    import black

    with open(path, "r", encoding='utf8') as f:
        contents = f.read()

    output = _run_black(contents)
    again = _run_black(output)

    assert output == again, ("Black not idempotent on file %s" % path)

    # Now we decode both versions with the traditional codec and compare.
    orig_pyxl = pyxl_transform_string(contents, invertible=False)
    new_pyxl = pyxl_transform_string(output, invertible=False)

    black.assert_equivalent(orig_pyxl, new_pyxl)
Exemplo n.º 2
0
def _expect_failure(file_name):
    path = os.path.join(error_cases_path, file_name)
    try:
        with open(path, 'r') as f:
            print(pyxl_transform_string(f.read()))
        assert False, "successfully decoded file %r" % file_name
    except (PyxlParseError, ParseError):
        pass
Exemplo n.º 3
0
def _run_black(contents):
    import black

    # Run black on the file. We manually encode and decode ourselves
    # to avoid needing to make black find the right codec.
    mode = black.FileMode()
    return pyxl_invert_string(
        black.format_str(pyxl_transform_string(contents, invertible=True),
                         mode=mode))
Exemplo n.º 4
0
def _roundtrip(file_name):
    path = os.path.join(dir_path, file_name)
    with open(path, "r", encoding='utf8') as f:
        contents = f.read()
        depyxled = pyxl_transform_string(contents, invertible=True)

        # Make sure the transformed string parses
        try:
            ast.parse(depyxled)
        except Exception as e:
            raise Exception("Parse error in file %s" % file_name)
        # Verify that it round trips without change
        assert contents == pyxl_invert_string(depyxled), (
            "Could not round-trip file %s" % file_name)
Exemplo n.º 5
0
#!/usr/bin/env python

import sys
from pyxl.codec.transform import pyxl_invert_string, pyxl_transform_string

if __name__ == '__main__':
    invert = invertible = False
    if sys.argv[1] == '-i':
        invertible = True
        fname = sys.argv[2]
    elif sys.argv[1] == '-r':
        invert = True
        fname = sys.argv[2]
    else:
        fname = sys.argv[1]
    with open(fname, 'r') as f:
        contents = f.read()
        if invert:
            print(pyxl_invert_string(contents), end='')
        else:
            print(pyxl_transform_string(contents, invertible), end='')