예제 #1
0
def test_canonicalize_imports_f_string_1():
    input = PythonBlock(
        dedent('''
        a = 1
        print(f"{a:2d}")
    ''').lstrip(),
        filename="/foo/test_canonicalize_imports_f_string_1.py")
    db = ImportDB("""
    """)
    output = canonicalize_imports(input, db=db)
    expected = PythonBlock(
        dedent('''
        a = 1
        print(f"{a:2d}")
    ''').lstrip(),
        filename="/foo/test_canonicalize_imports_f_string_1.py")
    assert output == expected
예제 #2
0
def test_canonicalize_imports_1():
    input = PythonBlock(dedent('''
        from m import x
        from m import x as X
        import m.x
        print(m.x, m.xx)
    ''').lstrip(), filename="/foo/test_transform_imports_1.py")
    db = ImportDB("""
        __canonical_imports__ = {"m.x": "m.y.z"}
    """)
    output = canonicalize_imports(input, db=db)
    expected = PythonBlock(dedent('''
        import m.y.z
        from m.y import z as X, z as x
        print(m.y.z, m.xx)
    ''').lstrip(), filename="/foo/test_transform_imports_1.py")
    assert output == expected
예제 #3
0
def test_empty_file_1():
    input = PythonBlock('', filename="/foo/test_empty_file_1.py")
    db = ImportDB("")
    output = canonicalize_imports(input, db=db)
    expected = PythonBlock('', filename="/foo/test_empty_file_1.py")
    assert output == expected