From aaf59cea31638cf2c108cfb131dfc09f7b1a1784 Mon Sep 17 00:00:00 2001 From: Joseph Perez Date: Thu, 11 Apr 2024 11:58:23 +0200 Subject: [PATCH] fix: tests fixes --- examples/z_get.py | 4 ++-- examples/z_pub_thr.py | 5 ++--- examples/z_queryable.py | 2 +- tests/examples_check.py | 16 ---------------- zenoh/session.py | 12 +----------- zenoh/value.py | 4 +++- 6 files changed, 9 insertions(+), 34 deletions(-) diff --git a/examples/z_get.py b/examples/z_get.py index 5faa5361..bdcde0f8 100644 --- a/examples/z_get.py +++ b/examples/z_get.py @@ -17,7 +17,7 @@ import argparse import json import zenoh -from zenoh import config, QueryTarget +from zenoh import config, QueryTarget, into_payload # --- Command line argument parsing --- --- --- --- --- --- parser = argparse.ArgumentParser( @@ -79,7 +79,7 @@ def main(): session = zenoh.open(conf) print("Sending Query '{}'...".format(selector)) - replies = session.get(selector, zenoh.Queue(), target=target, value=args.value, consolidation=zenoh.QueryConsolidation.NONE()) + replies = session.get(selector, zenoh.Queue(), target=target, payload=into_payload(args.value), consolidation=zenoh.QueryConsolidation.NONE()) for reply in replies.receiver: try: print(">> Received ('{}': '{}')" diff --git a/examples/z_pub_thr.py b/examples/z_pub_thr.py index dc67e725..2b0b9e61 100644 --- a/examples/z_pub_thr.py +++ b/examples/z_pub_thr.py @@ -17,7 +17,7 @@ import argparse import json import zenoh -from zenoh import config, CongestionControl, Value +from zenoh import config, CongestionControl # --- Command line argument parsing --- --- --- --- --- --- parser = argparse.ArgumentParser( @@ -63,7 +63,6 @@ def main(): data = bytearray() for i in range(0, size): data.append(i % 10) - data = Value(bytes(data)) congestion_control = CongestionControl.BLOCK() session = zenoh.open(conf) @@ -71,6 +70,6 @@ def main(): print("Press CTRL-C to quit...") while True: - pub.put(data) + pub.put(bytes(data)) main() diff --git a/examples/z_queryable.py b/examples/z_queryable.py index 4223afba..0ec9fe6d 100644 --- a/examples/z_queryable.py +++ b/examples/z_queryable.py @@ -17,7 +17,7 @@ import argparse import json import zenoh -from zenoh import config, Sample, Value +from zenoh import config, Sample # --- Command line argument parsing --- --- --- --- --- --- parser = argparse.ArgumentParser( diff --git a/tests/examples_check.py b/tests/examples_check.py index 6c2d3e93..8a43edbf 100644 --- a/tests/examples_check.py +++ b/tests/examples_check.py @@ -81,7 +81,6 @@ def time(self): storage = Pyrun("z_storage.py") sub = Pyrun("z_sub.py") -pull = Pyrun("z_pull.py") time.sleep(1) put = Pyrun("z_put.py") if put.status(): @@ -91,21 +90,6 @@ def time(self): pub = Pyrun("z_pub.py", ["--iter=2"]) time.sleep(4) -pull.interrupt() -if pub.status(): - pub.dbg() - errors.append(pub.status()) -if pull.status(KILL): - pull.dbg() - errors.append(pull.status(KILL)) -subout = "".join(pull.stdout) -if not ("Received PUT ('demo/example/zenoh-python-put': 'Put from Python!')" in subout): - errors.append("z_pull didn't catch put") -if not ("Received PUT ('demo/example/zenoh-python-pub': '[ 1] Pub from Python!')" in subout): - errors.append("z_pull didn't catch second z_pub") -if any(("z_pull" in error) for error in errors): - pull.dbg() - queryable = Pyrun("z_queryable.py", ["-k=demo/example/zenoh-python-queryable"]) time.sleep(1) get = Pyrun("z_get.py", ["-s=demo/example/zenoh-python-queryable"]) diff --git a/zenoh/session.py b/zenoh/session.py index 8afa75d0..4223424b 100644 --- a/zenoh/session.py +++ b/zenoh/session.py @@ -142,15 +142,7 @@ def delete(self, keyexpr: IntoKeyExpr, kwargs['congestion_control'] = congestion_control return super().delete(keyexpr, **kwargs) - @overload - def get(self, selector: IntoSelector, handler: IntoHandler[Reply, Any, Receiver], consolidation: QueryConsolidation = None, target: QueryTarget = None) -> Receiver: - ... - - @overload - def get(self, selector: IntoSelector, handler: IntoHandler[Reply, Any, Receiver], consolidation: QueryConsolidation = None, target: QueryTarget = None, *, payload: IntoPayload, encoding: Encoding = None) -> Receiver: - ... - - def get(self, selector: IntoSelector, handler: IntoHandler[Reply, Any, Receiver], consolidation: QueryConsolidation = None, target: QueryTarget = None, payload = None, encoding = None) -> Receiver: + def get(self, selector: IntoSelector, handler: IntoHandler[Reply, Any, Receiver], consolidation: QueryConsolidation = None, target: QueryTarget = None, payload: IntoPayload = None, encoding: Encoding = None) -> Receiver: """ Emits a query, which queryables with intersecting selectors will be able to reply to. @@ -203,8 +195,6 @@ def get(self, selector: IntoSelector, handler: IntoHandler[Reply, Any, Receiver] if payload is not None: kwargs["payload"] = payload if encoding is not None: - if payload is None: - raise ValueError("encoding specified without payload") kwargs["encoding"] = encoding super().get(Selector(selector), handler.closure, **kwargs) return handler.receiver diff --git a/zenoh/value.py b/zenoh/value.py index 2e5bf91e..be526e04 100644 --- a/zenoh/value.py +++ b/zenoh/value.py @@ -22,7 +22,9 @@ IntoPayload = Union[bytes, str, int, float, bool, list, dict] -def into_payload(obj: IntoPayload) -> bytes: +def into_payload(obj: Optional[IntoPayload]) -> Optional[bytes]: + if obj is None: + return obj if isinstance(obj, bytes): return obj if isinstance(obj, str):