Skip to content

Commit

Permalink
tests: split core and psyneulink integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kmantel committed Dec 9, 2023
1 parent 3b3ea9e commit 5677ac3
Show file tree
Hide file tree
Showing 8 changed files with 1,185 additions and 982 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: CI
name: CI Core

on:
push:
Expand Down Expand Up @@ -72,7 +72,7 @@ jobs:
- name: Test with pytest
timeout-minutes: 80
run: pytest --junit-xml=tests_out.xml --verbosity=0 -n auto
run: pytest --junit-xml=tests_out.xml --verbosity=0 -n auto --exclude tests/integration/

- name: Upload test results
uses: actions/upload-artifact@v3
Expand Down
33 changes: 0 additions & 33 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -1,43 +1,10 @@
import doctest
import pytest

from psyneulink.core import llvm as pnlvm


def pytest_runtest_setup(item):
if 'cuda' in item.keywords and not pnlvm.ptx_enabled:
pytest.skip('PTX engine not enabled/available')

doctest.ELLIPSIS_MARKER = "[...]"

def pytest_generate_tests(metafunc):
if "comp_mode_no_llvm" in metafunc.fixturenames:
modes = [m for m in get_comp_execution_modes()
if m.values[0] is not pnlvm.ExecutionMode.LLVM]
metafunc.parametrize("comp_mode", modes)

elif "comp_mode" in metafunc.fixturenames:
metafunc.parametrize("comp_mode", get_comp_execution_modes())


def pytest_runtest_teardown(item):
pnlvm.cleanup()

@pytest.fixture
def comp_mode_no_llvm():
# dummy fixture to allow 'comp_mode' filtering
pass

@pytest.helpers.register
def get_comp_execution_modes():
return [pytest.param(pnlvm.ExecutionMode.Python),
pytest.param(pnlvm.ExecutionMode.LLVM, marks=pytest.mark.llvm),
pytest.param(pnlvm.ExecutionMode.LLVMExec, marks=pytest.mark.llvm),
pytest.param(pnlvm.ExecutionMode.LLVMRun, marks=pytest.mark.llvm),
pytest.param(pnlvm.ExecutionMode.PTXExec, marks=[pytest.mark.llvm, pytest.mark.cuda]),
pytest.param(pnlvm.ExecutionMode.PTXRun, marks=[pytest.mark.llvm, pytest.mark.cuda])
]


# TODO: remove this helper when tests no longer use psyneulink
@pytest.helpers.register
Expand Down
1 change: 1 addition & 0 deletions psyneulink_requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
psyneulink >=0.9.1.0
41 changes: 41 additions & 0 deletions tests/integration/psyneulink/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import pytest

try:
from psyneulink.core import llvm as pnlvm
except Exception:
# psyneulink unavailable
pass
else:
def pytest_runtest_setup(item):
if 'cuda' in item.keywords and not pnlvm.ptx_enabled:
pytest.skip('PTX engine not enabled/available')

def pytest_generate_tests(metafunc):
if "comp_mode_no_llvm" in metafunc.fixturenames:
modes = [
m for m in get_comp_execution_modes()
if m.values[0] is not pnlvm.ExecutionMode.LLVM
]
metafunc.parametrize("comp_mode", modes)

elif "comp_mode" in metafunc.fixturenames:
metafunc.parametrize("comp_mode", get_comp_execution_modes())

def pytest_runtest_teardown(item):
pnlvm.cleanup()

@pytest.fixture
def comp_mode_no_llvm():
# dummy fixture to allow 'comp_mode' filtering
pass

@pytest.helpers.register
def get_comp_execution_modes():
return [
pytest.param(pnlvm.ExecutionMode.Python),
pytest.param(pnlvm.ExecutionMode.LLVM, marks=pytest.mark.llvm),
pytest.param(pnlvm.ExecutionMode.LLVMExec, marks=pytest.mark.llvm),
pytest.param(pnlvm.ExecutionMode.LLVMRun, marks=pytest.mark.llvm),
pytest.param(pnlvm.ExecutionMode.PTXExec, marks=[pytest.mark.llvm, pytest.mark.cuda]),
pytest.param(pnlvm.ExecutionMode.PTXRun, marks=[pytest.mark.llvm, pytest.mark.cuda])
]
46 changes: 46 additions & 0 deletions tests/integration/psyneulink/test_pnl_condition.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import numpy as np
import pytest

# importorskip/skipif module level does not provide reason for skipping
try:
import psyneulink as pnl
except Exception as e:
pnl_err = e
else:
pnl_err = None


@pytest.mark.skipif(
pnl_err is not None, reason=f'psyneulink error: {pnl_err}'
)
@pytest.mark.psyneulink
class TestCondition:
@pytest.mark.parametrize(
'parameter, indices, default_variable, integration_rate, expected_results',
[
('value', None, None, 1, [[[10]]]),
('value', (0, 0), [[0, 0]], [1, 2], [[[10, 20]]]),
('value', (0, 1), [[0, 0]], [1, 2], [[[5, 10]]]),
('num_executions', pnl.TimeScale.TRIAL, None, 1, [[[10]]]),
]
)
@pytest.mark.parametrize('threshold', [10, 10.0])
def test_Threshold_parameters(
self, parameter, indices, default_variable, integration_rate, expected_results, threshold,
):

A = pnl.TransferMechanism(
default_variable=default_variable,
integrator_mode=True,
integrator_function=pnl.SimpleIntegrator,
integration_rate=integration_rate,
)
comp = pnl.Composition(pathways=[A])

comp.termination_processing = {
pnl.TimeScale.TRIAL: pnl.Threshold(A, parameter, threshold, '>=', indices=indices)
}

comp.run(inputs={A: np.ones(A.defaults.variable.shape)})

np.testing.assert_array_equal(comp.results, expected_results)
Loading

0 comments on commit 5677ac3

Please sign in to comment.