Python Modules¶
This section details the public API for using the Pact testing package.
Public API Documentation¶
- class ska_pact_tango.pact.Pact(providers, consumer_name, consumer_class=None, pact_dir=None, pact_file_name='')[source]¶
Bases:
object
Represents a contract between a consumer and provider.
Provides Python context handlers to configure the Pact mock service to perform tests with a Tango device (consumer).
Also generates and writes a pact file.
- classmethod from_file(pact_file_path: str)[source]¶
Parses a pact file and returns an instance of Pact
- class ska_pact_tango.consumer.Consumer(name, consumer_cls=None)[source]¶
Bases:
object
A Pact consumer.
Use this class to describe the consumer executing commands on the provider and then use has_pact_with to create a contract with a specific provider.
- class ska_pact_tango.provider.Interaction[source]¶
Bases:
object
Define an interaction between a consumer and provider
- and_given(provider_state_description: str, *args)[source]¶
Add a description of what state the provider should be in
- execute_request(request: dict, device_proxy: <Mock name='mock.DeviceProxy' id='139680465216960'>)[source]¶
Execute a request against a Tango device
- Parameters:
request (dict) – The request to execute
device_proxy (tango.DeviceProxy) – The proxy to the provider device
- Returns:
The result of the request
- Return type:
Any
- classmethod from_dict(interaction_dict: dict)[source]¶
Returns an instance of Interaction
- Parameters:
interaction_dict (dict) – Interaction in a dictionary format
- Returns:
instance of Interaction
- Return type:
- given(provider_state_description: str, *args)[source]¶
Description of what state the provider should be in
- setup_provider(device_proxy: <Mock name='mock.DeviceProxy' id='139680465216960'>)[source]¶
Run through the provider states as defined in the Pact and execute them on the provider
- Parameters:
device_proxy (tango.DeviceProxy) – The proxy to the provider
- to_dict() dict [source]¶
Return a dictionary of the Interaction
- Returns:
A dictionary of the Interaction
- Return type:
- upon_receiving(scenario: str = '')[source]¶
Describe the interaction
- Parameters:
scenario (str, optional) – Description of the interaction, defaults to “”
- verify_interaction(device_proxy: <Mock name='mock.DeviceProxy' id='139680465216960'>)[source]¶
Verify the request against the Provider
- Parameters:
device_proxy (tango.DeviceProxy) – proxy to the provider device
- Raises:
AssertionError – If the request and response from the proxy fails
- will_respond_with(response_type, response=None)[source]¶
Define what the provider should return with.
- Parameters:
response – The type of the response from the provider
response – The provider response
- Return type:
- with_request(*args)[source]¶
Define the request from the consumer
Reference examples
- Tango attribute write
- Shortform
- E.g
>>> provider_device.random_float = 5.0
- Use
>>> with_request("attribute", "random_float", 5.0)
- Longform
- E.g
>>> provider_device.write_attribute("random_float", 5.0)
- Use
>>> with_request("method", "write_attribute", "random_float", 5.0) OR >>> with_request("write_attribute", "random_float", 5.0)
- Tango attribute read
- Shortform
- E.g
>>> provider_device.random_float
- Use
>>> with_request("attribute", "random_float")
- Longform
- E.g
>>> provider_device.read_attribute("random_float")
- Use
>>> with_request("read_attribute", "random_float")
- Tango commands
- Shortform
- E.g
>>> provider_device.SomeCommand()
- Use
>>> with_request("command", "SomeCommand")
- E.g
>>> provider_device.SomeCommand(1.0)
- Use
>>> with_request("command", "SomeCommand", 1.0)
- Longform
- E.g
>>> provider_device.command_inout("SomeCommand")
- Use
>>> with_request("method", "command_inout", "SomeCommand") OR >>> with_request("command_inout", "SomeCommand")
- E.g
>>> provider_device.command_inout("SomeCommand", 1.0)
- Use
>>> with_request("method", "command_inout", "SomeCommand", 1.0) OR >>> with_request("command_inout", "SomeCommand", 1.0)
- Parameters:
req_type (string) – read_attribute or command
name (string) – The name of the command or attribute
arg (Any) – Any argument to be used in the command
- Return type:
- class ska_pact_tango.provider.Provider(device_name: str)[source]¶
Bases:
object
A Pact provider.
- add_interaction(interaction: Interaction)[source]¶
Add an Interaction
- Parameters:
interaction (Interaction) – An interaction between the consumer and provider
- Returns:
self
- Return type:
- get_interaction_from_description(description) Optional[Interaction] [source]¶
Returns an interaction that matches the description
- Parameters:
description ([type]) – [description]
- Returns:
[description]
- Return type:
Optional[ska_pact_tango.Interaction]