Exemplo n.º 1
0
def test_create_unasynced_single_file(sources: pathlib.Path) -> None:
    async_file_path = sources / "_async" / "inner_package" / "logic.py"
    sync_file_path = sources / "_async" / "inner_package" / "sync.py"

    next(unasync_path(async_file_path, sync_file_path))

    assert sync_file_path.exists()
Exemplo n.º 2
0
def test_raising_error_if_dir_does_not_exist_and_creation_disabled(
    sources: pathlib.Path, ) -> None:
    async_folder = sources / "_async"
    sync_folder = sources / "_sync"

    with pytest.raises(RuntimeError):
        next(unasync_path(async_folder, sync_folder,
                          create_missed_paths=False))
Exemplo n.º 3
0
def test_raising_error_for_not_files_or_dirs_in_unasync_path(
    sources: pathlib.Path, ) -> None:
    async_folder = sources / "_async"
    sync_folder = sources / "_sync"

    fifo_path = async_folder / "fifo"

    os.mkfifo(fifo_path)

    with pytest.raises(ValueError):
        next(unasync_path(fifo_path, sync_folder / "fifo"))
Exemplo n.º 4
0
def test_skiping_not_files_or_dirs(sources: pathlib.Path) -> None:
    async_folder = sources / "_async"
    sync_folder = sources / "_sync"

    fifo_path = async_folder / "fifo"

    os.mkfifo(fifo_path)

    [_ for _ in unasync_path(async_folder, sync_folder)]  # consume iterator

    assert not (sync_folder / "fifo").exists()
Exemplo n.º 5
0
def test_unasynced_file_content(sources: pathlib.Path,
                                expected_unasynced_code: str) -> None:
    async_file_path = sources / "_async" / "inner_package" / "logic.py"
    sync_file_path = sources / "_async" / "inner_package" / "sync.py"

    next(unasync_path(async_file_path, sync_file_path))

    with open(sync_file_path) as sync_file:
        content = sync_file.read()

    assert content == expected_unasynced_code
Exemplo n.º 6
0
def test_create_right_sync_structure_for_dir(sources: pathlib.Path) -> None:
    async_folder = sources / "_async"
    sync_folder = sources / "_sync"

    [_ for _ in unasync_path(async_folder, sync_folder)]  # consume iterator

    required_paths = [
        sync_folder / "__init__.py",
        sync_folder / "inner_package",
        sync_folder / "inner_package" / "__init__.py",
        sync_folder / "inner_package" / "logic.py",
    ]
    for path in required_paths:
        assert path.exists()
Exemplo n.º 7
0
def unasync(
    paths: List[pathlib.Path] = typer.Argument(...,
                                               exists=True),  # noqa: WPS404
    prefix: str = typer.Option(
        "",
        "--prefix",
        "-p",
        help='Replace "async" prefix with passed one for code entities.',
        show_default=True,
    ),
    unasync_root_prefix: str = typer.Option(
        "_sync",
        "--root-prefix",
        help="Prefix for unasynced root path.",
        show_default=True,
    ),
    create_folders: bool = typer.Option(
        True,  # noqa: WPS425
        "--create-folders/--no-folders",
        help="Create recursive paths for unasynced code.",
        show_default=True,
    ),
    _version: bool = typer.Option(
        False,
        "--version",
        "-v",
        callback=version_callback,  # noqa: WPS425
    ),
) -> None:
    """unasyncer - CLI to "unasync" your python code."""
    for path in paths:
        try:
            unasyncer = unasync_path(
                path,
                path.parent / unasync_root_prefix,
                prefix,
                create_folders,
            )
        except ValueError as not_file_error:
            typer.echo(str(not_file_error), err=True)
            raise typer.Exit(2)

        try:
            for processed_path in unasyncer:
                typer.echo(f"processed: {processed_path}")
        except RuntimeError as error:
            typer.echo(str(error), err=True)
            raise typer.Exit(2)

    typer.echo("unasyncing completed!")
Exemplo n.º 8
0
def test_raising_error_if_path_does_not_exist() -> None:
    with pytest.raises(FileNotFoundError):
        next(unasync_path(pathlib.Path("error_path"), pathlib.Path("_sync")))