tests.support

Support for CoAPy unit testing.

copyright:Copyright 2013, Peter A. Bigot
license:Apache-2.0
class tests.support.FIFOEndpoint(sockaddr=None, family=0, security_mode=None, host=None, port=5683)[source]

Bases: coapy.endpoint.LocalEndpoint

A specialized endpoint for unit testing.

Each instance of this class is assigned a unique name. The underlying coapy.endpoint.LocalEndpoint._rawsendto() and coapy.endpoint.LocalEndpoint._rawrecvfrom() operations are replaced to directly deliver to another instance of this class.

_rawrecvfrom(bufsize)[source]

Return the tuple (data, destination_endpoint) at the head of fifo. If the fifo is empty, raises socket.error.

Overrides coapy.endpoint.LocalEndpoint.rawrecvfrom().

_rawsendto(data, destination_endpoint)[source]

Place the tuple (data, self) on the fifo of destination_endpoint, which must also be a FIFOEndpoint.

Overrides coapy.endpoint.LocalEndpoint.rawsendto().

fifo[source]

Access to the FIFO holding undelivered messages to this endpoint. Elements on the FIFO are tuples (data, source_endpoint) where data is a byte string and source_endpoint is the endpoint from which data was received.

The contents of the fifo may be inspected and manipulated to test endpoint network delivery without involving real sockets.

class tests.support.DeterministicBEBO_mixin[source]

Bases: object

Extension that replaces coapy.transmissionParameters with an instance of coapy.message.TransmissionParameters that sets ACK_RANDOM_FACTOR to 1.0 to eliminate non-determinism in delays.

This class should be mixed-in as a base class along with unittest.TestCase for tests that need deterministic retransmission behavior.

setUp()[source]

Cooperative super-calling support to install deterministic transmission parameters.

tearDown()[source]

Cooperative super-calling support to return to default transmission parameters.

class tests.support.LogHandler_mixin[source]

Bases: object

Extension that registers a logging.handlers.BufferingHandler for loggers used in CoAPy modules to capture the log messages for diagnostic verification.

This implementation currently assumes that only the root logger has set the log message level. For the duration of the test, this level is reset to 1 (enabling capture of records at all levels).

Note

Unit tests that make use of this feature should be sure to invoke self.log_handler.flush() prior to exiting. Any unflushed messages left in the buffering handler will be emitted to the console when the test cleanup is performed, so that unexpected log messages do not slip by unnoticed.

LOG_CAPACITY = 128

The number of records that the associated log_handler should be able to retain.

log_handler[source]

Read-only reference to the logging.handlers.BufferingHandler that is hooked into the logging infrastructure while the unit test is running. The test case may access the log handler’s buffer attribute to access the generated log records.

setUp()[source]

Cooperative super-calling support to install managed clock.

tearDown()[source]

Cooperative super-calling support to remove log_handler.

class tests.support.ManagedClock_mixin[source]

Bases: object

Extension that replaces coapy.clock with an instance of coapy.ManagedClock to eliminate non-determinism in clock queries.

This class should be mixed-in as a base class along with unittest.TestCase for tests that need to control the CoAPy clock.

setUp()[source]

Cooperative super-calling support to install managed clock.

tearDown()[source]

Cooperative super-calling support to return to default clock.

Previous topic

coapy.httputil

This Page