Skip to content

Commit

Permalink
tests: make core independent of psyneulink
Browse files Browse the repository at this point in the history
Most tests came from psyneulink and used psyneulink objects despite
testing only scheduler functionality.
Replace these with generic/non-psyneulink alternatives so that
testing core graph-scheduler functionality does not depend on
psyneulink.
  • Loading branch information
kmantel committed Dec 12, 2023
1 parent 761d5a5 commit d72daae
Show file tree
Hide file tree
Showing 4 changed files with 802 additions and 1,347 deletions.
48 changes: 40 additions & 8 deletions tests/scheduling/conftest.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,27 @@
import types

import psyneulink as pnl
import pytest

import graph_scheduler as gs


class SimpleTestNode(types.SimpleNamespace):
def __init__(self, name=None, is_finished_flag=True, value=0):
super().__init__(name=name, is_finished_flag=is_finished_flag, value=value)

def __hash__(self):
return id(self)

def __repr__(self):
return str(self.name)

def is_finished(self, execution_id):
return self.is_finished_flag

def add(self, n=1):
self.value += n
return self.value


def pytest_assertrepr_compare(op, left, right):
if isinstance(left, list) and isinstance(right, list) and op == '==':
Expand Down Expand Up @@ -37,12 +56,25 @@ def create_node(function=lambda x: x):


@pytest.fixture
def three_node_linear_composition():
A = pnl.TransferMechanism(name='A')
B = pnl.TransferMechanism(name='B')
C = pnl.TransferMechanism(name='C')
def three_node_linear_scheduler():
A = SimpleTestNode('A')
B = SimpleTestNode('B')
C = SimpleTestNode('C')

comp = pnl.Composition()
comp.add_linear_processing_pathway([A, B, C])
sched = gs.Scheduler(graph=create_graph_from_pathways([A, B, C]))

return sched.nodes, sched


@pytest.helpers.register
def get_test_node():
return SimpleTestNode


@pytest.helpers.register
def run_scheduler(scheduler, func=lambda test_node: test_node, **run_kwargs):
for execution_set in scheduler.run(**run_kwargs):
for node in execution_set:
func(node)

return comp.nodes, comp
return [node.value for node in scheduler.nodes]

0 comments on commit d72daae

Please sign in to comment.