-
Notifications
You must be signed in to change notification settings - Fork 8
/
test_addremove_metrological_agents.py
83 lines (72 loc) · 3.18 KB
/
test_addremove_metrological_agents.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import pytest
from agentMET4FOF.agents.metrological_base_agents import (
MetrologicalAgent,
MetrologicalMonitorAgent,
)
from tests.conftest import test_timeout
agent_type_permutations = [
[MetrologicalAgent],
[MetrologicalMonitorAgent],
[MetrologicalAgent, MetrologicalAgent],
[MetrologicalAgent, MetrologicalMonitorAgent],
[MetrologicalMonitorAgent, MetrologicalAgent],
[MetrologicalMonitorAgent, MetrologicalMonitorAgent],
[
MetrologicalAgent,
MetrologicalAgent,
MetrologicalMonitorAgent,
MetrologicalMonitorAgent,
],
]
@pytest.mark.timeout(test_timeout)
@pytest.mark.parametrize("agent_types", agent_type_permutations)
def test_addremove_metrological_agents(agent_network, agent_types):
# Check for all combinations in agent_type_permutations, if agents can be added
# to an agent network, which as a result contains those agents.
n_agents = len(agent_types)
# Create the agents as desired.
for agent_type in agent_types:
agent_network.add_agent(agentType=agent_type)
# Check if for each element in agent_types there is an agent in the network.
assert len(agent_network.agents()) == n_agents
for agent in agent_network.agents():
# Check if removal does not raise errors.
assert agent_network.remove_agent(agent) is None
n_agents -= 1
# Check if agent network really contains one agent less after a short latency
# period. This reduces test runtime in case of passed tests but
# results in quite cryptic error messages in case it fails due to the
# timeout causing the actual fail. So, if this line fails, regardless of
# the error message, it means, the agents have not been properly removed.
is_not_equal = True
while is_not_equal:
try:
assert len(agent_network.agents()) == n_agents
is_not_equal = False
except AssertionError:
pass
@pytest.mark.parametrize("agent_types", agent_type_permutations)
def test_bind_agents(agent_network, agent_types):
# Check for all combinations in agent_type_permutations, if agents can be bound.
# Create the agents according to agent_types.
agents = [
agent_network.add_agent(agentType=agent_type) for agent_type in agent_types
]
# Interconnect all agents unidirectional.
for index, agent in enumerate(agents):
subsequent_agents = agents[index:]
for subsequent_agent in subsequent_agents:
assert agent_network.bind_agents(agent, subsequent_agent) == 0
@pytest.mark.parametrize("agent_types", agent_type_permutations)
def test_bind_agents(agent_network, agent_types):
# Check for all combinations in agent_type_permutations, if agents can be removed
# again.
# Create the agents according to agent_types.
agents = [
agent_network.add_agent(agentType=agent_type) for agent_type in agent_types
]
# Interconnect all agents unidirectional.
for index, agent in enumerate(agents):
subsequent_agents = agents[index:]
for subsequent_agent in subsequent_agents:
assert agent_network.bind_agents(agent, subsequent_agent) == 0