forked from fsspec/universal_pathlib
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_s3.py
More file actions
82 lines (66 loc) · 2.41 KB
/
test_s3.py
File metadata and controls
82 lines (66 loc) · 2.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
"""see upath/tests/conftest.py for fixtures
"""
import pytest # noqa: F401
from upath import UPath
from upath.errors import NotDirectoryError
from upath.implementations.cloud import S3Path
from ..cases import BaseTests
class TestUPathS3(BaseTests):
SUPPORTS_EMPTY_DIRS = False
@pytest.fixture(autouse=True)
def path(self, s3_fixture):
path, anon, s3so = s3_fixture
self.path = UPath(path, anon=anon, **s3so)
self.anon = anon
self.s3so = s3so
def test_is_S3Path(self):
assert isinstance(self.path, S3Path)
def test_chmod(self):
# todo
pass
def test_rmdir(self):
dirname = "rmdir_test"
mock_dir = self.path.joinpath(dirname)
mock_dir.joinpath("test.txt").touch()
mock_dir.rmdir()
assert not mock_dir.exists()
with pytest.raises(NotDirectoryError):
self.path.joinpath("file1.txt").rmdir()
def test_relative_to(self):
assert "s3://test_bucket/file.txt" == str(
UPath("s3://test_bucket/file.txt").relative_to(
UPath("s3://test_bucket")
)
)
def test_iterdir_root(self):
client_kwargs = self.path._kwargs["client_kwargs"]
bucket_path = UPath(
"s3://other_test_bucket", client_kwargs=client_kwargs
)
bucket_path.mkdir(mode="private")
(bucket_path / "test1.txt").touch()
(bucket_path / "test2.txt").touch()
for x in bucket_path.iterdir():
assert x.name != ""
assert x.exists()
def test_touch_unlink(self):
path = self.path.joinpath("test_touch.txt")
path.touch()
assert path.exists()
path.unlink()
assert not path.exists()
# should raise FileNotFoundError since file is missing
with pytest.raises(FileNotFoundError):
path.unlink()
# file doesn't exists, but missing_ok is True
path.unlink(missing_ok=True)
@pytest.mark.parametrize(
"joiner", [["bucket", "path", "file"], "bucket/path/file"]
)
def test_no_bucket_joinpath(self, joiner):
path = UPath("s3://", anon=self.anon, **self.s3so)
path = path.joinpath(joiner)
assert str(path) == "s3://bucket/path/file"
def test_creating_s3path_with_bucket(self):
path = UPath("s3://", bucket="bucket", anon=self.anon, **self.s3so)
assert str(path) == "s3://bucket/"