Skip to content

Commit

Permalink
Merge pull request datalad#7690 from yarikoptic/rf-test
Browse files Browse the repository at this point in the history
test: refactor test_parallel.py to be abit more pytest'y
  • Loading branch information
yarikoptic authored Dec 13, 2024
2 parents 7987c55 + 5217592 commit bfeb0a8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
3 changes: 3 additions & 0 deletions changelog.d/pr-7690.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### 🧪 Tests

- test: refactor test_parallel.py to be abit more pytest'y. [PR #7690](https://github.com/datalad/datalad/pull/7690) (by [@yarikoptic](https://github.com/yarikoptic))
27 changes: 11 additions & 16 deletions datalad/support/tests/test_parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,23 @@
assert_greater_equal,
assert_raises,
assert_repo_status,
known_failure_osx,
on_osx,
on_windows,
rmtree,
skip_if,
slow,
with_tempfile,
)

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 @@ -74,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 @@ -87,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 @@ -100,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 bfeb0a8

Please sign in to comment.