예제 #1
0
def test_path_4():
    """
    指定できないパスの場合は ValueError になるテスト
    """

    with pytest.raises(ValueError):
        input_path = pathlib.PosixPath("input_test")
        input_root = pathlib.PosixPath("input_test/folder1")
        output_root = pathlib.PosixPath("output_test")
        resolve_output_dir_path(input_path, input_root, output_root)
예제 #2
0
def test_path_2():
    """
    指定パスから1階層深いテスト
    """
    input_path = pathlib.PosixPath("input_test/folder1")
    input_root = pathlib.PosixPath("input_test")
    output_root = pathlib.PosixPath("output_test")
    res = resolve_output_dir_path(input_path, input_root, output_root)
    assert str(res) == "output_test/folder1"
예제 #3
0
def test_path():
    """
    指定パス直下のテスト
    """
    input_path = pathlib.PosixPath("input_test")
    input_root = pathlib.PosixPath("input_test")
    output_root = pathlib.PosixPath("output_test")
    res = resolve_output_dir_path(input_path, input_root, output_root)
    assert str(res) == "output_test"
예제 #4
0
def test_path_7():
    """
    相対パス
    """

    input_path = pathlib.PosixPath("../web_image_converter/input_test/folder1")
    input_root = pathlib.PosixPath("../web_image_converter/input_test")
    output_root = pathlib.PosixPath("../web_image_converter/output_test")
    res = resolve_output_dir_path(input_path, input_root, output_root)
    assert str(res) == "../web_image_converter/output_test/folder1"
예제 #5
0
def test_path_3():
    """
    絶対パスのテスト
    """
    pwd = pathlib.PosixPath(os.getcwd())
    input_path = pwd / "input_test/folder1"
    input_root = pwd / "input_test"
    output_root = pwd / "output_test"
    res = resolve_output_dir_path(input_path, input_root, output_root)
    assert str(res) == str(pwd / "output_test/folder1")
예제 #6
0
def test_path_6():
    """
    相対パス input と絶対パス output
    """

    pwd = pathlib.PosixPath(os.getcwd())
    input_path = pathlib.PosixPath("input_test/folder1")
    input_root = pathlib.PosixPath("input_test")
    output_root = pwd / "output_test"
    res = resolve_output_dir_path(input_path, input_root, output_root)
    assert str(res) == str(pwd / "output_test/folder1")
예제 #7
0
def test_path_5():
    """
    絶対パス input と相対パス output
    """

    pwd = pathlib.PosixPath(os.getcwd())
    input_path = pwd / "input_test/folder1"
    input_root = pwd / "input_test"
    output_root = pathlib.PosixPath("output_test")
    res = resolve_output_dir_path(input_path, input_root, output_root)
    assert str(res) == "output_test/folder1"
예제 #8
0
def convert_all(
    input_root_dir: PosixPath,
    output_root_dir: PosixPath,
) -> None:
    # NOTE: os.walk使うより、再帰処理にしたほうがきれいかも?(雑にメモリに展開されすぎている気がする)
    for dir_path, dir_list, file_list in os.walk(input_root_dir):
        file_count = len(file_list)
        if file_count == 0:
            # skip
            continue
        logger.debug(f"{dir_path} count: {file_count}")
        for filename in file_list:
            file_path = pathlib.PosixPath(filename)
            input_dir = pathlib.PosixPath(dir_path)
            output_dir = resolve_output_dir_path(input_dir, input_root_dir,
                                                 output_root_dir)
            convert(
                input_dir=input_dir,
                output_dir=output_dir,
                file_path=file_path,
            )