Test the signature producing strategy.
"""

# isort: STDLIB
import unittest
from os import environ, sys

# isort: THIRDPARTY
from hypothesis import HealthCheck, errors, given, settings, strategies

# isort: LOCAL
from hs_dbus_signature import dbus_signatures
from hs_dbus_signature._signature import _CODES

settings.register_profile("tracing", deadline=None)
if sys.gettrace() is not None or environ.get("TRAVIS") is not None:
    settings.load_profile("tracing")


@strategies.composite
def dbus_signature_strategy(draw):
    """
    Generates any valid dbus signature strategy.
    """
    max_codes = draw(strategies.integers(min_value=1, max_value=5))
    min_complete_types = draw(strategies.integers(min_value=0, max_value=5))
    max_complete_types = draw(
        strategies.one_of(
            strategies.integers(min_value=min_complete_types, max_value=5),
            strategies.none(),
        )
예제 #2
0
# isort: THIRDPARTY
import dbus
from hypothesis import HealthCheck, example, given, settings, strategies

# isort: FIRSTPARTY
from dbus_signature_pyparsing import Parser
from hs_dbus_signature import dbus_signatures

# isort: LOCAL
from into_dbus_python import signature, xformer, xformers
from into_dbus_python._errors import IntoDPUnexpectedValueError

settings.register_profile(
    "tracing", deadline=None, suppress_health_check=[HealthCheck.too_slow]
)
if sys.gettrace() is not None:
    settings.load_profile("tracing")

# Omits h, unix fd, because it is unclear what are valid fds for dbus
SIGNATURE_STRATEGY = dbus_signatures(max_codes=20, blacklist="h")

OBJECT_PATH_STRATEGY = strategies.builds(
    "/".__add__,
    strategies.builds(
        "/".join,
        strategies.lists(
            strategies.text(
                alphabet=list(
                    string.digits
                    + string.ascii_uppercase
                    + string.ascii_lowercase