def test_parse_header_coding(): source = clean_whitespace(""" # coding: shift_jis # 今日は expr = 1 + 1 """) coding, header = transpile.parse_module_header(source) assert coding == "shift_jis" assert header == "# coding: shift_jis\n# 今日は\n" source_data = source.encode("shift_jis") coding, header = transpile.parse_module_header(source_data) assert coding == "shift_jis" assert header == "# coding: shift_jis\n# 今日は\n"
def test_fixers(fixture): expected_source = utils.clean_whitespace(fixture.expected_source) expected_ast = utils.parsedump_ast(expected_source) expected_header = transpile.parse_module_header(expected_source, fixture.target_version) test_source = utils.clean_whitespace(fixture.test_source) _debug_ast("testcase", test_source) _debug_ast("expected", expected_source) ctx = common.init_build_context( target_version=fixture.target_version, fixers=fixture.names, filepath="<testfile>" ) results = utils.transpile_and_dump(ctx, test_source) result_header_coding, result_header_text, result_source = results _debug_ast("result", result_source) result_ast = utils.parsedump_ast(result_source) assert result_header_coding == expected_header.coding assert result_header_text == expected_header.text assert result_ast == expected_ast assert _normalized_source(result_source) == _normalized_source(expected_source)
def test_parse_header_simple(): coding, header = transpile.parse_module_header( clean_whitespace(""" # coding: ascii # Header line expr = 1 + 1 """)) assert coding == "ascii" assert header == "# coding: ascii\n# Header line\n"
def test_parse_header_simple(): source = clean_whitespace( """ # coding: ascii # Header line expr = 1 + 1 """ ) header = transpile.parse_module_header(source, "2.7") assert header.coding == "ascii" assert header.text == "# coding: ascii\n# Header line\n"
def test_fixers(fixture): if "--capture=no" in sys.argv: print() expected_source = utils.clean_whitespace(fixture.expected_source) expected_ast = utils.parsedump_ast(expected_source) expected_coding, expected_header = transpile.parse_module_header( expected_source) test_source = utils.clean_whitespace(fixture.test_source) test_ast = utils.parsedump_ast(test_source) print(">>>>>>>>" * 9) print(test_ast) print("--------" * 9) print(repr(test_source)) print(">>>>>>>>" * 9) print("????????" * 9) # print(expected_ast) # print("--------" * 9) print(repr(expected_source)) print("????????" * 9) cfg = {"fixers": fixture.names, "target_version": fixture.target_version} result_coding, result_header, result_source = utils.transpile_and_dump( test_source, cfg) result_ast = utils.parsedump_ast(result_source) print("<<<<<<<<" * 9) # print(result_ast) # print("--------" * 9) print(repr(result_source)) print("<<<<<<<<" * 9) assert result_coding == expected_coding assert result_header == expected_header assert result_ast == expected_ast assert _normalized_source(result_source) == _normalized_source( expected_source)