Exemplo n.º 1
0
def test_patma_hint() -> None:
    source, expected = read_data("pattern_matching_simple")
    mode = black.Mode(target_versions={black.TargetVersion.PY39})
    with pytest.raises(black.parsing.InvalidInput) as exc_info:
        assert_format(source, expected, mode, minimum_version=(3, 10))

    exc_info.match(black.parsing.PY310_HINT)
Exemplo n.º 2
0
def test_patma_invalid() -> None:
    source, expected = read_data("pattern_matching_invalid")
    mode = black.Mode(target_versions={black.TargetVersion.PY310})
    with pytest.raises(black.parsing.InvalidInput) as exc_info:
        assert_format(source, expected, mode, minimum_version=(3, 10))

    exc_info.match("Cannot parse: 10:11")
Exemplo n.º 3
0
def test_remove_with_brackets() -> None:
    source, expected = read_data("remove_with_brackets")
    assert_format(
        source,
        expected,
        black.Mode(preview=True),
        minimum_version=(3, 9),
    )
Exemplo n.º 4
0
def test_python_2_hint() -> None:
    with pytest.raises(black.parsing.InvalidInput) as exc_info:
        assert_format("print 'daylily'", "print 'daylily'")
    exc_info.match(black.parsing.PY2_HINT)
Exemplo n.º 5
0
def test_python_310_without_target_version() -> None:
    source, expected = read_data("pattern_matching_simple")
    mode = black.Mode()
    assert_format(source, expected, mode, minimum_version=(3, 10))
Exemplo n.º 6
0
def test_python_310(filename: str) -> None:
    source, expected = read_data(filename)
    mode = black.Mode(target_versions={black.TargetVersion.PY310})
    assert_format(source, expected, mode, minimum_version=(3, 10))
Exemplo n.º 7
0
def test_long_first_line() -> None:
    source, expected = read_data("long_first_line")
    assert_format(source, expected, mode=black.Mode(use_tabs=True))
Exemplo n.º 8
0
def test_python39() -> None:
    source, expected = read_data("python39")
    assert_format(source, expected, minimum_version=(3, 9))
Exemplo n.º 9
0
def test_numeric_literals_ignoring_underscores() -> None:
    source, expected = read_data("numeric_literals_skip_underscores")
    mode = replace(DEFAULT_MODE, target_versions=PY36_VERSIONS)
    assert_format(source, expected, mode)
Exemplo n.º 10
0
def test_pep_572_remove_parens() -> None:
    source, expected = read_data("pep_572_remove_parens")
    assert_format(source, expected, minimum_version=(3, 8))
Exemplo n.º 11
0
def test_empty() -> None:
    source = expected = ""
    assert_format(source, expected)
Exemplo n.º 12
0
def check_file(filename: str, mode: black.Mode, *, data: bool = True) -> None:
    source, expected = read_data(filename, data=data)
    assert_format(source, expected, mode, fast=False)
Exemplo n.º 13
0
def test_python2_print_function() -> None:
    source, expected = read_data("python2_print_function")
    mode = replace(DEFAULT_MODE, target_versions={black.TargetVersion.PY27})
    assert_format(source, expected, mode)
Exemplo n.º 14
0
def test_line_length_tabs() -> None:
    source, expected = read_data("line_length_tabs")
    assert_format(source,
                  expected,
                  mode=black.Mode(line_length=20, use_tabs=True))
Exemplo n.º 15
0
def test_docstring_tabs() -> None:
    source, expected = read_data("docstring_tabs")
    assert_format(source, expected, mode=black.Mode(use_tabs=True))
Exemplo n.º 16
0
def test_docstring_no_string_normalization() -> None:
    """Like test_docstring but with string normalization off."""
    source, expected = read_data("docstring_no_string_normalization")
    mode = replace(DEFAULT_MODE, string_normalization=False)
    assert_format(source, expected, mode)
Exemplo n.º 17
0
def test_long_strings_flag_disabled() -> None:
    """Tests for turning off the string processing logic."""
    source, expected = read_data("long_strings_flag_disabled")
    mode = replace(DEFAULT_MODE, experimental_string_processing=False)
    assert_format(source, expected, mode)
Exemplo n.º 18
0
def test_pep_572_do_not_remove_parens() -> None:
    source, expected = read_data("pep_572_do_not_remove_parens")
    # the AST safety checks will fail, but that's expected, just make sure no
    # parentheses are touched
    assert_format(source, expected, fast=True)
Exemplo n.º 19
0
def test_stub() -> None:
    mode = replace(DEFAULT_MODE, is_pyi=True)
    source, expected = read_data("stub.pyi")
    assert_format(source, expected, mode)
Exemplo n.º 20
0
def test_pep_572_newer_syntax(major: int, minor: int) -> None:
    source, expected = read_data(f"pep_572_py{major}{minor}")
    assert_format(source, expected, minimum_version=(major, minor))
Exemplo n.º 21
0
def test_power_op_newline() -> None:
    # requires line_length=0
    source, expected = read_data("power_op_newline")
    assert_format(source, expected, mode=black.Mode(line_length=0))
Exemplo n.º 22
0
def test_pep_570() -> None:
    source, expected = read_data("pep_570")
    assert_format(source, expected, minimum_version=(3, 8))