Skip to content

Commit

Permalink
ci:add ci (#472)
Browse files Browse the repository at this point in the history
  • Loading branch information
LoveEatCandy authored Jan 7, 2025
1 parent 268768d commit 66ba0fd
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 6 deletions.
8 changes: 4 additions & 4 deletions megfile/lib/s3_pipe_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ def __init__(
join_thread: bool = True,
profile_name: Optional[str] = None,
):
if mode not in ("rb", "wb"):
raise ValueError("unacceptable mode: %r" % mode)

self._bucket = bucket
self._key = key
self._mode = mode
Expand All @@ -45,6 +42,9 @@ def __init__(
self._offset = 0
self._profile_name = profile_name

if mode not in ("rb", "wb"):
raise ValueError("unacceptable mode: %r" % mode)

self._exc = None
self._pipe = os.pipe()
_s3_opened_pipes.append(self._pipe)
Expand Down Expand Up @@ -76,7 +76,7 @@ def _download_fileobj(self):
try:
with os.fdopen(self._pipe[1], "wb") as buffer:
self._client.download_fileobj(self._bucket, self._key, buffer)
except BrokenPipeError:
except BrokenPipeError: # pragma: no cover
if self._fileobj.closed:
return
raise
Expand Down
2 changes: 0 additions & 2 deletions megfile/smart.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,6 @@ def register_copy_func(
dst_dict = _copy_funcs.get(src_protocol, {})
dst_dict[dst_protocol] = copy_func
_copy_funcs[src_protocol] = dst_dict
except Exception as error:
raise error
else:
raise ValueError(
"Copy Function has already existed: {}->{}".format(
Expand Down
3 changes: 3 additions & 0 deletions tests/lib/test_s3_pipe_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ def test_s3_pipe_handler_read(client):
assert reader.tell() == 22
assert reader.read() == b""

with pytest.raises(ValueError):
S3PipeHandler(BUCKET, KEY, "ab", s3_client=client)


def test_s3_pipe_handler_write(client):
with S3PipeHandler(BUCKET, KEY, "wb", s3_client=client) as writer:
Expand Down
20 changes: 20 additions & 0 deletions tests/lib/test_s3_prefetch_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -639,3 +639,23 @@ def test_s3_prefetch_reader_no_buffer(client_for_get_object):
reader.read()

assert list(reader._futures.keys()) == []


def test_s3_prefetch_reader_size(client_for_get_object, mocker):
def fake_fetch_response(*args, **kwargs):
return {
"ContentLength": 123,
"Body": None,
"ETag": "test",
}

mocker.patch(
"megfile.lib.s3_prefetch_reader.S3PrefetchReader._fetch_response",
fake_fetch_response,
)
with S3PrefetchReader(
BUCKET,
KEY,
s3_client=client_for_get_object,
) as reader:
assert reader._content_size == 123
5 changes: 5 additions & 0 deletions tests/test_fs_purepath.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import pathlib

import pytest

from megfile.fs_path import FSPath
Expand Down Expand Up @@ -59,6 +61,9 @@ def test_operators():
assert FSPath("file://foo") / "bar" / "baz" == FSPath("file://foo/bar/baz")
assert FSPath("foo") / "bar" / "baz" == FSPath("foo/bar/baz")
assert FSPath("file://foo") / "bar" / "baz" in {FSPath("file://foo/bar/baz")}
assert FSPath("file://foo") / pathlib.Path("bar") / "baz" in {
FSPath("file://foo/bar/baz")
}


def test_parts():
Expand Down
88 changes: 88 additions & 0 deletions tests/test_pathlike.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,91 @@ def test_uri_path(mocker):
with pytest.raises(ValueError):
uri_path.relative_to(1)
assert uri_path.resolve() == "fs://test"


def test_base_path_attr(mocker):
path = BasePath("/test")
with pytest.raises(NotImplementedError):
path / "test"

assert path.name == "/test"

with pytest.raises(NotImplementedError):
path.joinpath("test")

with pytest.raises(NotImplementedError):
path.parts

with pytest.raises(NotImplementedError):
path.parents

with pytest.raises(NotImplementedError):
path.parent

with pytest.raises(NotImplementedError):
path.is_dir()

with pytest.raises(NotImplementedError):
path.is_file()

assert path.is_symlink() is False

with pytest.raises(NotImplementedError):
path.access(None)

with pytest.raises(NotImplementedError):
path.exists()

with pytest.raises(NotImplementedError):
path.listdir()

with pytest.raises(NotImplementedError):
path.scandir()

with pytest.raises(NotImplementedError):
path.getsize()

with pytest.raises(NotImplementedError):
path.getmtime()

with pytest.raises(NotImplementedError):
path.stat()

with pytest.raises(NotImplementedError):
path.match(r"*")

with pytest.raises(NotImplementedError):
path.remove()

with pytest.raises(NotImplementedError):
path.mkdir()

with pytest.raises(NotImplementedError):
path.rmdir()

with pytest.raises(NotImplementedError):
path.open()

with pytest.raises(NotImplementedError):
path.walk()

with pytest.raises(NotImplementedError):
path.scan()

with pytest.raises(NotImplementedError):
path.scan_stat()

with pytest.raises(NotImplementedError):
path.glob(None)

with pytest.raises(NotImplementedError):
path.iglob(None)

with pytest.raises(NotImplementedError):
path.glob_stat(None)

with pytest.raises(NotImplementedError):
path.load()

with pytest.raises(NotImplementedError):
path.save(None)

0 comments on commit 66ba0fd

Please sign in to comment.