|
14 | 14 |
|
15 | 15 | import pytest |
16 | 16 | import mock |
| 17 | +import math |
17 | 18 | import datetime |
18 | 19 |
|
19 | 20 | from google.cloud.firestore_v1 import _helpers |
@@ -117,6 +118,13 @@ def test_to_pb(self, input_val, to_pb_val): |
117 | 118 | instance = Constant.of(input_val) |
118 | 119 | assert instance._to_pb() == to_pb_val |
119 | 120 |
|
| 121 | + @pytest.mark.parametrize("input", [float("nan"), math.nan]) |
| 122 | + def test_nan_to_pb(self, input): |
| 123 | + instance = Constant.of(input) |
| 124 | + assert repr(instance) == "Constant.of(math.nan)" |
| 125 | + pb_val = instance._to_pb() |
| 126 | + assert math.isnan(pb_val.double_value) |
| 127 | + |
120 | 128 | @pytest.mark.parametrize( |
121 | 129 | "input_val,expected", |
122 | 130 | [ |
@@ -284,7 +292,7 @@ def test__from_query_filter_pb_composite_filter_or(self, mock_client): |
284 | 292 | field1 = Field.of("field1") |
285 | 293 | field2 = Field.of("field2") |
286 | 294 | expected_cond1 = expr.And(field1.exists(), field1.equal(Constant("val1"))) |
287 | | - expected_cond2 = expr.And(field2.exists(), field2.is_null()) |
| 295 | + expected_cond2 = expr.And(field2.exists(), field2.equal(None)) |
288 | 296 | expected = expr.Or(expected_cond1, expected_cond2) |
289 | 297 |
|
290 | 298 | assert repr(result) == repr(expected) |
@@ -371,7 +379,7 @@ def test__from_query_filter_pb_composite_filter_nested(self, mock_client): |
371 | 379 | field3 = Field.of("field3") |
372 | 380 | expected_cond1 = expr.And(field1.exists(), field1.equal(Constant("val1"))) |
373 | 381 | expected_cond2 = expr.And(field2.exists(), field2.greater_than(Constant(10))) |
374 | | - expected_cond3 = expr.And(field3.exists(), field3.is_not_null()) |
| 382 | + expected_cond3 = expr.And(field3.exists(), expr.Not(field3.equal(None))) |
375 | 383 | expected_inner_and = expr.And(expected_cond2, expected_cond3) |
376 | 384 | expected_outer_or = expr.Or(expected_cond1, expected_inner_and) |
377 | 385 |
|
@@ -400,18 +408,21 @@ def test__from_query_filter_pb_composite_filter_unknown_op(self, mock_client): |
400 | 408 | @pytest.mark.parametrize( |
401 | 409 | "op_enum, expected_expr_func", |
402 | 410 | [ |
403 | | - (query_pb.StructuredQuery.UnaryFilter.Operator.IS_NAN, Expression.is_nan), |
| 411 | + ( |
| 412 | + query_pb.StructuredQuery.UnaryFilter.Operator.IS_NAN, |
| 413 | + lambda x: x.equal(float("nan")), |
| 414 | + ), |
404 | 415 | ( |
405 | 416 | query_pb.StructuredQuery.UnaryFilter.Operator.IS_NOT_NAN, |
406 | | - Expression.is_not_nan, |
| 417 | + lambda x: expr.Not(x.equal(float("nan"))), |
407 | 418 | ), |
408 | 419 | ( |
409 | 420 | query_pb.StructuredQuery.UnaryFilter.Operator.IS_NULL, |
410 | | - Expression.is_null, |
| 421 | + lambda x: x.equal(None), |
411 | 422 | ), |
412 | 423 | ( |
413 | 424 | query_pb.StructuredQuery.UnaryFilter.Operator.IS_NOT_NULL, |
414 | | - Expression.is_not_null, |
| 425 | + lambda x: expr.Not(x.equal(None)), |
415 | 426 | ), |
416 | 427 | ], |
417 | 428 | ) |
@@ -846,42 +857,6 @@ def test_if_absent(self): |
846 | 857 | infix_instance = arg1.if_absent(arg2) |
847 | 858 | assert infix_instance == instance |
848 | 859 |
|
849 | | - def test_is_nan(self): |
850 | | - arg1 = self._make_arg("Value") |
851 | | - instance = Expression.is_nan(arg1) |
852 | | - assert instance.name == "is_nan" |
853 | | - assert instance.params == [arg1] |
854 | | - assert repr(instance) == "Value.is_nan()" |
855 | | - infix_instance = arg1.is_nan() |
856 | | - assert infix_instance == instance |
857 | | - |
858 | | - def test_is_not_nan(self): |
859 | | - arg1 = self._make_arg("Value") |
860 | | - instance = Expression.is_not_nan(arg1) |
861 | | - assert instance.name == "is_not_nan" |
862 | | - assert instance.params == [arg1] |
863 | | - assert repr(instance) == "Value.is_not_nan()" |
864 | | - infix_instance = arg1.is_not_nan() |
865 | | - assert infix_instance == instance |
866 | | - |
867 | | - def test_is_null(self): |
868 | | - arg1 = self._make_arg("Value") |
869 | | - instance = Expression.is_null(arg1) |
870 | | - assert instance.name == "is_null" |
871 | | - assert instance.params == [arg1] |
872 | | - assert repr(instance) == "Value.is_null()" |
873 | | - infix_instance = arg1.is_null() |
874 | | - assert infix_instance == instance |
875 | | - |
876 | | - def test_is_not_null(self): |
877 | | - arg1 = self._make_arg("Value") |
878 | | - instance = Expression.is_not_null(arg1) |
879 | | - assert instance.name == "is_not_null" |
880 | | - assert instance.params == [arg1] |
881 | | - assert repr(instance) == "Value.is_not_null()" |
882 | | - infix_instance = arg1.is_not_null() |
883 | | - assert infix_instance == instance |
884 | | - |
885 | 860 | def test_is_error(self): |
886 | 861 | arg1 = self._make_arg("Value") |
887 | 862 | instance = Expression.is_error(arg1) |
|
0 commit comments