Example #1
0
def test_touch(s3bucket, contents, key, expect):
    for k, v in contents.items():
        s3bucket.put(k, v)
    S3Path(f"{s3bucket.root}/{key}").touch(exist_ok=False)

    for k, v in expect.items():
        assert s3bucket.get(k)["Body"].read().decode("utf-8") == v
Example #2
0
def test_open(s3bucket, rmode, wmode, file_cls, expect):
    p = S3Path(f"{s3bucket.root}/file")
    with p.open(wmode) as fw:
        assert isinstance(fw, file_cls)
        fw.write(expect)
    with p.open(rmode) as fr:
        assert isinstance(fr, file_cls)
        assert fr.read() == expect
Example #3
0
def test_touch_exist_ok(s3bucket, contents):
    originals = {}
    for k, v in contents.items():
        s3bucket.put(k, v)
        originals[k] = s3bucket.get(k)

    time.sleep(1)

    for k, v in contents.items():
        S3Path(f"{s3bucket.root}/{k}").touch(exist_ok=True)

    for k, org in originals.items():
        touched = s3bucket.get(k)
        assert org["ETag"] == touched["ETag"]
        assert org["LastModified"] < touched["LastModified"]
Example #4
0
def test_iterdir(s3bucket, keys, root, expect):
    for k in keys:
        s3bucket.put(k)
    it = S3Path(f"{s3bucket.root}/{root}").iterdir()
    assert isinstance(it, collections.abc.Iterable)
    assert set(it) == {S3Path(f"{s3bucket.root}/{p}") for p in expect}
Example #5
0
def test_read_write_bytes(s3bucket, expect):
    url = f"{s3bucket.root}/file"
    S3Path(url).write_bytes(expect)
    assert S3Path(url).read_bytes() == expect
Example #6
0
def test_path_predicate(api_name):
    assert getattr(S3Path("s3://example/com"), api_name)() == False
Example #7
0
def test_path_public_api_fail(api_name, args):
    getattr(S3Path("s3://example/"), api_name)(*args)
Example #8
0
def test_is_dir(s3bucket, key, content, expect):
    s3bucket.put(key, content)
    assert S3Path(f"{s3bucket.root}/{key}").is_dir() == expect
Example #9
0
def test_exists(s3bucket, putstr, pathstr, expect):
    s3bucket.put(putstr)
    assert S3Path(f"{s3bucket.root}{pathstr}").exists() == expect
Example #10
0
def test_mkdir_fail(s3bucket, pathstr, expect):
    s3bucket.put("parent/")
    with pytest.raises(expect):
        S3Path(f"{s3bucket.root}/{pathstr}").mkdir()
Example #11
0
def test_mkdir(s3bucket, key, args):
    s3bucket.put("parent/")
    S3Path(f"{s3bucket.root}/{key}").mkdir(**args)
    assert s3bucket.get(f"{key.rstrip('/')}/")
Example #12
0
def test_touch_fail(s3bucket, key, args, expect):
    s3bucket.put("exist")
    with pytest.raises(expect):
        S3Path(f"{s3bucket.root}/{key}").touch(**args)
Example #13
0
            marks=pytest.mark.skip(reason="minio doesn't support directories"),
        ),
        ("key/file", "", False),
        ("key/dir/", "", True),
    ],
)
def test_is_dir(s3bucket, key, content, expect):
    s3bucket.put(key, content)
    assert S3Path(f"{s3bucket.root}/{key}").is_dir() == expect


@pytest.mark.parametrize(
    ["api_name", "args"],
    [
        ("home", []),
        ("samefile", [S3Path("s3://other/abc")]),
        ("glob", ["*.py"]),
        ("rglob", ["*.py"]),
        ("absolute", []),
        pytest.param(
            "stat",
            [],
            marks=pytest.mark.skipif(
                (3, 10) <= sys.version_info,
                reason="python 3.10 require stat implementation",
            ),
        ),
        ("owner", []),
        ("readlink", []),
        ("chmod", [0x666]),
        ("lchmod", [0x666]),