7
7
import pytest
8
8
from threading import Timer
9
9
10
-
11
10
import osbrain
12
11
from osbrain import run_agent
13
12
from osbrain import Agent
@@ -179,20 +178,20 @@ def test_agent_proxy_nameserver_address(nsproxy):
179
178
assert agent .nsaddr () == nsproxy .addr ()
180
179
181
180
182
- def test_agent_proxy_safe_and_unsafe_property (nsproxy ):
181
+ def test_agent_proxy_safe_and_unsafe_property (monkeypatch , nsproxy ):
183
182
"""
184
183
Using the safe/unsafe property from a proxy should allow us to
185
184
override the environment global configuration.
186
185
"""
187
186
run_agent ('foo' )
188
187
# Safe environment
189
- osbrain .config [ 'SAFE' ] = True
188
+ monkeypatch . setitem ( osbrain .config , 'SAFE' , True )
190
189
proxy = Proxy ('foo' )
191
190
assert proxy ._safe
192
191
assert proxy .safe ._safe
193
192
assert not proxy .unsafe ._safe
194
193
# Unsafe environment
195
- osbrain .config [ 'SAFE' ] = False
194
+ monkeypatch . setitem ( osbrain .config , 'SAFE' , False )
196
195
proxy = Proxy ('foo' )
197
196
assert not proxy ._safe
198
197
assert proxy .safe ._safe
@@ -210,33 +209,33 @@ def test_agent_run_agent_safe_and_unsafe(nsproxy):
210
209
assert not unsafe ._safe
211
210
212
211
213
- def test_agent_proxy_safe_and_unsafe_parameter (nsproxy ):
212
+ def test_agent_proxy_safe_and_unsafe_parameter (monkeypatch , nsproxy ):
214
213
"""
215
214
Using the safe/unsafe parameter when initializating a proxy should allow
216
215
us to override the environment global configuration.
217
216
"""
218
217
run_agent ('foo' )
219
218
# Safe environment
220
- osbrain .config [ 'SAFE' ] = True
219
+ monkeypatch . setitem ( osbrain .config , 'SAFE' , True )
221
220
proxy = Proxy ('foo' )
222
221
assert proxy ._safe
223
222
proxy = Proxy ('foo' , safe = False )
224
223
assert not proxy ._safe
225
224
# Unsafe environment
226
- osbrain .config [ 'SAFE' ] = False
225
+ monkeypatch . setitem ( osbrain .config , 'SAFE' , False )
227
226
proxy = Proxy ('foo' )
228
227
assert not proxy ._safe
229
228
proxy = Proxy ('foo' , safe = True )
230
229
assert proxy ._safe
231
230
232
231
233
- def test_agent_proxy_safe_and_unsafe_calls_property_safe (nsproxy ):
232
+ def test_agent_proxy_safe_and_unsafe_calls_property_safe (monkeypatch , nsproxy ):
234
233
"""
235
234
An agent can be accessed through a proxy in both safe and unsafe ways.
236
235
When using the `safe` property, calls are expected to wait until the main
237
236
thread is able to process them to avoid concurrency.
238
237
"""
239
- osbrain .config [ 'SAFE' ] = False
238
+ monkeypatch . setitem ( osbrain .config , 'SAFE' , False )
240
239
worker = setup_bussy_worker (nsproxy )
241
240
assert not worker ._safe
242
241
t0 = time .time ()
@@ -247,13 +246,14 @@ def test_agent_proxy_safe_and_unsafe_calls_property_safe(nsproxy):
247
246
assert not worker ._safe
248
247
249
248
250
- def test_agent_proxy_safe_and_unsafe_calls_property_unsafe (nsproxy ):
249
+ def test_agent_proxy_safe_and_unsafe_calls_property_unsafe (
250
+ monkeypatch , nsproxy ):
251
251
"""
252
252
An agent can be accessed through a proxy in both safe and unsafe ways.
253
253
When using the `unsafe` property, calls are not expected to wait until
254
254
the main thread is able to process them (concurrency is allowed).
255
255
"""
256
- osbrain .config [ 'SAFE' ] = True
256
+ monkeypatch . setitem ( osbrain .config , 'SAFE' , True )
257
257
worker = setup_bussy_worker (nsproxy )
258
258
assert worker ._safe
259
259
t0 = time .time ()
@@ -266,27 +266,28 @@ def test_agent_proxy_safe_and_unsafe_calls_property_unsafe(nsproxy):
266
266
assert worker ._safe
267
267
268
268
269
- def test_agent_proxy_safe_and_unsafe_calls_environ_safe (nsproxy ):
269
+ def test_agent_proxy_safe_and_unsafe_calls_environ_safe (monkeypatch , nsproxy ):
270
270
"""
271
271
An agent can be accessed through a proxy in both safe and unsafe ways.
272
272
When using the `safe` property, calls are expected to wait until the main
273
273
thread is able to process them to avoid concurrency.
274
274
"""
275
- osbrain .config [ 'SAFE' ] = True
275
+ monkeypatch . setitem ( osbrain .config , 'SAFE' , True )
276
276
worker = setup_bussy_worker (nsproxy )
277
277
t0 = time .time ()
278
278
assert worker .listen () == 'OK'
279
279
assert since (t0 , passed = 2. , tolerance = 0.1 )
280
280
assert not worker .get_attr ('bussy' )
281
281
282
282
283
- def test_agent_proxy_safe_and_unsafe_calls_environ_unsafe (nsproxy ):
283
+ def test_agent_proxy_safe_and_unsafe_calls_environ_unsafe (
284
+ monkeypatch , nsproxy ):
284
285
"""
285
286
An agent can be accessed through a proxy in both safe and unsafe ways.
286
287
When using the `unsafe` property, calls are not expected to wait until
287
288
the main thread is able to process them (concurrency is allowed).
288
289
"""
289
- osbrain .config [ 'SAFE' ] = False
290
+ monkeypatch . setitem ( osbrain .config , 'SAFE' , False )
290
291
worker = setup_bussy_worker (nsproxy )
291
292
t0 = time .time ()
292
293
assert worker .listen () == 'OK'
0 commit comments