# Path: clearly/client/display_modes.py
# def find_mode(constant: Union[None, int, ModeTask, ModeWorker]) \
#         -> Union[None, ModeTask, ModeWorker]:
#     if isinstance(constant, (type(None), ModeTask, ModeWorker)):
#         return constant
#     if isinstance(constant, int) and constant in _VALUES:
#         return _VALUES[constant]
#     raise UserWarning('Invalid mode constant.')
# 
# Path: clearly/client/display_modes.py
# class ModeTask(EnumSpecDescription):
#     TASK = 'name, uuid, routing key, state and retries', False, False, False
# 
#     RESULT = 'TASK + results', False, True, False
#     ERROR = 'TASK + exceptions', False, False, True
#     OUTCOME = 'RESULT + ERROR', False, True, True
# 
#     SUCCESS = 'RESULT + args/kwargs', None, True, False
#     FAILURE = 'ERROR + args/kwargs', None, False, True
#     DONE = 'SUCCESS + FAILURE', None, True, True
# 
#     SENT = 'TASK + args/kwargs being sent', True, False, False
#     FLOWING = 'SENT + SUCCESS', True, True, False
#     BREAKING = 'SENT + FAILURE', True, False, True
#     ALL = 'SENT + DONE', True, True, True
# 
# class ModeWorker(EnumSpecDescription):
#     WORKER = 'name, status and pid', False
#     STATS = 'WORKER + version, load and heartbeats', True


import pytest
from clearly.client.display_modes import find_mode
from clearly.client import ModeTask, ModeWorker



@pytest.mark.parametrize('constant', [
    '', 'ALL', 1.1, object(), -1, 1 + len(ModeTask.__members__) + len(ModeWorker.__members__)
])
def test_find_mode_error(constant):
    with pytest.raises(UserWarning):
        # noinspection PyTypeChecker
        assert find_mode(constant)


@pytest.mark.parametrize('constant, expected', [
    (None, None),
    *((c, c) for c in ModeTask.__members__.values()),
    *((c, c) for c in ModeWorker.__members__.values()),
    *((c.value, c) for c in ModeTask.__members__.values()),
    *((c.value, c) for c in ModeWorker.__members__.values()),
])
def test_find_mode(constant, expected):

# Path: clearly/client/display_modes.py
# def find_mode(constant: Union[None, int, ModeTask, ModeWorker]) \
#         -> Union[None, ModeTask, ModeWorker]:
#     if isinstance(constant, (type(None), ModeTask, ModeWorker)):
#         return constant
#     if isinstance(constant, int) and constant in _VALUES:
#         return _VALUES[constant]
#     raise UserWarning('Invalid mode constant.')
# 
# Path: clearly/client/display_modes.py
# class ModeTask(EnumSpecDescription):
#     TASK = 'name, uuid, routing key, state and retries', False, False, False
# 
#     RESULT = 'TASK + results', False, True, False
#     ERROR = 'TASK + exceptions', False, False, True
#     OUTCOME = 'RESULT + ERROR', False, True, True
# 
#     SUCCESS = 'RESULT + args/kwargs', None, True, False
#     FAILURE = 'ERROR + args/kwargs', None, False, True
#     DONE = 'SUCCESS + FAILURE', None, True, True
# 
#     SENT = 'TASK + args/kwargs being sent', True, False, False
#     FLOWING = 'SENT + SUCCESS', True, True, False
#     BREAKING = 'SENT + FAILURE', True, False, True
#     ALL = 'SENT + DONE', True, True, True
# 
# class ModeWorker(EnumSpecDescription):
#     WORKER = 'name, status and pid', False
#     STATS = 'WORKER + version, load and heartbeats', True


# Path: tests/unit/client/test_display_modes.py
import pytest
from clearly.client.display_modes import find_mode
from clearly.client import ModeTask, ModeWorker




@pytest.mark.parametrize('constant', [
    '', 'ALL', 1.1, object(), -1, 1 + len(ModeTask.__members__) + len(ModeWorker.__members__)
])
def test_find_mode_error(constant):
    with pytest.raises(UserWarning):
        # noinspection PyTypeChecker
        assert find_mode(constant)


@pytest.mark.parametrize('constant, expected', [
    (None, None),
    *((c, c) for c in ModeTask.__members__.values()),
    *((c, c) for c in ModeWorker.__members__.values()),
    *((c.value, c) for c in ModeTask.__members__.values()),
    *((c.value, c) for c in ModeWorker.__members__.values()),
])
def test_find_mode(constant, expected):

    assert find_mode(constant) == expected