aea.test_
tools.test_
cases
This module contains test case classes based on pytest for AEA end-to-end testing.
BaseAEATestCase Objects
Base class for AEA test cases.
set_
agent_
context
Set the current agent context.
unset_
agent_
context
Unset the current agent context.
set_
config
| @classmethod
| set_config(cls, dotted_path: str, value: Any, type_: Optional[str] = None) -> Result
Set a config.
Run from agent's directory.
Arguments:
dotted_path
: str dotted path to config param.value
: a new value to set.type_
: the type
Returns:
Result
nested_
set_
config
Force set config.
disable_
aea_
logging
Disable AEA logging of specific agent.
Run from agent's directory.
run_
cli_
command
Run AEA CLI command.
Arguments:
args
: CLI argscwd
: the working directory from where to run the command.kwargs
: other keyword arguments to click.CliRunner.invoke.
Raises:
AEATestingException
: if command fails.
Returns:
Result
start_
subprocess
Run python with args as subprocess.
Arguments:
args
: CLI argscwd
: the current working directory
Returns:
subprocess object.
start_
thread
Start python Thread.
Arguments:
target
: target method.kwargs
: thread keyword arguments
Returns:
thread
create_
agents
| @classmethod
| create_agents(cls, *agents_names: str, *, is_local: bool = True, is_empty: bool = False) -> None
Create agents in current working directory.
Arguments:
agents_names
: str agent names.is_local
: a flag for local folder add True by default.is_empty
: optional boolean flag for skip adding default dependencies.
fetch_
agent
Create agents in current working directory.
Arguments:
public_id
: str public idagent_name
: str agent name.is_local
: a flag for local folder add True by default.
difference_
to_
fetched_
agent
Compare agent against the one fetched from public id.
Arguments:
public_id
: str public idagent_name
: str agent name.
Returns:
list of files differing in the projects
delete_
agents
Delete agents in current working directory.
Arguments:
agents_names
: str agent names.
run_
agent
Run agent as subprocess.
Run from agent's directory.
Arguments:
args
: CLI args
Returns:
subprocess object.
run_
interaction
Run interaction as subprocess.
Run from agent's directory.
Returns:
subprocess object.
terminate_
agents
| @classmethod
| terminate_agents(cls, *subprocesses: subprocess.Popen, *, timeout: int = 20) -> None
Terminate agent subprocesses.
Run from agent's directory.
Arguments:
subprocesses
: the subprocesses running the agentstimeout
: the timeout for interruption
is_
successfully_
terminated
Check if all subprocesses terminated successfully.
initialize_
aea
Initialize AEA locally with author name.
add_
item
Add an item to the agent.
Run from agent's directory.
Arguments:
item_type
: str item type.public_id
: public id of the item.local
: a flag for local folder add True by default.
Returns:
Result
remove_
item
Remove an item from the agent.
Run from agent's directory.
Arguments:
item_type
: str item type.public_id
: public id of the item.
Returns:
Result
scaffold_
item
| @classmethod
| scaffold_item(cls, item_type: str, name: str, skip_consistency_check: bool = False) -> Result
Scaffold an item for the agent.
Run from agent's directory.
Arguments:
item_type
: str item type.name
: name of the item.skip_consistency_check
: if True, skip consistency check.
Returns:
Result
fingerprint_
item
Fingerprint an item for the agent.
Run from agent's directory.
Arguments:
item_type
: str item type.public_id
: public id of the item.
Returns:
Result
eject_
item
Eject an item in the agent in quiet mode (i.e. no interaction).
Run from agent's directory.
Arguments:
item_type
: str item type.public_id
: public id of the item.
Returns:
None
run_
install
Execute AEA CLI install command.
Run from agent's directory.
Returns:
Result
generate_
private_
key
| @classmethod
| generate_private_key(cls, ledger_api_id: str = DEFAULT_LEDGER, private_key_file: Optional[str] = None, password: Optional[str] = None) -> Result
Generate AEA private key with CLI command.
Run from agent's directory.
Arguments:
ledger_api_id
: ledger API ID.private_key_file
: the private key file.password
: the password.
Returns:
Result
add_
private_
key
| @classmethod
| add_private_key(cls, ledger_api_id: str = DEFAULT_LEDGER, private_key_filepath: str = DEFAULT_PRIVATE_KEY_FILE, connection: bool = False, password: Optional[str] = None) -> Result
Add private key with CLI command.
Run from agent's directory.
Arguments:
ledger_api_id
: ledger API ID.private_key_filepath
: private key filepath.connection
: whether or not the private key filepath is for a connection.password
: the password to encrypt private keys.
Returns:
Result
remove_
private_
key
| @classmethod
| remove_private_key(cls, ledger_api_id: str = DEFAULT_LEDGER, connection: bool = False) -> Result
Remove private key with CLI command.
Run from agent's directory.
Arguments:
ledger_api_id
: ledger API ID.connection
: whether or not the private key filepath is for a connection.
Returns:
Result
replace_
private_
key_
in_
file
| @classmethod
| replace_private_key_in_file(cls, private_key: str, private_key_filepath: str = DEFAULT_PRIVATE_KEY_FILE) -> None
Replace the private key in the provided file with the provided key.
Arguments:
private_key
: the private keyprivate_key_filepath
: the filepath to the private key file :raises: exception if file does not exist
generate_
wealth
| @classmethod
| generate_wealth(cls, ledger_api_id: str = DEFAULT_LEDGER, password: Optional[str] = None) -> Result
Generate wealth with CLI command.
Run from agent's directory.
Arguments:
ledger_api_id
: ledger API ID.password
: the password.
Returns:
Result
get_
wealth
| @classmethod
| get_wealth(cls, ledger_api_id: str = DEFAULT_LEDGER, password: Optional[str] = None) -> str
Get wealth with CLI command.
Run from agent's directory.
Arguments:
ledger_api_id
: ledger API ID.password
: the password to encrypt/decrypt private keys.
Returns:
command line output
get_
address
| @classmethod
| get_address(cls, ledger_api_id: str = DEFAULT_LEDGER, password: Optional[str] = None) -> str
Get address with CLI command.
Run from agent's directory.
Arguments:
ledger_api_id
: ledger API ID.password
: the password to encrypt/decrypt private keys.
Returns:
command line output
replace_
file_
content
Replace the content of the source file to the destination file.
Arguments:
src
: the source file.dest
: the destination file.
change_
directory
Change current working directory.
Arguments:
path
: path to the new working directory.
send_
envelope_
to_
agent
Send an envelope to an agent, using the stub connection.
read_
envelope_
from_
agent
Read an envelope from an agent, using the stub connection.
missing_
from_
output
| @classmethod
| missing_from_output(cls, process: subprocess.Popen, strings: Sequence[str], timeout: int = DEFAULT_PROCESS_TIMEOUT, period: int = 1, is_terminating: bool = True) -> List[str]
Check if strings are present in process output.
Read process stdout in thread and terminate when all strings are present or timeout expired.
Arguments:
process
: agent subprocess.strings
: tuple of strings expected to appear in output.timeout
: int amount of seconds before stopping check.period
: int period of checking.is_terminating
: whether or not the agents are terminated
Returns:
list of missed strings.
is_
running
| @classmethod
| is_running(cls, process: subprocess.Popen, timeout: int = DEFAULT_LAUNCH_TIMEOUT) -> bool
Check if the AEA is launched and running (ready to process messages).
Arguments:
process
: agent subprocess.timeout
: the timeout to wait for launch to complete
Returns:
bool indicating status
invoke
Call the cli command.
load_
agent_
config
Load agent configuration.
setup_
class
Set up the test class.
teardown_
class
Teardown the test.
AEATestCaseEmpty Objects
Test case for a default AEA project.
This test case will create a default AEA project.
setup_
class
Set up the test class.
teardown_
class
Teardown the test class.
AEATestCaseEmptyFlaky Objects
Test case for a default AEA project.
This test case will create a default AEA project.
Use for flaky tests with the flaky decorator.
setup_
class
Set up the test class.
teardown_
class
Teardown the test class.
AEATestCaseMany Objects
Test case for many AEA projects.
setup_
class
Set up the test class.
teardown_
class
Teardown the test class.
AEATestCaseManyFlaky Objects
Test case for many AEA projects which are flaky.
Use for flaky tests with the flaky decorator.
setup_
class
Set up the test class.
teardown_
class
Teardown the test class.
AEATestCase Objects
Test case from an existing AEA project.
Subclass this class and set path_to_aea
properly. By default,
it is assumed the project is inside the current working directory.
setup_
class
Set up the test class.
teardown_
class
Teardown the test class.