예제 #1
0
 def test_default_name_and_projections_listing_for_input_port_in_constructor(
         self):
     T1 = TransferMechanism()
     my_input_port = InputPort(projections=[T1])
     T2 = TransferMechanism(input_ports=[my_input_port])
     assert T2.input_ports[0].name == 'InputPort-0'
     assert T2.input_ports[0].projections[0].sender.name == 'RESULT'
예제 #2
0
    def test_user_added_ports(self):

        comp = Composition()
        mech = ProcessingMechanism()
        comp.add_node(mech)
        # instantiate custom input and output ports
        inp = InputPort(size=2)
        out = OutputPort(size=2)
        # add custom input and output ports to CIM
        comp.input_CIM.add_ports([inp, out])
        # verify the ports have been added to the user_added_ports set
        # and that no extra ports were added
        assert inp in comp.input_CIM.user_added_ports['input_ports']
        assert len(comp.input_CIM.user_added_ports['input_ports']) == 1
        assert out in comp.input_CIM.user_added_ports['output_ports']
        assert len(comp.input_CIM.user_added_ports['output_ports']) == 1
        comp.input_CIM.remove_ports([inp, out])
        # verify that call to remove ports succesfully removed the ports from user_added_ports
        assert len(comp.input_CIM.user_added_ports['input_ports']) == 0
        assert len(comp.input_CIM.user_added_ports['output_ports']) == 0
예제 #3
0
    def test_warning_on_custom_cim_ports(self):

        comp = Composition()
        mech = ProcessingMechanism()
        comp.add_node(mech)
        warning_text = (
            'You are attempting to add custom ports to a CIM, which can result in unpredictable behavior '
            'and is therefore recommended against. If suitable, you should instead add ports to the '
            r'mechanism\(s\) that project to or are projected to from the CIM.'
        )
        with pytest.warns(UserWarning, match=warning_text):
            # KDM 7/22/20: previously was OutputPort, but that produces
            # an invalid CIM state that cannot be executed, and will
            # throw an error due to new _update_default_variable call
            comp.input_CIM.add_ports(InputPort())

        with pytest.warns(None) as w:
            comp._analyze_graph()
            comp.run({mech: [[1]]})

        assert len(w) == 0
예제 #4
0
    def test_add_input_port_with_projection_by_assigning_owner(self):
        T1 = TransferMechanism()
        T2 = TransferMechanism()
        InputPort(owner=T2, projections=[T1])

        assert T2.input_ports[1].path_afferents[0].sender.owner is T1
예제 #5
0
 def test_add_input_port_with_projection_using_add_ports(self):
     T1 = TransferMechanism()
     I = InputPort(projections=[T1])
     T2 = TransferMechanism()
     T2.add_ports([I])
     assert T2.input_ports[1].path_afferents[0].sender.owner is T1
예제 #6
0
 def test_add_input_port_with_projection_in_mech_constructor(self):
     T1 = TransferMechanism()
     I = InputPort(projections=[T1])
     T2 = TransferMechanism(input_ports=[I])
     assert T2.input_ports[0].path_afferents[0].sender.owner is T1
예제 #7
0
 def test_InputPort_mismatches_default(self):
     with pytest.raises(MechanismError) as error_text:
         i = InputPort(reference_value=[0, 0, 0])
         TransferMechanism(default_variable=[0, 0], input_ports=[i])
     assert mismatches_specified_default_variable_error_text in str(error_text.value)