Fokko commented on code in PR #2593:
URL: https://github.com/apache/iceberg-python/pull/2593#discussion_r2449284683
##########
tests/expressions/test_expressions.py:
##########
@@ -738,6 +738,29 @@ def test_not() -> None:
assert not_ == pickle.loads(pickle.dumps(not_))
+def test_not_json_serialization_and_deserialization() -> None:
+ expr = Not(AlwaysFalse())
+ json_str = expr.model_dump_json()
+ restored = Not.model_validate_json(json_str)
+ assert isinstance(restored, AlwaysTrue)
+
+ expr2 = Not(Not(AlwaysFalse()))
+ json_str2 = expr2.model_dump_json()
+ restored2 = Not.model_validate_json(json_str2)
+ assert isinstance(restored2, AlwaysFalse)
+
+ class DummyExpr(BooleanExpression):
+ def __invert__(self) -> BooleanExpression:
+ return self
+
+ dummy = DummyExpr()
+ not_dummy = Not(child=dummy)
+ json_str3 = not_dummy.model_dump_json()
+ restored3 = Not.model_validate_json(json_str3)
+ assert isinstance(restored3, Not)
+ assert isinstance(restored3.child, DummyExpr)
Review Comment:
Let's make this test much simpler for now. `Not(AlwaysFalse())` will
automatically be rewritten to `AlwaysTrue()`, so the test is not a real round
trip. Let simplify it to:
```suggestion
def test_not_json_serialization_and_deserialization() -> None:
not_expr = Not(GreaterThan("a", 22))
json_str = not_expr.model_dump_json()
assert json_str ==
"""{"type":"not","child":{"term":"a","type":"gt","value":22}}"""
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]