def test_asynctask_class(broker, monkeypatch): broker.purge_queue() broker.cache.clear() a = AsyncTask("math.copysign") assert a.func == "math.copysign" a.args = (1, -1) assert a.started is False a.cached = True assert a.cached a.sync = True assert a.sync a.broker = broker assert a.broker == broker a.run() assert a.result() == -1 assert a.fetch().result == -1 # again with kwargs a = AsyncTask("math.copysign", 1, -1, cached=True, sync=True, broker=broker) a.run() assert a.result() == -1 # with q_options a = AsyncTask( "math.copysign", 1, -1, q_options={ "cached": True, "sync": False, "broker": broker }, ) assert not a.sync a.sync = True assert a.kwargs["q_options"]["sync"] is True a.run() assert a.result() == -1 a.group = "async_class_test" assert a.group == "async_class_test" a.save = False assert not a.save a.hook = "djq.tests.tasks.hello" assert a.hook == "djq.tests.tasks.hello" assert a.started is False a.run() assert a.result_group() == [-1] assert a.fetch_group() == [a.fetch()] # global overrides monkeypatch.setattr(Conf, "SYNC", True) monkeypatch.setattr(Conf, "CACHED", True) a = AsyncTask("math.floor", 1.5) a.run() assert a.result() == 1
def test_asynctask_class(broker, monkeypatch): broker.purge_queue() broker.cache.clear() a = AsyncTask('math.copysign') assert a.func == 'math.copysign' a.args = (1, -1) assert a.started is False a.cached = True assert a.cached a.sync = True assert a.sync a.broker = broker assert a.broker == broker a.run() assert a.result() == -1 assert a.fetch().result == -1 # again with kwargs a = AsyncTask('math.copysign', 1, -1, cached=True, sync=True, broker=broker) a.run() assert a.result() == -1 # with q_options a = AsyncTask('math.copysign', 1, -1, q_options={ 'cached': True, 'sync': False, 'broker': broker }) assert not a.sync a.sync = True assert a.kwargs['q_options']['sync'] is True a.run() assert a.result() == -1 a.group = 'async_class_test' assert a.group == 'async_class_test' a.save = False assert not a.save a.hook = 'djq.tests.tasks.hello' assert a.hook == 'djq.tests.tasks.hello' assert a.started is False a.run() assert a.result_group() == [-1] assert a.fetch_group() == [a.fetch()] # global overrides monkeypatch.setattr(Conf, 'SYNC', True) monkeypatch.setattr(Conf, 'CACHED', True) a = AsyncTask('math.floor', 1.5) a.run() assert a.result() == 1
def test_asynctask_class(broker, monkeypatch): broker.purge_queue() broker.cache.clear() a = AsyncTask('math.copysign') assert a.func == 'math.copysign' a.args = (1, -1) assert a.started is False a.cached = True assert a.cached is True a.sync = True assert a.sync is True a.broker = broker assert a.broker == broker a.run() assert a.result() == -1 assert a.fetch().result == -1 # again with kwargs a = AsyncTask('math.copysign', 1, -1, cached=True, sync=True, broker=broker) a.run() assert a.result() == -1 # with q_options a = AsyncTask('math.copysign', 1, -1, q_options={'cached': True, 'sync': False, 'broker': broker}) assert a.sync is False a.sync = True assert a.kwargs['q_options']['sync'] is True a.run() assert a.result() == -1 a.group = 'async_class_test' assert a.group == 'async_class_test' a.save = False assert a.save is False a.hook = 'djq.tests.tasks.hello' assert a.hook == 'djq.tests.tasks.hello' assert a.started is False a.run() assert a.result_group() == [-1] assert a.fetch_group() == [a.fetch()] # global overrides monkeypatch.setattr(Conf, 'SYNC', True) monkeypatch.setattr(Conf, 'CACHED', True) a = AsyncTask('math.floor', 1.5) a.run() assert a.result() == 1