Assertions

hospital provides a set of assertions to write healthchecks.

HTTP

Assertions around HTTP resources.

hospital.assertions.http.assert_http_response(url, status_code=200, timeout=1)

Assert that GET url returns status_code within timeout.

>>> from hospital.assertions.http import assert_http_response
>>> assert_http_response('http://hospital.readthedocs.org', 200)

Raises AssertionError in case of failure.

>>> assert_http_response('http://hospital.readthedocs.org', 401)
... # Doctest: +ELLIPSIS
Traceback (most recent call last):
    ...
AssertionError

Use timeout argument as a ceil for tolerable latency (in seconds).

>>> try:
...     assert_http_response('http://hospital.readthedocs.org',
...                          timeout=0.001)
... except AssertionError:
...     pass

Networking

Assertions related to networking.

hospital.assertions.networking.assert_ping(host, timeout=1)

Assert host responds to ping within timeout.

Packaging

Assertions related to Python packaging.

hospital.assertions.packaging.assert_supported_python_version(distribution, version=None)

Assert that distribution claims support for Python version.

distribution
Distribution object, as returned by pkg_resources.get_distribution().
version
Python version, as a string. If omitted or None (the default), the current Python version is retrieved from sys.version_info.