コード例 #1
0
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
コード例 #2
0
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
コード例 #3
0
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
コード例 #4
0
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
コード例 #5
0
def test_raise_exception(scheduler):
    """
    Tests whether the Scheduler responds correctly to a task raising an exception.
    """
    args, expected = _get_input_output()

    loop = asyncio.get_event_loop()
    try:
        loop.run_until_complete(
            scheduler.map(target=_func_raise_exception, args=args))
        assert False, "Scheduler did not raise Exception."
    except Exception as e:
        assert isinstance(e, TaskFailedException)

    assert scheduler.failed
コード例 #6
0
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
コード例 #7
0
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