Skip to content

Commit e42491d

Browse files
authored
Add support for 'gs' as alias for 'gcs' in pytest servers (#182)
The commit extends pytest_servers to recognize 'gs' as an alias for 'gcs'. This allows users to use 'gs' as a parameter in pytest. Corresponding test cases have also been updated to reflect this change.
1 parent 21b6fbe commit e42491d

File tree

4 files changed

+52
-4
lines changed

4 files changed

+52
-4
lines changed

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ The `tmp_upath` fixture can be used for parametrizing paths with pytest's indire
109109

110110
.. code:: python
111111
112-
@pytest.mark.parametrize("tmp_upath", ["local", "s3", "gcs"], indirect=True)
112+
@pytest.mark.parametrize("tmp_upath", ["local", "s3", "gcs", "gs"], indirect=True)
113113
def test_something(tmp_upath):
114114
pass
115115

src/pytest_servers/factory.py

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ class TempUPathFactory:
2929
"_gcs_endpoint_url",
3030
requires_docker=True,
3131
),
32+
"gs": MockRemote(
33+
"fake_gcs_server",
34+
"_gcs_endpoint_url",
35+
requires_docker=True,
36+
),
3237
"s3": MockRemote(
3338
"s3_server",
3439
"_s3_client_kwargs",
@@ -103,6 +108,7 @@ def mktemp( # noqa: C901 # complex-structure
103108
- s3
104109
- azure
105110
- gcs
111+
- gs (alias for gcs)
106112
107113
:param mock:
108114
Set to False to use real remotes
@@ -146,13 +152,20 @@ def mktemp( # noqa: C901 # complex-structure
146152
msg = "missing connection string"
147153
raise RemoteUnavailable(msg)
148154
return self.azure(connection_string=self._azure_connection_string, **kwargs)
155+
149156
if fs == "gcs":
150157
return self.gcs(
151158
endpoint_url=self._gcs_endpoint_url,
152159
version_aware=version_aware,
153160
**kwargs,
154161
)
155162

163+
if fs == "gs":
164+
return self.gs(
165+
endpoint_url=self._gcs_endpoint_url,
166+
version_aware=version_aware,
167+
**kwargs,
168+
)
156169
raise ValueError(fs)
157170

158171
def local(self) -> LocalPath:
@@ -237,12 +250,41 @@ def memory(
237250
path.mkdir()
238251
return path
239252

253+
def gs(
254+
self,
255+
endpoint_url: str | None = None,
256+
*,
257+
version_aware: bool = False,
258+
**kwargs,
259+
) -> UPath:
260+
return self._gs(
261+
"gs",
262+
endpoint_url=endpoint_url,
263+
version_aware=version_aware,
264+
**kwargs,
265+
)
266+
240267
def gcs(
241268
self,
242269
endpoint_url: str | None = None,
243270
*,
244271
version_aware: bool = False,
245272
**kwargs,
273+
) -> UPath:
274+
return self._gs(
275+
"gcs",
276+
endpoint_url=endpoint_url,
277+
version_aware=version_aware,
278+
**kwargs,
279+
)
280+
281+
def _gs(
282+
self,
283+
scheme: str,
284+
endpoint_url: str | None = None,
285+
*,
286+
version_aware: bool = False,
287+
**kwargs,
246288
) -> UPath:
247289
"""Create a new gcs bucket and return an UPath instance.
248290
@@ -256,7 +298,7 @@ def gcs(
256298
bucket_name = f"pytest-servers-{random_string()}"
257299

258300
path = UPath(
259-
f"gcs://{bucket_name}",
301+
f"{scheme}://{bucket_name}",
260302
version_aware=version_aware,
261303
**client_kwargs,
262304
**kwargs,

src/pytest_servers/fixtures.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,5 +102,7 @@ def tmp_upath(
102102
return tmp_upath_factory.mktemp("azure")
103103
if param == "gcs":
104104
return tmp_upath_factory.mktemp("gcs", version_aware=version_aware)
105+
if param == "gs":
106+
return tmp_upath_factory.mktemp("gs", version_aware=version_aware)
105107
msg = f"unknown {param=}"
106108
raise ValueError(msg)

tests/test_factory.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,15 @@
2828
"gcs",
2929
upath.implementations.cloud.GCSPath,
3030
),
31+
pytest.param(
32+
"gs",
33+
upath.implementations.cloud.GCSPath,
34+
),
3135
]
3236

3337

3438
with_versioning = [
35-
param for param in implementations if param.values[0] in ("s3", "gcs")
39+
param for param in implementations if param.values[0] in ("s3", "gcs", "gs")
3640
]
3741

3842

@@ -43,7 +47,7 @@
4347
)
4448
class TestTmpUPathFactory:
4549
def test_init(self, tmp_upath_factory, fs, cls):
46-
if fs == "gcs":
50+
if fs in ("gcs", "gs"):
4751
pytest.skip("gcsfs does not support .exists() on a bucket")
4852
path = tmp_upath_factory.mktemp(fs)
4953
assert isinstance(path, cls)

0 commit comments

Comments
 (0)