Commit f2f9c518 authored by Robin Obůrka's avatar Robin Obůrka

tests: Add some more tests of argument and resource parsing

parent e7168d04
import pytest
import zmq
import sn
@pytest.fixture
def zmq_context():
return zmq.Context.instance()
@pytest.fixture
def arg_parser():
return sn.get_arg_parser()
......@@ -12,6 +18,49 @@ def empty_args():
@pytest.fixture(params=[
"--resource",
"--resource BAD",
"--resource res,connect,PUSH,,",
"--resource res,connect,PUSH,sentinel.cz,",
"--resource res,connect,PULL,,7700",
"--resource ,connect,PUSH,sentinel.cz,7700",
"--resource connect,PUSH,sentinel.cz,7700",
"--resource res,connect,PUSh,sentinel.cz,7700",
"--resource res,connect,FOO,sentinel.cz,7700",
"--resource res,connect,FOO,sentinel.cz,7700",
"--resource res,connect,PUSH,sentinel.cz,0",
"--resource res,connect,PUSH,*,8800",
"--resource res,connect,PUSH,localhost,8800"
" --resource res,connect,PUSH,localhost,8800",
"--resource res,bind,PULL,localhost,8800"
" --resource res,bind,PULL,localhost,8800",
])
def bad_args(request):
return request.param.split(" ")
@pytest.fixture(params=[
"--resource res,connect,PUSH,127.0.0.1,8800",
"--resource res,connect,PUSH,setinel.turris.cz,8800",
])
def conn_args(request):
return request.param.split(" ")
@pytest.fixture(params=[
"--resource res,bind,PUSH,*,8800",
"--resource res,bind,PULL,*,8801",
"--resource res,bind,PULL,127.0.0.1,8802",
])
def bind_args(request):
return request.param.split(" ")
@pytest.fixture(params=[
"--resource res1,connect,PUSH,localhost,8800"
" --resource res2,connect,PUSH,localhost,8800",
"--resource res1,connect,PUSH,localhost,8800"
" --resource res1,connect,PUSH,localhost,8801"
" --resource res2,connect,PUB,localhost,8802",
"--resource res1,connect,PUB,localhost,8800"
" --resource res1,connect,PUB,localhost,8801"
" --resource res2,connect,PUB,localhost,8802",
])
def multisock_args(request):
return request.param.split(" ")
import pytest
import argparse
import zmq
import sn
......@@ -8,6 +9,21 @@ def test_empty_args(arg_parser, empty_args):
with pytest.raises(SystemExit):
arg_parser.parse_args(empty_args)
def test_bad_args(arg_parser, bad_args):
with pytest.raises(SystemExit):
arg_parser.parse_args(bad_args)
def test_bad_args(zmq_context, arg_parser, bad_args):
with pytest.raises((SystemExit, sn.SockConfigError, zmq.error.ZMQError)):
ctx = sn.SN(zmq_context, arg_parser, args=bad_args)
assert ctx.get_socket("res")
def test_connect_args(zmq_context, arg_parser, conn_args):
ctx = sn.SN(zmq_context, arg_parser, args=conn_args)
assert ctx.get_socket("res")
def test_bind_args(zmq_context, arg_parser, bind_args):
ctx = sn.SN(zmq_context, arg_parser, args=bind_args)
assert ctx.get_socket("res")
def test_multisock_args(zmq_context, arg_parser, multisock_args):
ctx = sn.SN(zmq_context, arg_parser, args=multisock_args)
r1, r2 = ctx.get_socket("res1", "res2")
assert r1
assert r2
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