22import warnings
33from unittest .mock import (
44 AsyncMock ,
5+ MagicMock ,
56 call ,
67 patch ,
78)
@@ -106,37 +107,67 @@ async def test_loop(self):
106107 self .assertEqual (call (), mock_loop .call_args )
107108
108109 async def test_setup (self ):
109- mock = AsyncMock ()
110- self .launcher .injector .wire_and_setup_injections = mock
111- await self .launcher .setup ()
110+ wire_mock = MagicMock ()
111+ setup_mock = AsyncMock ()
112+ mock_entrypoint_aenter = AsyncMock ()
113+
114+ self .launcher .injector .wire_injections = wire_mock
115+ self .launcher .injector .setup_injections = setup_mock
116+
117+ with patch ("minos.common.launchers._create_loop" ) as mock_loop :
118+ loop = FakeLoop ()
119+ mock_loop .return_value = loop
120+ with patch ("minos.common.launchers._create_entrypoint" ) as mock_entrypoint :
121+ entrypoint = FakeEntrypoint ()
122+ mock_entrypoint .return_value = entrypoint
123+
124+ entrypoint .__aenter__ = mock_entrypoint_aenter
125+
126+ await self .launcher .setup ()
112127
113- self .assertEqual (1 , mock .call_count )
128+ self .assertEqual (1 , wire_mock .call_count )
114129 import tests
115130 from minos import (
116131 common ,
117132 )
118133
119- self .assertEqual (0 , len (mock .call_args .args ))
120- self .assertEqual (2 , len (mock .call_args .kwargs ))
121- observed = mock .call_args .kwargs ["modules" ]
134+ self .assertEqual (0 , len (wire_mock .call_args .args ))
135+ self .assertEqual (2 , len (wire_mock .call_args .kwargs ))
136+ observed = wire_mock .call_args .kwargs ["modules" ]
122137
123138 self .assertIn (tests , observed )
124139 self .assertIn (common , observed )
125140
126- self .assertEqual (["tests" ], mock .call_args .kwargs ["packages" ])
141+ self .assertEqual (["tests" ], wire_mock .call_args .kwargs ["packages" ])
127142
128- await self .launcher .destroy ()
143+ self .assertEqual (1 , setup_mock .call_count )
144+ self .assertEqual (1 , mock_entrypoint_aenter .call_count )
129145
130146 async def test_destroy (self ):
131- self .launcher .injector . wire_and_setup_injections = AsyncMock ()
147+ self .launcher ._setup = AsyncMock ()
132148 await self .launcher .setup ()
133149
134- mock = AsyncMock ()
135- self .launcher .injector .unwire_and_destroy_injections = mock
136- await self .launcher .destroy ()
150+ destroy_mock = AsyncMock ()
151+ unwire_mock = MagicMock ()
152+ mock_entrypoint_aexit = AsyncMock ()
153+
154+ self .launcher .injector .destroy_injections = destroy_mock
155+ self .launcher .injector .unwire_injections = unwire_mock
156+
157+ with patch ("minos.common.launchers._create_loop" ) as mock_loop :
158+ loop = FakeLoop ()
159+ mock_loop .return_value = loop
160+ with patch ("minos.common.launchers._create_entrypoint" ) as mock_entrypoint :
161+ entrypoint = FakeEntrypoint ()
162+ mock_entrypoint .return_value = entrypoint
163+
164+ entrypoint .__aexit__ = mock_entrypoint_aexit
165+
166+ await self .launcher .destroy ()
137167
138- self .assertEqual (1 , mock .call_count )
139- self .assertEqual (call (), mock .call_args )
168+ self .assertEqual (1 , unwire_mock .call_count )
169+ self .assertEqual (1 , destroy_mock .call_count )
170+ self .assertEqual (1 , mock_entrypoint_aexit .call_count )
140171
141172 def test_launch (self ):
142173 mock_setup = AsyncMock ()
@@ -157,8 +188,8 @@ def test_launch(self):
157188
158189 self .launcher .launch ()
159190
160- self .assertEqual (1 , mock_entrypoint .call_count )
161- self .assertEqual (1 , mock_loop .call_count )
191+ self .assertEqual (1 , mock_setup .call_count )
192+ self .assertEqual (1 , mock_destroy .call_count )
162193
163194
164195class TestEntryPointLauncherLoop (unittest .TestCase ):
0 commit comments