Skip to content

Commit

Permalink
introducing pytest generate functions
Browse files Browse the repository at this point in the history
  • Loading branch information
anushka255 committed Sep 23, 2024
1 parent cdf891d commit a484322
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions tests/test_paste.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import hashlib
import sys
from pathlib import Path

import numpy as np
import ot.backend
import pandas as pd
Expand Down Expand Up @@ -36,7 +36,22 @@ def assert_checksum_equals(temp_dir, filename):
)


def test_pairwise_alignment(slices):
def pytest_generate_tests(metafunc):
if "use_gpu" and "backend" in metafunc.fixturenames:
if sys.platform == "linux":
metafunc.parametrize(
"use_gpu, backend",
[(True, ot.backend.TorchBackend()), (False, ot.backend.NumpyBackend())],
)
else:
metafunc.parametrize(
"use_gpu, backend", [(False, ot.backend.NumpyBackend())]
)
if "gpu_verbose" in metafunc.fixturenames:
metafunc.parametrize("gpu_verbose", [True, False])


def test_pairwise_alignment(slices, use_gpu, backend, gpu_verbose):
temp_dir = Path(tempfile.mkdtemp())
outcome = pairwise_align(
slices[0],
Expand All @@ -46,14 +61,17 @@ def test_pairwise_alignment(slices):
a_distribution=slices[0].obsm["weights"],
b_distribution=slices[1].obsm["weights"],
G_init=None,
use_gpu=use_gpu,
backend=backend,
gpu_verbose=gpu_verbose,
)
pd.DataFrame(
outcome, index=slices[0].obs.index, columns=slices[1].obs.index
).to_csv(temp_dir / "slices_1_2_pairwise.csv")
assert_checksum_equals(temp_dir, "slices_1_2_pairwise.csv")


def test_center_alignment(slices):
def test_center_alignment(slices, use_gpu, backend, gpu_verbose):
temp_dir = Path(tempfile.mkdtemp())

# Make a copy of the list
Expand Down

0 comments on commit a484322

Please sign in to comment.