# Path: osbrain/agent.py
# TOPIC_SEPARATOR = b'\x80'
# 
# Path: osbrain/common.py
# class LogLevel(str):
#     """
#     Identifies the log level: ERROR, WARNING, INFO, DEBUG.
#     """
# 
#     def __new__(cls, value):
#         if value not in ['ERROR', 'WARNING', 'INFO', 'DEBUG']:
#             raise ValueError('Incorrect value "%s"!' % value)
#         return super().__new__(cls, value)
# 
# Path: osbrain/common.py
# def topic_to_bytes(topic: Union[bytes, str]) -> bytes:
#     """
#     Return the passed topic as a :class:`bytes` object.
#     """
#     if isinstance(topic, str):
#         topic = topic.encode()
#     return topic
# 
# Path: osbrain/common.py
# def topics_to_bytes(handlers: Dict[Union[bytes, str], Any], uuid: bytes = b''):
#     """
#     Given some pairs topic/handler, leaves them prepared for making the actual
#     ZeroMQ subscription.
# 
#     Parameters
#     ----------
#     handlers
#         Contains pairs "topic - handler".
#     uuid
#         uuid of the SYNC_PUB/SYNC_SUB channel (if applies). For normal
#         PUB/SUB communication, this should be ``b''``.
# 
#     Returns
#     -------
#     Dict[bytes, Any]
#     """
#     curated_handlers = {}
# 
#     for topic, value in handlers.items():
#         topic = topic_to_bytes(topic)
#         curated_handlers[uuid + topic] = value
# 
#     return curated_handlers
# 
# Path: osbrain/common.py
# def unique_identifier() -> bytes:
#     """
#     Returns
#     -------
#         A unique identifier that is safe to use in PUB-SUB communication
#         patterns (i.e.: does not contain the
#         :py:data:`osbrain.agent.TOPIC_SEPARATOR` character).
#     """
#     return uuid4().hex.encode()


import pytest
from osbrain.agent import TOPIC_SEPARATOR
from osbrain.common import LogLevel
from osbrain.common import topic_to_bytes
from osbrain.common import topics_to_bytes
from osbrain.common import unique_identifier
        assert isinstance(identifier, bytes)
        assert TOPIC_SEPARATOR not in identifier


def test_loglevel():
    """
    Test LogLevel class initialization.
    """
    # Valid initialization
    for level in ['ERROR', 'WARNING', 'INFO', 'DEBUG']:
        LogLevel(level)
    # Invalid initialization
    with pytest.raises(ValueError):
        LogLevel('FOO')


def test_topic_to_bytes():
    """
    Test the topic to bytes function.
    """
    assert topic_to_bytes('foo') == b'foo'
    assert topic_to_bytes(b'bar') == b'bar'


def test_topics_to_bytes_without_uuid():
    """
    Test topics_to_bytes basic usage, without specifying a uuid.
    """
    handlers = {'topic_one': 'handler', b'topic_two': 'handler'}


# Path: osbrain/agent.py
# TOPIC_SEPARATOR = b'\x80'
# 
# Path: osbrain/common.py
# class LogLevel(str):
#     """
#     Identifies the log level: ERROR, WARNING, INFO, DEBUG.
#     """
# 
#     def __new__(cls, value):
#         if value not in ['ERROR', 'WARNING', 'INFO', 'DEBUG']:
#             raise ValueError('Incorrect value "%s"!' % value)
#         return super().__new__(cls, value)
# 
# Path: osbrain/common.py
# def topic_to_bytes(topic: Union[bytes, str]) -> bytes:
#     """
#     Return the passed topic as a :class:`bytes` object.
#     """
#     if isinstance(topic, str):
#         topic = topic.encode()
#     return topic
# 
# Path: osbrain/common.py
# def topics_to_bytes(handlers: Dict[Union[bytes, str], Any], uuid: bytes = b''):
#     """
#     Given some pairs topic/handler, leaves them prepared for making the actual
#     ZeroMQ subscription.
# 
#     Parameters
#     ----------
#     handlers
#         Contains pairs "topic - handler".
#     uuid
#         uuid of the SYNC_PUB/SYNC_SUB channel (if applies). For normal
#         PUB/SUB communication, this should be ``b''``.
# 
#     Returns
#     -------
#     Dict[bytes, Any]
#     """
#     curated_handlers = {}
# 
#     for topic, value in handlers.items():
#         topic = topic_to_bytes(topic)
#         curated_handlers[uuid + topic] = value
# 
#     return curated_handlers
# 
# Path: osbrain/common.py
# def unique_identifier() -> bytes:
#     """
#     Returns
#     -------
#         A unique identifier that is safe to use in PUB-SUB communication
#         patterns (i.e.: does not contain the
#         :py:data:`osbrain.agent.TOPIC_SEPARATOR` character).
#     """
#     return uuid4().hex.encode()


# Path: osbrain/tests/test_common.py
import pytest
from osbrain.agent import TOPIC_SEPARATOR
from osbrain.common import LogLevel
from osbrain.common import topic_to_bytes
from osbrain.common import topics_to_bytes
from osbrain.common import unique_identifier

        assert isinstance(identifier, bytes)
        assert TOPIC_SEPARATOR not in identifier


def test_loglevel():
    """
    Test LogLevel class initialization.
    """
    # Valid initialization
    for level in ['ERROR', 'WARNING', 'INFO', 'DEBUG']:
        LogLevel(level)
    # Invalid initialization
    with pytest.raises(ValueError):
        LogLevel('FOO')


def test_topic_to_bytes():
    """
    Test the topic to bytes function.
    """
    assert topic_to_bytes('foo') == b'foo'
    assert topic_to_bytes(b'bar') == b'bar'


def test_topics_to_bytes_without_uuid():
    """
    Test topics_to_bytes basic usage, without specifying a uuid.
    """
    handlers = {'topic_one': 'handler', b'topic_two': 'handler'}


    curated = topics_to_bytes(handlers)