Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions nineml/abstraction/componentclass/visitors/validators/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
from sympy.logic.boolalg import BooleanTrue, BooleanFalse
from nineml.visitors import BaseVisitor, BaseVisitorWithContext
from functools import reduce
import warnings
from nineml.abstraction.componentclass.ports import EventSendPort



class AliasesAreNotRecursiveComponentValidator(BaseVisitor):
Expand Down Expand Up @@ -371,3 +374,31 @@ def action_alias(self, alias, **kwargs): # @UnusedVariable

def default_action(self, obj, nineml_cls, **kwargs):
pass

class EventSendPortHasOutputEventComponentValidator(BaseVisitorWithContext):
"""
Warn if an EventSendPort has no matching OutputEvent
"""

def __init__(self, component_class, **kwargs): # @UnusedVariable
BaseVisitorWithContext.__init__(self)
self.component_class = component_class
self.visit(component_class)

def action_eventsendport(self, port, **kwargs): # @UnusedVariable
# Check for matching OutputEvent by name
matches = [
ev for ev in self.component_class.output_events
if ev.name == port.name
]

if not matches:
warnings.warn(
"EventSendPort '{}' has no matching OutputEvent"
.format(port.name),
UserWarning
)

def default_action(self, obj, nineml_cls, **kwargs):
pass