Skip to content
This repository was archived by the owner on Mar 2, 2026. It is now read-only.

Commit c62f3d9

Browse files
chore: improve pipelines tests (#1116)
1 parent 643f014 commit c62f3d9

25 files changed

Lines changed: 3910 additions & 3384 deletions

google/cloud/firestore_v1/_pipeline_stages.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,13 @@ class UnnestOptions:
112112
storing the original 0-based index of the element within the array.
113113
"""
114114

115-
def __init__(self, index_field: str):
116-
self.index_field = index_field
115+
def __init__(self, index_field: Field | str):
116+
self.index_field = (
117+
index_field if isinstance(index_field, Field) else Field.of(index_field)
118+
)
117119

118120
def __repr__(self):
119-
return f"{self.__class__.__name__}(index_field={self.index_field!r})"
121+
return f"{self.__class__.__name__}(index_field={self.index_field.path!r})"
120122

121123

122124
class Stage(ABC):
@@ -258,13 +260,7 @@ def of(*documents: "BaseDocumentReference") -> "Documents":
258260
return Documents(*doc_paths)
259261

260262
def _pb_args(self):
261-
return [
262-
Value(
263-
array_value={
264-
"values": [Value(string_value=path) for path in self.paths]
265-
}
266-
)
267-
]
263+
return [Value(reference_value=path) for path in self.paths]
268264

269265

270266
class FindNearest(Stage):
@@ -306,15 +302,23 @@ def _pb_options(self) -> dict[str, Value]:
306302
class GenericStage(Stage):
307303
"""Represents a generic, named stage with parameters."""
308304

309-
def __init__(self, name: str, *params: Expr | Value):
305+
def __init__(
306+
self, name: str, *params: Expr | Value, options: dict[str, Expr | Value] = {}
307+
):
310308
super().__init__(name)
311309
self.params: list[Value] = [
312310
p._to_pb() if isinstance(p, Expr) else p for p in params
313311
]
312+
self.options: dict[str, Value] = {
313+
k: v._to_pb() if isinstance(v, Expr) else v for k, v in options.items()
314+
}
314315

315316
def _pb_args(self):
316317
return self.params
317318

319+
def _pb_options(self):
320+
return self.options
321+
318322
def __repr__(self):
319323
return f"{self.__class__.__name__}(name='{self.name}')"
320324

@@ -437,7 +441,7 @@ def _pb_args(self):
437441
def _pb_options(self):
438442
options = {}
439443
if self.options is not None:
440-
options["index_field"] = Value(string_value=self.options.index_field)
444+
options["index_field"] = self.options.index_field._to_pb()
441445
return options
442446

443447

google/cloud/firestore_v1/pipeline_expressions.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,6 @@ def _to_pb(self) -> Value:
112112
@staticmethod
113113
def _cast_to_expr_or_convert_to_constant(o: Any, include_vector=False) -> "Expr":
114114
"""Convert arbitrary object to an Expr."""
115-
if isinstance(o, Constant) and isinstance(o.value, list):
116-
o = o.value
117115
if isinstance(o, Expr):
118116
return o
119117
if isinstance(o, dict):
@@ -143,7 +141,7 @@ def __init__(self, instance_func):
143141
def static_func(self, first_arg, *other_args, **kwargs):
144142
if not isinstance(first_arg, (Expr, str)):
145143
raise TypeError(
146-
f"`expressions must be called on an Expr or a string representing a field name. got {type(first_arg)}."
144+
f"'{self.instance_func.__name__}' must be called on an Expression or a string representing a field. got {type(first_arg)}."
147145
)
148146
first_expr = (
149147
Field.of(first_arg) if not isinstance(first_arg, Expr) else first_arg
@@ -152,7 +150,7 @@ def static_func(self, first_arg, *other_args, **kwargs):
152150

153151
def __get__(self, instance, owner):
154152
if instance is None:
155-
return self.static_func.__get__(instance, owner)
153+
return self.static_func
156154
else:
157155
return self.instance_func.__get__(instance, owner)
158156

@@ -1280,7 +1278,7 @@ def map_get(self, key: str | Constant[str]) -> "Expr":
12801278

12811279
@expose_as_static
12821280
def map_remove(self, key: str | Constant[str]) -> "Expr":
1283-
"""Remove a key from the map produced by evaluating this expression.
1281+
"""Remove a key from a the map produced by evaluating this expression.
12841282
12851283
Example:
12861284
>>> Map({"city": "London"}).map_remove("city")

pytest.ini

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,5 @@ filterwarnings =
2222
ignore:.*The \`credentials_file\` argument is deprecated.*:DeprecationWarning
2323
# Remove after updating test dependencies that use asyncio.iscoroutinefunction
2424
ignore:.*\'asyncio.iscoroutinefunction\' is deprecated.*:DeprecationWarning
25-
ignore:.*\'asyncio.get_event_loop_policy\' is deprecated.*:DeprecationWarning
25+
ignore:.*\'asyncio.get_event_loop_policy\' is deprecated.*:DeprecationWarning
26+
ignore:.*Please upgrade to the latest Python version.*:FutureWarning

0 commit comments

Comments
 (0)