Commit 4dba6b7b authored by Robin Obůrka's avatar Robin Obůrka

tests: Move fixtures to conftest.py

It is not necessary to keep them separated.
parent 2bdde423
from .fixtures import *
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():
return "--resource res,connect,PUSH,127.0.0.1,8800".split(" ")
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():
return "--resource res,connect,PUSH,127.0.0.1,8800".split(" ")
import sys
sys.path.append("..")
from .fixtures import *
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()
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()
from .fixtures import *
import pytest
import msgpack
@pytest.fixture
def good_type():
return "sentinel/tests/good_string"
@pytest.fixture(params=[
"sentinel",
"sentinel/tests",
"sentinel/tests/goodstring",
"sentinel/tests/good/string",
"sentinel/tests/good_string",
"sentinel/tests/good_string_123",
"sentinel/tests/box1",
"sentinel/tests/box/1",
"s/t/b",
"a/b/c/s/d/g",
])
def good_types(request):
return request.param
@pytest.fixture(params=[
"/sentinel/tests/broken",
"sentinel/tests/broken/",
"/sentinel/tests/broken/",
"sentinel/tests/bro ken",
"sentinel/tests/bro-ken",
"sentinel/tests/Broken",
"sentinel/tests/břoken",
"sentinel/tests/bro?ken",
"sentinel/tests/bro@ken",
"sentinel//broken",
"sentinel//broken",
"s//b",
"sentinel/",
"/sentinel",
""
])
def bad_types(request):
return request.param
@pytest.fixture
def good_payload():
return {
"key1": "val1",
"key2": 2,
"key3": True,
"key4": "ěščřžýáíé",
}
@pytest.fixture
def good_msg(good_type, good_payload):
t = bytes(good_type, encoding="UTF-8")
p = msgpack.packb(good_payload, encoding="UTF-8")
return (t, p)
@pytest.fixture
def good_long(good_type, good_payload):
t = bytes(good_type, encoding="UTF-8")
p = msgpack.packb(good_payload, encoding="UTF-8")
x = msgpack.packb(good_payload, encoding="UTF-8")
return (t, p, x)
@pytest.fixture(params=[1, 5, 7, 9, 12, 15, 18, 20])
def broken_msg(request, good_msg):
# Parameters are tested by eye, but it generates several different
# exception from msgpack. So, the test should be sufficient
pos = request.param
# Swap "random" bytes
ba = bytearray(good_msg[1])
ba[0], ba[pos] = ba[pos], ba[0]
msg = bytes(ba)
return (good_msg[0], msg)
@pytest.fixture
def good_type_msg(good_types, good_msg):
t = bytes(good_types, encoding="UTF-8")
return (t, good_msg[1])
@pytest.fixture
def broken_type_msg(bad_types, good_msg):
t = bytes(bad_types, encoding="UTF-8")
return (t, good_msg[1])
import pytest
import msgpack
@pytest.fixture
def good_type():
return "sentinel/tests/good_string"
@pytest.fixture(params=[
"sentinel",
"sentinel/tests",
"sentinel/tests/goodstring",
"sentinel/tests/good/string",
"sentinel/tests/good_string",
"sentinel/tests/good_string_123",
"sentinel/tests/box1",
"sentinel/tests/box/1",
"s/t/b",
"a/b/c/s/d/g",
])
def good_types(request):
return request.param
@pytest.fixture(params=[
"/sentinel/tests/broken",
"sentinel/tests/broken/",
"/sentinel/tests/broken/",
"sentinel/tests/bro ken",
"sentinel/tests/bro-ken",
"sentinel/tests/Broken",
"sentinel/tests/břoken",
"sentinel/tests/bro?ken",
"sentinel/tests/bro@ken",
"sentinel//broken",
"sentinel//broken",
"s//b",
"sentinel/",
"/sentinel",
""
])
def bad_types(request):
return request.param
@pytest.fixture
def good_payload():
return {
"key1": "val1",
"key2": 2,
"key3": True,
"key4": "ěščřžýáíé",
}
@pytest.fixture
def good_msg(good_type, good_payload):
t = bytes(good_type, encoding="UTF-8")
p = msgpack.packb(good_payload, encoding="UTF-8")
return (t, p)
@pytest.fixture
def good_long(good_type, good_payload):
t = bytes(good_type, encoding="UTF-8")
p = msgpack.packb(good_payload, encoding="UTF-8")
x = msgpack.packb(good_payload, encoding="UTF-8")
return (t, p, x)
@pytest.fixture(params=[1, 5, 7, 9, 12, 15, 18, 20])
def broken_msg(request, good_msg):
# Parameters are tested by eye, but it generates several different
# exception from msgpack. So, the test should be sufficient
pos = request.param
# Swap "random" bytes
ba = bytearray(good_msg[1])
ba[0], ba[pos] = ba[pos], ba[0]
msg = bytes(ba)
return (good_msg[0], msg)
@pytest.fixture
def good_type_msg(good_types, good_msg):
t = bytes(good_types, encoding="UTF-8")
return (t, good_msg[1])
@pytest.fixture
def broken_type_msg(bad_types, good_msg):
t = bytes(bad_types, encoding="UTF-8")
return (t, good_msg[1])
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 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()
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