Skip to content

Commit

Permalink
fix: tests fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
wyfo committed Apr 11, 2024
1 parent 79a045d commit aaf59ce
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 34 deletions.
4 changes: 2 additions & 2 deletions examples/z_get.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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 ('{}': '{}')"
Expand Down
5 changes: 2 additions & 3 deletions examples/z_pub_thr.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -63,14 +63,13 @@ 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)
pub = session.declare_publisher('test/thr', congestion_control=congestion_control)

print("Press CTRL-C to quit...")
while True:
pub.put(data)
pub.put(bytes(data))

main()
2 changes: 1 addition & 1 deletion examples/z_queryable.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
16 changes: 0 additions & 16 deletions tests/examples_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -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"])
Expand Down
12 changes: 1 addition & 11 deletions zenoh/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion zenoh/value.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit aaf59ce

Please sign in to comment.