Skip to main content
Help the Python Software Foundation raise $60,000 USD by December 31st!  Building the PSF Q4 Fundraiser

dbus signature hypothesis strategy generator

Project description

This package contains a Hypothesis strategy for generating DBus signatures. An informal specification of DBus signatures is available at: https://dbus.freedesktop.org/doc/dbus-specification.html.

The strategy is intended to be both sound and complete. That is, it should never generate an invalid DBus signature and it should be capable, modulo size constraints, of generating any valid DBus signature.

Usage

Import the function and obtain a strategy with the default parameters.

>>> from hs_dbus_signature import dbus_signatures
>>> strategy = dbus_signatures()

Obtain a few examples of valid signatures, e.g.,

>>> strategy.example()
''
>>> strategy.example()
'a{ng}'
>>> strategy.example()
'a{xas}a{gah}a{nau}'

Make use of the strategy in your tests, e.g.

from hypothesis import given

@given(dbus_signatures())
def test(signature):
    ...

Use the parameters to omit dicts

>>> strategy = dbus_signatures(exclude_dicts=True)
>>> strategy.example()
'(gnggg)(n)(gn)(nnnnn)(nn)'

or to ensure that no example signature is the empty string

>>> strategy = dbus_signatures(min_complete_types=1)
>>> strategy.example()
'a{sv}'

The strategy will raise an InvalidArgument exception immediately if it is given arguments which allow no examples to be drawn.

>>> strategy = dbus_signatures(blacklist=string.ascii_lowercase)
Traceback (most recent call last):
...

Remarks

Documentation for the Hypothesis testing library can be found at http://hypothesis.readthedocs.io.

This strategy makes use of the Hypothesis higher-order strategy, recursive(), which is discussed here: http://hypothesis.works/articles/recursive-data/.

It is only supported for Python 3 as it uses Python 3 only syntax.

Downstream packagers, if incorporating testing into their packaging, are encouraged to use only the tests in the test_deterministic.py module, to avoid testing failures that may arise due to the non-deterministic behavior of Hypothesis tests.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for hs-dbus-signature, version 0.7
Filename, size File type Python version Upload date Hashes
Filename, size hs_dbus_signature-0.7-py3-none-any.whl (5.0 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size hs-dbus-signature-0.7.tar.gz (6.3 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page