conftest.py 3.53 KB
Newer Older
1 2
import pytest

3 4
from unittest.mock import patch

5

6 7
def args_from_string(s):
    args = ["prog"]
8
    args.extend([a for a in s.split(" ") if a])
9 10 11 12

    return args


13
@pytest.fixture
14 15 16 17 18
def one_resource_mock():
    with patch("sys.argv", args_from_string("--resource res,connect,PUSH,127.0.0.1,8800")) as m:
        yield m


19 20 21 22 23 24
@pytest.fixture
def verbose_args_mock():
    with patch("sys.argv", args_from_string("--resource res,connect,PUSH,127.0.0.1,8800 -v")) as m:
        yield m


25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
@pytest.fixture
def empty_args_mock():
    with patch("sys.argv", args_from_string("")) as m:
        yield m


@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"
Robin Obůrka's avatar
Robin Obůrka committed
46
                        "     --resource res,connect,PUSH,localhost,8800",
47
                        "--resource res,bind,PULL,localhost,8800"
Robin Obůrka's avatar
Robin Obůrka committed
48
                        "     --resource res,bind,PULL,localhost,8800",
49
                        "--resource res,bind,PULL,localhost,8800"
Robin Obůrka's avatar
Robin Obůrka committed
50
                        "     --resource res,bind,PUSH,localhost,8800",
51 52 53 54 55 56 57 58 59 60

                       ])
def bad_resources_mock(request):
    with patch("sys.argv", args_from_string(request.param)) as m:
        yield m


@pytest.fixture(params=[
                        "--resource res,connect,PUSH,127.0.0.1,8800",
                        "--resource res,connect,PUSH,setinel.turris.cz,8800",
61
                        "--resource res,connect,PUSH,[::1],8800",
62 63 64 65 66 67 68 69 70 71
                       ])
def connect_resources_mock(request):
    with patch("sys.argv", args_from_string(request.param)) as m:
        yield m


@pytest.fixture(params=[
                        "--resource res,bind,PUSH,*,8800",
                        "--resource res,bind,PULL,*,8801",
                        "--resource res,bind,PULL,127.0.0.1,8802",
72 73
                        "--resource res,bind,PULL,::1,8802",
                        "--resource res,bind,PULL,[::1],8802",
74 75 76 77 78 79 80 81
                       ])
def bind_resources_mock(request):
    with patch("sys.argv", args_from_string(request.param)) as m:
        yield m


@pytest.fixture(params=[
                        "--resource res1,connect,PUSH,localhost,8800"
Robin Obůrka's avatar
Robin Obůrka committed
82
                        "     --resource res2,connect,PUSH,localhost,8800",
83
                        "--resource res1,connect,PUSH,localhost,8800"
Robin Obůrka's avatar
Robin Obůrka committed
84 85
                        "     --resource res1,connect,PUSH,localhost,8801"
                        "     --resource res2,connect,PUB,localhost,8802",
86
                        "--resource res1,connect,PUB,localhost,8800"
Robin Obůrka's avatar
Robin Obůrka committed
87 88
                        "     --resource res1,connect,PUB,localhost,8801"
                        "     --resource res2,connect,PUB,localhost,8802",
89 90 91 92
                       ])
def multisock_resources_mock(request):
    with patch("sys.argv", args_from_string(request.param)) as m:
        yield m