Commit 44ce1f7b authored by Robin Obůrka's avatar Robin Obůrka

tests: Refactoring of argparser tests - parametrize tests directly

parent 4dba6b7b
......@@ -3,59 +3,5 @@ import pytest
import sn
@pytest.fixture
def empty_args():
return []
@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,conn,PUSH,127.0.0.1,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(" ")
@pytest.fixture
def required_args():
def required_type_arg():
return "--resource res,connect,PUSH,127.0.0.1,8800".split(" ")
......@@ -5,41 +5,87 @@ import zmq
import sn
def test_empty_args(arg_parser, empty_args):
def test_empty_args(arg_parser):
with pytest.raises(SystemExit):
arg_parser.parse_args(empty_args)
arg_parser.parse_args([])
def test_empty_args_native(zmq_context):
with pytest.raises(SystemExit):
ctx = sn.SN(zmq_context)
def test_bad_args(zmq_context, arg_parser, bad_args):
@pytest.mark.parametrize("bad_arg", [
"--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,conn,PUSH,127.0.0.1,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 test_bad_args(zmq_context, arg_parser, bad_arg):
with pytest.raises((SystemExit, sn.SockConfigError, zmq.error.ZMQError)):
ctx = sn.SN(zmq_context, arg_parser, args=bad_args)
ctx = sn.SN(zmq_context, arg_parser, args=bad_arg.split(" "))
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)
@pytest.mark.parametrize("conn_arg", [
"--resource res,connect,PUSH,127.0.0.1,8800",
"--resource res,connect,PUSH,setinel.turris.cz,8800",
])
def test_connect_args(zmq_context, arg_parser, conn_arg):
ctx = sn.SN(zmq_context, arg_parser, args=conn_arg.split(" "))
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)
@pytest.mark.parametrize("bind_arg", [
"--resource res,bind,PUSH,*,8800",
"--resource res,bind,PULL,*,8801",
"--resource res,bind,PULL,127.0.0.1,8802",
])
def test_bind_args(zmq_context, arg_parser, bind_arg):
ctx = sn.SN(zmq_context, arg_parser, args=bind_arg.split(" "))
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)
@pytest.mark.parametrize("multisock_arg", [
"--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 test_multisock_args(zmq_context, arg_parser, multisock_arg):
ctx = sn.SN(zmq_context, arg_parser, args=multisock_arg.split(" "))
assert ctx
r1, r2 = ctx.get_socket("res1", "res2")
assert r1
assert r2
def test_required_accept(zmq_context, arg_parser, required_args):
ctx = sn.SN(zmq_context, arg_parser, args=required_args)
def test_required_type_accept(zmq_context, arg_parser, required_type_arg):
ctx = sn.SN(zmq_context, arg_parser, args=required_type_arg)
assert ctx
assert ctx.get_socket(("res", "PUSH"))
def test_required_decline(zmq_context, arg_parser, required_args):
def test_required_type_decline(zmq_context, arg_parser, required_type_arg):
with pytest.raises(sn.SockConfigError):
ctx = sn.SN(zmq_context, arg_parser, args=required_args)
ctx = sn.SN(zmq_context, arg_parser, args=required_type_arg)
assert ctx
assert ctx.get_socket(("res", "PUB"))
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