Exemplo n.º 1
0
def test_base_suffix():
    assert PurePathy("my/library/fake_file.txt").suffix == ".txt"
    assert PurePathy("my/library.tar.gz").suffix == ".gz"
    assert PurePathy("my/library").suffix == ""
Exemplo n.º 2
0
def test_base_parent():
    assert PurePathy("foo//bar").parent == PurePathy("foo")
    assert PurePathy("foo/./bar").parent == PurePathy("foo")
    assert PurePathy("foo/../bar").parent == PurePathy(".")
    assert PurePathy("../bar").parent == PurePathy("..")
    assert PurePathy("foo", "../bar").parent == PurePathy(".")
    assert PurePathy("/foo/bar").parent == PurePathy("/foo")
    assert PurePathy(".").parent == PurePathy(".")
    assert PurePathy("/").parent == PurePathy("/")
Exemplo n.º 3
0
def test_base_name():
    assert PurePathy("my/library/fake_file.txt").name == "fake_file.txt"
Exemplo n.º 4
0
def test_base_relative_to():
    gcs_path = PurePathy("/etc/passwd")
    assert gcs_path.relative_to("/") == PurePathy("etc/passwd")
    assert gcs_path.relative_to("/etc") == PurePathy("passwd")
    with pytest.raises(ValueError):
        gcs_path.relative_to("/usr")
Exemplo n.º 5
0
def test_client_create_bucket(temp_folder: Path):
    bucket_target = temp_folder / "foo"
    assert bucket_target.exists() is False
    cl = BucketClientFS(temp_folder)
    cl.create_bucket(PurePathy("gs://foo/"))
    assert bucket_target.exists() is True
Exemplo n.º 6
0
def test_base_uri():
    assert PurePathy("/etc/passwd").as_uri() == "gs://etc/passwd"
    assert PurePathy("/etc/init.d/apache2").as_uri() == "gs://etc/init.d/apache2"
    assert PurePathy("/bucket/key").as_uri() == "gs://bucket/key"
Exemplo n.º 7
0
def test_base_reserved():
    assert not PurePathy("/a/b").is_reserved()
    assert not PurePathy("a/b").is_reserved()
Exemplo n.º 8
0
def test_base_join_paths():
    assert PurePathy(Path("foo"), Path("bar")) == PurePathy("foo/bar")
Exemplo n.º 9
0
def test_base_empty():
    assert PurePathy() == PurePathy(".")
Exemplo n.º 10
0
def test_base_fspath():
    assert os.fspath(PurePathy("/var/tests/fake")) == "/var/tests/fake"
Exemplo n.º 11
0
def test_base_join_strs():
    assert PurePathy("foo", "some/path", "bar") == PurePathy("foo/some/path/bar")
Exemplo n.º 12
0
def test_base_scheme_extraction():
    assert PurePathy("gs://var/tests/fake").scheme == "gs"
    assert PurePathy("s3://var/tests/fake").scheme == "s3"
    assert PurePathy("file://var/tests/fake").scheme == "file"
    assert PurePathy("/var/tests/fake").scheme == ""
Exemplo n.º 13
0
def test_base_repr():
    a = PurePathy("/var/tests/fake")
    assert a.as_posix() == "/var/tests/fake"
    assert repr(PurePathy("fake_file.txt")) == "PurePathy('fake_file.txt')"
    assert str(PurePathy("fake_file.txt")) == "fake_file.txt"
    assert bytes(PurePathy("fake_file.txt")) == b"fake_file.txt"
Exemplo n.º 14
0
def test_base_paths_of_a_different_flavour():
    with pytest.raises(TypeError):
        PurePathy("/bucket/key") < PurePosixPath("/bucket/key")

    with pytest.raises(TypeError):
        PureWindowsPath("/bucket/key") > PurePathy("/bucket/key")
Exemplo n.º 15
0
def test_base_suffixes():
    assert PurePathy("my/library.tar.gar").suffixes == [".tar", ".gar"]
    assert PurePathy("my/library.tar.gz").suffixes == [".tar", ".gz"]
    assert PurePathy("my/library").suffixes == []
Exemplo n.º 16
0
def test_base_absolute_paths():
    assert PurePathy("/etc", "/usr", "lib64") == PurePathy("/usr/lib64")
Exemplo n.º 17
0
def test_base_stem():
    assert PurePathy("my/library.tar.gar").stem == "library.tar"
    assert PurePathy("my/library.tar").stem == "library"
    assert PurePathy("my/library").stem == "library"
Exemplo n.º 18
0
def test_base_slashes_single_double_dots():
    assert PurePathy("foo//bar") == PurePathy("foo/bar")
    assert PurePathy("foo/./bar") == PurePathy("foo/bar")
    assert PurePathy("foo/../bar") == PurePathy("bar")
    assert PurePathy("../bar") == PurePathy("../bar")
    assert PurePathy("foo", "../bar") == PurePathy("bar")
Exemplo n.º 19
0
def test_base_absolute():
    assert PurePathy("/a/b").is_absolute()
    assert not PurePathy("a/b").is_absolute()
Exemplo n.º 20
0
def test_base_operators():
    assert PurePathy("/etc") / "init.d" / "apache2" == PurePathy("/etc/init.d/apache2")
    assert "/var" / PurePathy("tests") / "fake" == PurePathy("/var/tests/fake")
Exemplo n.º 21
0
def test_base_joinpath():
    assert PurePathy("/etc").joinpath("passwd") == PurePathy("/etc/passwd")
    assert PurePathy("/etc").joinpath(PurePathy("passwd")) == PurePathy("/etc/passwd")
    assert PurePathy("/etc").joinpath("init.d", "apache2") == PurePathy(
        "/etc/init.d/apache2"
    )
Exemplo n.º 22
0
def test_base_parents():
    assert tuple(PurePathy("foo//bar").parents) == (
        PurePathy("foo"),
        PurePathy("."),
    )
    assert tuple(PurePathy("foo/./bar").parents) == (
        PurePathy("foo"),
        PurePathy("."),
    )
    assert tuple(PurePathy("foo/../bar").parents) == (PurePathy("."),)
    assert tuple(PurePathy("../bar").parents) == (PurePathy(".."), PurePathy("."))
    assert tuple(PurePathy("foo", "../bar").parents) == (PurePathy("."),)
    assert tuple(PurePathy("/foo/bar").parents) == (
        PurePathy("/foo"),
        PurePathy("/"),
    )
Exemplo n.º 23
0
def test_base_with_name():
    gcs_path = PurePathy("/Downloads/pathlib.tar.gz")
    assert gcs_path.with_name("fake_file.txt") == PurePathy("/Downloads/fake_file.txt")
    gcs_path = PurePathy("/")
    with pytest.raises(ValueError):
        gcs_path.with_name("fake_file.txt")
Exemplo n.º 24
0
def test_base_with_suffix():
    gcs_path = PurePathy("/Downloads/pathlib.tar.gz")
    assert gcs_path.with_suffix(".bz2") == PurePathy(
        "/Downloads/pathlib.tar.bz2")
    gcs_path = PurePathy("README")
    assert gcs_path.with_suffix(".txt") == PurePathy("README.txt")
    gcs_path = PurePathy("README.txt")
    assert gcs_path.with_suffix("") == PurePathy("README")