Commit 728a6e9c authored by Robin Obůrka's avatar Robin Obůrka

tests: Add module for testing network module

parent a9f9a045
from .fixtures import *
import pytest
import zmq
import sn
# This test proof that SN class is really able to generate working sockets.
# More input brutal test is in module argparser.
@pytest.fixture
def socket_binded():
ctx = zmq.Context.instance()
s = ctx.socket(zmq.PULL)
s.bind("tcp://127.0.0.1:8800")
s.ipv6 = True
yield s
s.close()
ctx.destroy()
@pytest.fixture
def socket_connected():
ctx = zmq.Context.instance()
s = ctx.socket(zmq.PUSH)
s.connect("tcp://127.0.0.1:8800")
s.ipv6 = True
yield s
s.close()
ctx.destroy()
import sn
def test_send(zmq_context, arg_parser, socket_binded):
msg = b"ping"
ctx = sn.SN(zmq_context, arg_parser, args=["--resource", "res,connect,PUSH,127.0.0.1,8800"])
s = ctx.get_socket("res")
assert s
s.send(msg)
m = socket_binded.recv()
assert m == msg
s.close()
ctx.context.destroy()
def test_recv(zmq_context, arg_parser, socket_connected):
msg = b"ping"
ctx = sn.SN(zmq_context, arg_parser, args=["--resource", "res,bind,PULL,127.0.0.1,8800"])
s = ctx.get_socket("res")
assert s
socket_connected.send(msg)
m = s.recv()
assert m == msg
s.close()
ctx.context.destroy()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment