Skip to content

Commit

Permalink
test: refactor test_ProducerConsumer to use fixture and parametrization
Browse files Browse the repository at this point in the history
  • Loading branch information
yarikoptic committed Dec 12, 2024
1 parent 9a0db8e commit b9675f8
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions datalad/support/tests/test_parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,15 @@
info_log_level = lgr.getEffectiveLevel() >= logging.INFO


def check_ProducerConsumer(PC, jobs):
@pytest.fixture(params=["auto", None, 1, 10])
def jobs(request):
"""Fixture to automagically sweep over a sample of "jobs" values
"""
return request.param


@pytest.mark.parametrize("PC", [ProducerConsumer, ProducerConsumerProgressLog])
def test_ProducerConsumer_PC(PC, jobs):
def slowprod(n, secs=0.001):
for i in range(n):
yield i
Expand Down Expand Up @@ -70,7 +78,7 @@ def fastcons(i):
[{"i": i, "status": "ok" if i % 2 else "error"} for i in range(10)])


def check_producing_consumer(jobs):
def test_producing_consumer(jobs):
def producer():
yield from range(3)
def consumer(i):
Expand All @@ -83,7 +91,7 @@ def consumer(i):
assert_equal(list(pc), [0, 1, 2, "0", "1", "4"])


def check_producer_future_key(jobs):
def test_producer_future_key(jobs):
def producer():
for i in range(3):
yield i, {"k": i**2} # dict is mutable, will need a key
Expand All @@ -96,15 +104,6 @@ def consumer(args):
assert_equal(list(pc), [0, 1, 2])


def test_ProducerConsumer():
# Largely a smoke test, which only verifies correct results output
for jobs in "auto", None, 1, 10:
for PC in ProducerConsumer, ProducerConsumerProgressLog:
check_ProducerConsumer(PC, jobs)
check_producing_consumer(jobs)
check_producer_future_key(jobs)


@slow # 12sec on Yarik's laptop
@with_tempfile(mkdir=True)
def test_creatsubdatasets(topds_path=None, n=2):
Expand Down

0 comments on commit b9675f8

Please sign in to comment.