コード例 #1
0
async def test_rmtree(any_dir):
    assert [p async for p in bbb.listdir(any_dir)] == []

    N = 5
    await asyncio.wait([
        helpers.unsafe_create_file(any_dir / "alpha" / str(i))
        for i in range(N)
    ] + [
        helpers.unsafe_create_file(any_dir / "alpha" / "beta" / str(i))
        for i in range(N)
    ])
    with pytest.raises(NotADirectoryError):
        async with bbb.BoostExecutor(N) as e:
            await bbb.rmtree(any_dir / "alpha" / "0", e)

    async with bbb.BoostExecutor(N) as e:
        assert len([p async for p in bbb.listdir(any_dir / "alpha")]) == N + 1
        assert len([p async for p in bbb.listtree(any_dir / "alpha")]) == 2 * N
        await bbb.rmtree(any_dir / "alpha", e)

    with pytest.raises(FileNotFoundError):
        async with bbb.BoostExecutor(N) as e:
            await bbb.rmtree(any_dir / "alpha", e)

    with pytest.raises(FileNotFoundError):
        [p async for p in bbb.listdir(any_dir / "alpha")]
    assert [p async for p in bbb.listdir(any_dir)] == []
    assert [p async for p in bbb.listtree(any_dir)] == []
コード例 #2
0
async def test_remove(any_dir):
    assert [p async for p in bbb.listdir(any_dir)] == []
    helpers.create_file(any_dir / "alpha")

    with pytest.raises((IsADirectoryError, PermissionError)):
        await bbb.remove(any_dir)

    assert [p.name async for p in bbb.listdir(any_dir)] == ["alpha"]
    await bbb.remove(any_dir / "alpha")
    assert [p async for p in bbb.listdir(any_dir)] == []
コード例 #3
0
async def test_listtree(any_dir):
    async def _listtree(d):
        return sorted([p.relative_to(any_dir) async for p in bbb.listtree(d)])

    assert await _listtree(any_dir) == []

    helpers.create_file(any_dir / "alpha")
    helpers.create_file(any_dir / "bravo")
    helpers.create_file(any_dir / "charlie" / "delta" / "echo")

    assert await _listtree(any_dir) == ["alpha", "bravo", "charlie/delta/echo"]
    assert [p.name async for p in bbb.listdir(any_dir / "charlie")] == ["delta"]

    with pytest.raises(FileNotFoundError):
        [p.name async for p in bbb.listdir(any_dir / "foxtrot")]
    with pytest.raises(FileNotFoundError):
        [p.name async for p in bbb.listdir(any_dir / "alp")]
    with pytest.raises(NotADirectoryError):
        [p.name async for p in bbb.listdir(any_dir / "alpha")]
コード例 #4
0
async def test_listdir(any_dir):
    assert [p async for p in bbb.listdir(any_dir)] == []

    helpers.create_file(any_dir / "alpha")
    helpers.create_file(any_dir / "bravo")

    assert sorted([p.name async for p in bbb.listdir(any_dir)]) == ["alpha", "bravo"]

    helpers.create_file(any_dir / "charlie" / "delta" / "echo")

    assert sorted([p.name async for p in bbb.listdir(any_dir)]) == ["alpha", "bravo", "charlie"]
    assert [p.name async for p in bbb.listdir(any_dir / "charlie")] == ["delta"]
    assert [p.name async for p in bbb.listdir(any_dir / "charlie" / "delta")] == ["echo"]

    with pytest.raises(FileNotFoundError):
        [p.name async for p in bbb.listdir(any_dir / "foxtrot")]
    with pytest.raises(FileNotFoundError):
        [p.name async for p in bbb.listdir(any_dir / "alp")]
    with pytest.raises(NotADirectoryError):
        [p.name async for p in bbb.listdir(any_dir / "alpha")]
コード例 #5
0
async def ls(path: str, long: bool = False, machine: bool = False) -> None:
    path_obj = bbb.BasePath.from_str(path)
    if is_glob(path):
        it = bbb.listing.glob_scandir(path_obj)
        if long:
            await print_long(it, human_readable=not machine)
        else:
            async for entry in it:
                print(entry.path)
        return

    try:
        if long:
            await print_long(bbb.scandir(path_obj), human_readable=not machine)
        else:
            async for p in bbb.listdir(path_obj):
                print(p)
    except NotADirectoryError:
        if long:
            stat = await bbb.stat(path_obj)
            entry = bbb.listing.DirEntry.from_path_stat(path_obj, stat)
            print(entry.format(human_readable=not machine))
        else:
            print(path_obj)
コード例 #6
0
async def test_glob_scandir(any_dir):
    assert [p async for p in bbb.listdir(any_dir)] == []

    await asyncio.wait(
        [
            helpers.unsafe_create_file(any_dir / "A.X"),
            helpers.unsafe_create_file(any_dir / "A.Y"),
            helpers.unsafe_create_file(any_dir / "B.X"),
            helpers.unsafe_create_file(any_dir / "B.Y"),
        ]
    )

    async def glob(pattern):
        return sorted([p.path.name async for p in bbb.listing.glob_scandir(pattern)])

    assert await glob(any_dir / "*X") == ["A.X", "B.X"]
    assert await glob(any_dir / "A*") == ["A.X", "A.Y"]
    assert await glob(any_dir / "A*X") == ["A.X"]
    assert await glob(any_dir) == ["A.X", "A.Y", "B.X", "B.Y"]

    if isinstance(any_dir, AzurePath):
        assert any_dir.container in (await glob(AzurePath(any_dir.account, "*", "")))
    if isinstance(any_dir, GooglePath):
        assert any_dir.bucket in (await glob(GooglePath("*", "")))
コード例 #7
0
async def test_google_list_buckets():
    with helpers.tmp_google_dir() as google_dir:
        bucket = GooglePath("", "")
        assert google_dir.bucket in [p.name async for p in bbb.listdir(bucket)]
コード例 #8
0
async def test_azure_list_containers():
    with helpers.tmp_azure_dir() as az_dir:
        account = AzurePath(az_dir.account, "", "")
        assert az_dir.container in [p.name async for p in bbb.listdir(account)]