def test_set_trailing(): assert format_code("{3,}") == "{3,}"
def test_assert(): assert format_code("assert a") == "assert a" assert format_code("assert a , b") == "assert a, b"
def test_dict_comprehension(): assert format_code("{ x : z for x in x }") == "{x: z for x in x}"
def test_def_arguments_dict_argument(): assert format_code("def a( ** b ):\n pass") == "def a(**b):\n pass\n"
def test_raise(): assert format_code("raise Exception()") == "raise Exception()" assert format_code("raise Exception() , b") == "raise Exception(), b" assert format_code("raise Exception() , b , c") == "raise Exception(), b, c"
def test_replace_old_comparison_operator(): assert format_code("a <> b") == "a != b"
def test_respect_backslash(): respect_backslash = "a ==\\\n b" assert format_code(respect_backslash) == respect_backslash respect_backslash = "a \\\n== b" assert format_code(respect_backslash) == respect_backslash
def test_fix_bad_indentation_simple_too_big(): assert format_code("if a:\n pass") == "if a:\n pass\n"
def test_fix_indentation_complex(): print("result:") print(format_code(bad_indentation)) print("expected:") print(bad_indentation_fixed) assert format_code(bad_indentation) == bad_indentation_fixed
def test_replace_tabs(): assert format_code("if a:\n if b:\n pass\n\n") == "if a:\n if b:\n pass\n\n"
def test_funcdef(): assert format_code("def a ( ) :\n pass") == "def a():\n pass\n"
def test_simily_print_function_stuff(): assert format_code("print(a)") == "print(a)"
def test_empty_comment_no_space(): assert format_code("#") == "#"
def test_dict_trailing(): assert format_code("{3: 3,}") == "{3: 3,}"
def test_split_semicolon(): assert format_code("a;b") == "a\nb"
def test_bug_reindent_tabs(): assert format_code(bug_reindent_tabs) == bug_reindent_tabs_fixed
def test_split_semicolon_indented(): assert format_code("\n a;b") == "\n a\n b"
def test_call_argument(): assert format_code("a( b = c )") == "a(b=c)"
def test_comment_previous_endl_indent_regression_test(): assert format_code(comment_previous_endl_indent) == comment_previous_endl_indent
def test_blank_lines_arround_functions_first_level(): assert format_code(root_level_function) == root_level_function_fixed
def test_on_self_tests(): assert format_code(open("./test_pyfmt.py", "r").read()) == open("./test_pyfmt.py", "r").read()
def test_blank_lines_arround_class_first_level(): assert format_code(root_level_function.replace('def', 'class')) == root_level_function_fixed.replace('def', 'class')
def test_return(): assert format_code("return") == "return" assert format_code("return a") == "return a"
def test_replace_windows_endl(): assert format_code("\r\n") == "\n"
def test_ternary_operator(): assert format_code("a if b else c") == "a if b else c"
def test_def_arguments(): assert format_code("def a( b =False):\n pass") == "def a(b=False):\n pass\n"
def test_set_comprehension(): assert format_code("{ x for x in x }") == "{x for x in x}"
def test_blank_lines_arround_methods(): assert format_code(class_level_function) == class_level_function_fixed
def test_generator_comprehension(): assert format_code("( x for x in x )") == "(x for x in x)"
def test_list_trailing(): assert format_code("[3,]") == "[3,]"