def init_local_class_then_gcs_path(clean):
    if skip_gcs["gcs"]:
        print("skipped")
        return

    init("local")
    p = TransparentPath("chien", fs="gcs", bucket=bucket)
    assert str(p.path) == f"{bucket}/chien"
    assert str(p) == f"gs://{bucket}/chien"
    assert p.__fspath__() == f"gs://{bucket}/chien"

    assert "gcs" in p.fs_kind
    assert p.fs == TransparentPath.fss["gcs_sandbox-281209"]
    assert not TransparentPath.unset
    assert len(TransparentPath.fss) == 2
    assert TransparentPath.fs_kind == "local"
    assert "gcs_sandbox-281209" in list(
        TransparentPath.fss.keys()) and "local" in list(
            TransparentPath.fss.keys())
    assert isinstance(TransparentPath.fss["gcs_sandbox-281209"],
                      gcsfs.GCSFileSystem)
    assert isinstance(TransparentPath.fss["local"], LocalFileSystem)
    reinit()

    init("local")
    with pytest.raises(ValueError):
        TransparentPath(f"gs://{bucket}/chien", bucket=bucket + "chien")

    with pytest.raises(ValueError):
        TransparentPath(f"gs://{bucket}/chien", fs="local", bucket=bucket)

    with pytest.raises(ValueError):
        TransparentPath(f"gs://{bucket}/chien")

    p = TransparentPath(f"gs://{bucket}/chien", )
    assert str(p.path) == f"{bucket}/chien"
    assert str(p) == f"gs://{bucket}/chien"
    assert p.__fspath__() == f"gs://{bucket}/chien"

    assert "gcs" in p.fs_kind
    assert p.fs == TransparentPath.fss["gcs_sandbox-281209"]
    assert not TransparentPath.unset
    assert len(TransparentPath.fss) == 2
    assert TransparentPath.fs_kind == "local"
    assert "gcs_sandbox-281209" in list(
        TransparentPath.fss.keys()) and "local" in list(
            TransparentPath.fss.keys())
    assert isinstance(TransparentPath.fss["gcs_sandbox-281209"],
                      gcsfs.GCSFileSystem)
    assert isinstance(TransparentPath.fss["local"], LocalFileSystem)
def test_path_success(clean, fs_kind, global_init, expected_fs_kind,
                      expected_fs_type, args, kwargs):
    if skip_gcs[fs_kind]:
        print("skipped")
        return

    if global_init:
        init(fs_kind)

    str_prefix, pathlib_prefix = get_prefixes(fs_kind)

    p = TransparentPath(*args, **kwargs)
    if "gs://" not in args[0]:
        assert str(p.path) == f"{pathlib_prefix}/{args[0]}"
        assert str(p) == f"{str_prefix}/{args[0]}"
        assert p.__fspath__() == f"{str_prefix}/{args[0]}"
    else:
        assert str(p.path) == f"{args[0].replace('gs://', '')}"
        assert str(p) == f"{args[0]}"
        assert p.__fspath__() == f"{args[0]}"

    assert fs_kind in p.fs_kind
    if global_init:
        for fs_name in TransparentPath.fss:
            if expected_fs_kind in fs_name:
                expected_fs_kind = fs_name
                break
        assert p.fs == TransparentPath.fss[expected_fs_kind]
        assert not TransparentPath.unset
        if expected_fs_kind == "local":
            assert len(TransparentPath.fss) == 1
        else:
            assert len(TransparentPath.fss) == 2
        assert TransparentPath.fs_kind == fs_kind
        assert list(TransparentPath.fss.keys())[-1] == expected_fs_kind
        assert isinstance(TransparentPath.fss[expected_fs_kind],
                          expected_fs_type)
    else:
        assert TransparentPath.unset
Exemplo n.º 3
0
def test_multipleexistenceerror(clean, fs_kind, excep):
    if skip_gcs[fs_kind]:
        print("skipped")
        return
    init(fs_kind)

    # noinspection PyTypeChecker
    with pytest.raises(excep):
        p1 = TransparentPath("chien")
        p2 = TransparentPath("chien") / "chat"
        p2.touch()
        if excep == FileExistsError:
            p1.touch()
        else:
            p1.fs.touch(p1.__fspath__())
        TransparentPath("chien").read()
def init_gcs_class_then_local_path(clean):
    if skip_gcs["gcs"]:
        print("skipped")
        return

    init("gcs")
    p = TransparentPath("chien", fs="local")
    assert str(p.path) == f"{os.getcwd()}/chien"
    assert str(p) == f"{os.getcwd()}/chien"
    assert p.__fspath__() == f"{os.getcwd()}/chien"

    assert p.fs_kind == "local"
    assert p.fs == TransparentPath.fss["local"]
    assert not TransparentPath.unset
    assert len(TransparentPath.fss) == 2
    assert "gcs" in TransparentPath.fs_kind
    assert "gcs_sandbox-281209" in list(
        TransparentPath.fss.keys()) and "local" in list(
            TransparentPath.fss.keys())
    assert isinstance(TransparentPath.fss["gcs_sandbox-281209"],
                      gcsfs.GCSFileSystem)
    assert isinstance(TransparentPath.fss["local"], LocalFileSystem)