def test_map_blocking(scheduler): """Tests whether `map_blocking()` works correctly.""" # scheduler = Scheduler() args, expected = _get_input_output() results: List[Tuple[int, int, int]] = scheduler.map_blocking(target=_func, args=args) assert_results(expected, results) assert scheduler.finished
def test_add(scheduler): """Tests whether `add()` works correctly.""" # scheduler = Scheduler() args, expected = _get_input_output() for a in args: scheduler.add(target=_func, args=a) results: List[Tuple[int, int, int]] = scheduler.run_blocking() assert_results(expected, results) assert scheduler.finished
def test_map(scheduler): """Tests whether `map()` works correctly.""" # scheduler = Scheduler() args, expected = _get_input_output() loop = asyncio.get_event_loop() results: List[Tuple[int, int, int]] = loop.run_until_complete( scheduler.map(target=_func, args=args)) assert_results(expected, results) assert scheduler.finished
def test_map_two_return_values(scheduler): """Tests whether `map()` works correctly when the target function returns two results.""" # scheduler = Scheduler() args, expected = _get_input_output_two_results() loop = asyncio.get_event_loop() results: List[Tuple[int, int]] = loop.run_until_complete( scheduler.map(target=_func_returns_two_values, args=args)) assert all([hasattr(r, "__len__") for r in results]) assert_results(expected, results) assert scheduler.finished
def test_run_blocking(scheduler): """Tests whether `run_blocking()` works correctly.""" # scheduler = Scheduler() args, expected = _get_input_output() for a in args: q = Queue() p = Process(target=_funcq, args=(q, ) + a) scheduler.add_process(p, q) results: List[Tuple[int, int, int]] = scheduler.run_blocking() assert_results(expected, results) assert scheduler.finished
def test_add_task(scheduler): """Tests whether tasks are added to the scheduler correctly with `add_task()`.""" # scheduler = Scheduler() args, expected = _get_input_output() for a in args: q = Queue() p = Process(target=_funcq, args=(q, ) + a) task = ProcessTask(p, q) scheduler.add_task(task) results: List[Tuple[int, int, int]] = scheduler.run_blocking() assert_results(expected, results) assert scheduler.finished
def test_multiprocess(scheduler): """Tests whether `add()` and `run_blocking()` work correctly with `multiprocess` instead of `multiprocessing`.""" # scheduler = Scheduler() args, expected = _get_input_output() for a in args: scheduler.add( target=_func, args=a, process_type=multiprocess.Process, queue_type=multiprocess.Queue, ) results: List[Tuple[int, int, int]] = scheduler.run_blocking() assert_results(expected, results) assert scheduler.finished