Skip to content

Commit

Permalink
tests: Add a helper to generate power set
Browse files Browse the repository at this point in the history
Use it to test all combinations of debug flags

Signed-off-by: Jan Vesely <[email protected]>
  • Loading branch information
jvesely committed Jun 29, 2023
1 parent 70281e8 commit 7648f49
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 9 additions & 1 deletion conftest.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import contextlib
import doctest
import io
import itertools
import numpy as np
import psyneulink
import pytest
import re
import sys

import psyneulink
from psyneulink import clear_registry, primary_registries, torch_available
from psyneulink.core import llvm as pnlvm
from psyneulink.core.globals.utilities import set_global_seed
Expand Down Expand Up @@ -246,6 +247,13 @@ def expand_np_ndarray(arr):
results_list.extend(nested_elem)
return results_list

@pytest.helpers.register
def power_set(s):
"""Set of all potential subsets."""

vals = list(s)
return (c for l in range(len(vals) + 1) for c in itertools.combinations(vals, l))


# flag when run from pytest
# https://docs.pytest.org/en/stable/example/simple.html#detect-if-running-from-within-a-pytest-run
Expand Down
2 changes: 1 addition & 1 deletion tests/llvm/test_debug_composition.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from psyneulink.core.compositions.composition import Composition

debug_options=["const_input=[[[7]]]", "const_input", "const_params", "const_data", "const_state", "stat", "time_stat", "unaligned_copy"]
options_combinations = (";".join(("", *c)) for i in range(len(debug_options) + 1) for c in combinations(debug_options, i))
options_combinations = (";".join(("", *c)) for c in pytest.helpers.power_set(debug_options))

@pytest.mark.composition
@pytest.mark.parametrize("mode", [pytest.param(pnlvm.ExecutionMode.LLVMRun, marks=pytest.mark.llvm),
Expand Down

0 comments on commit 7648f49

Please sign in to comment.