Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for 'gs' as alias for 'gcs' in pytest servers #182

Merged
merged 1 commit into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ The `tmp_upath` fixture can be used for parametrizing paths with pytest's indire

.. code:: python

@pytest.mark.parametrize("tmp_upath", ["local", "s3", "gcs"], indirect=True)
@pytest.mark.parametrize("tmp_upath", ["local", "s3", "gcs", "gs"], indirect=True)
def test_something(tmp_upath):
pass

Expand Down
44 changes: 43 additions & 1 deletion src/pytest_servers/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ class TempUPathFactory:
"_gcs_endpoint_url",
requires_docker=True,
),
"gs": MockRemote(
"fake_gcs_server",
"_gcs_endpoint_url",
requires_docker=True,
),
"s3": MockRemote(
"s3_server",
"_s3_client_kwargs",
Expand Down Expand Up @@ -103,6 +108,7 @@ def mktemp( # noqa: C901 # complex-structure
- s3
- azure
- gcs
- gs (alias for gcs)

:param mock:
Set to False to use real remotes
Expand Down Expand Up @@ -146,13 +152,20 @@ def mktemp( # noqa: C901 # complex-structure
msg = "missing connection string"
raise RemoteUnavailable(msg)
return self.azure(connection_string=self._azure_connection_string, **kwargs)

if fs == "gcs":
return self.gcs(
endpoint_url=self._gcs_endpoint_url,
version_aware=version_aware,
**kwargs,
)

if fs == "gs":
return self.gs(
endpoint_url=self._gcs_endpoint_url,
version_aware=version_aware,
**kwargs,
)
raise ValueError(fs)

def local(self) -> LocalPath:
Expand Down Expand Up @@ -237,12 +250,41 @@ def memory(
path.mkdir()
return path

def gs(
self,
endpoint_url: str | None = None,
*,
version_aware: bool = False,
**kwargs,
) -> UPath:
return self._gs(
"gs",
endpoint_url=endpoint_url,
version_aware=version_aware,
**kwargs,
)

def gcs(
self,
endpoint_url: str | None = None,
*,
version_aware: bool = False,
**kwargs,
) -> UPath:
return self._gs(
"gcs",
endpoint_url=endpoint_url,
version_aware=version_aware,
**kwargs,
)

def _gs(
self,
scheme: str,
endpoint_url: str | None = None,
*,
version_aware: bool = False,
**kwargs,
) -> UPath:
"""Create a new gcs bucket and return an UPath instance.

Expand All @@ -256,7 +298,7 @@ def gcs(
bucket_name = f"pytest-servers-{random_string()}"

path = UPath(
f"gcs://{bucket_name}",
f"{scheme}://{bucket_name}",
version_aware=version_aware,
**client_kwargs,
**kwargs,
Expand Down
2 changes: 2 additions & 0 deletions src/pytest_servers/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,5 +102,7 @@ def tmp_upath(
return tmp_upath_factory.mktemp("azure")
if param == "gcs":
return tmp_upath_factory.mktemp("gcs", version_aware=version_aware)
if param == "gs":
return tmp_upath_factory.mktemp("gs", version_aware=version_aware)
msg = f"unknown {param=}"
raise ValueError(msg)
8 changes: 6 additions & 2 deletions tests/test_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,15 @@
"gcs",
upath.implementations.cloud.GCSPath,
),
pytest.param(
"gs",
upath.implementations.cloud.GCSPath,
),
]


with_versioning = [
param for param in implementations if param.values[0] in ("s3", "gcs")
param for param in implementations if param.values[0] in ("s3", "gcs", "gs")
]


Expand All @@ -43,7 +47,7 @@
)
class TestTmpUPathFactory:
def test_init(self, tmp_upath_factory, fs, cls):
if fs == "gcs":
if fs in ("gcs", "gs"):
pytest.skip("gcsfs does not support .exists() on a bucket")
path = tmp_upath_factory.mktemp(fs)
assert isinstance(path, cls)
Expand Down
Loading