11
2- from tests import AsyncMock
3-
42import pytest
3+ from unittest .mock import AsyncMock
54
65from app .planners .atomic import LogicalPlanner
76
@@ -15,7 +14,10 @@ def __init__(self):
1514 self .adversary = AdversaryStub ()
1615 self .agents = ['agent_1' ]
1716 self .wait_for_links_completion = AsyncMock ()
18- self .apply = AsyncMock ()
17+ self .apply = AsyncMock (side_effect = self ._apply_side_effect )
18+
19+ def _apply_side_effect (self , value ):
20+ return value .id
1921
2022
2123class PlanningSvcStub ():
@@ -34,9 +36,10 @@ def __init__(self, ability_id):
3436class LinkStub ():
3537 def __init__ (self , ability_id ):
3638 self .ability = AbilityStub (ability_id )
39+ self .id = 'link_' + ability_id
3740
3841 def __eq__ (self , other ):
39- return self .ability .ability_id == other .ability .ability_id
42+ return self .ability .ability_id == other .ability .ability_id and self . id == other . id
4043
4144
4245@pytest .fixture
@@ -64,8 +67,8 @@ def test_atomic_with_links_in_order(self, event_loop, atomic_planner):
6467
6568 assert atomic_planner .operation .apply .call_count == 1
6669 assert atomic_planner .operation .wait_for_links_completion .call_count == 1
67- atomic_planner .operation .apply .assert_called_with (LinkStub ('ability_b' ))
68- atomic_planner .operation .wait_for_links_completion .assert_called_with ([ LinkStub ( 'ability_b' ) ])
70+ atomic_planner .operation .apply .assert_awaited_with (LinkStub ('ability_b' ))
71+ atomic_planner .operation .wait_for_links_completion .assert_awaited_with ([ 'link_ability_b' ])
6972
7073 def test_atomic_with_links_out_of_order (self , event_loop , atomic_planner ):
7174
@@ -80,8 +83,8 @@ def test_atomic_with_links_out_of_order(self, event_loop, atomic_planner):
8083
8184 assert atomic_planner .operation .apply .call_count == 1
8285 assert atomic_planner .operation .wait_for_links_completion .call_count == 1
83- atomic_planner .operation .apply .assert_called_with (LinkStub ('ability_b' ))
84- atomic_planner .operation .wait_for_links_completion .assert_called_with ([ LinkStub ( 'ability_b' ) ])
86+ atomic_planner .operation .apply .assert_awaited_with (LinkStub ('ability_b' ))
87+ atomic_planner .operation .wait_for_links_completion .assert_awaited_with ([ 'link_ability_b' ])
8588
8689 def test_atomic_no_links (self , event_loop , atomic_planner ):
8790
0 commit comments