async def test_download_semaphore(): context = swcontext.Context() context.config = {"foo": "bar"} sem = context.download_semaphore assert type(sem) == asyncio.BoundedSemaphore assert sem._value == swcontext.DEFAULT_MAX_CONCURRENT_DOWNLOADS assert sem is context.download_semaphore
def test_set_event_loop(mocker): """`context.event_loop` returns the same value once set. (This may seem obvious, but this tests the correctness of the property.) """ fake_loop = mock.MagicMock() context = swcontext.Context() context.event_loop = fake_loop assert context.event_loop is fake_loop
def test_bad_verify_task(claim_task, bad_path): context = swcontext.Context() context.task = { "payload": { "upstreamArtifacts": [{ "taskId": "bar", "paths": ["baz", bad_path], }], }, } with pytest.raises(CoTError): context.verify_task()
def test_verify_task(claim_task): context = swcontext.Context() context.task = { "payload": { "upstreamArtifacts": [{ "taskId": "foo", "paths": ["bar"], }], }, } # should not throw context.verify_task()
def test_new_event_loop(mocker): """The default context.event_loop is from `asyncio.get_event_loop`""" fake_loop = mock.MagicMock() mocker.patch.object(asyncio, 'get_event_loop', return_value=fake_loop) context = swcontext.Context() assert context.event_loop is fake_loop