示例#1
0
    def test_keyspace_collision(self):
        # Create the model with it's default keyspace
        model = Model()

        # Create the keyspace
        keyspace_a = mock.Mock(name="keyspace")
        keyspace_b = mock.Mock(name="keyspace")

        # Create the connection that we're building
        pre = mock.Mock("pre")
        post = mock.Mock("post")
        post.size_in = 0
        connection = mock.Mock(spec_set=nengo.Connection)
        connection.pre_obj = pre
        connection.post_obj = post

        # Create a spec for the source and a spec for the sink
        source_obj = mock.Mock()
        source_spec = spec(source_obj, keyspace=keyspace_a)
        sink_obj = mock.Mock()
        sink_spec = spec(sink_obj, keyspace=keyspace_b)

        with pytest.raises(NotImplementedError) as excinfo:
            _make_signal(model, connection, source_spec, sink_spec)
        assert "keyspace" in str(excinfo.value)
示例#2
0
    def test_standard(self):
        """Test that mostly empty specs result in appropriate calls to build
        the keyspace and that the weight is grabbed from the connection.
        """
        # Create the model with it's default keyspace
        model = mock.Mock()
        model.keyspaces = {"nengo": mock.Mock()}
        exp_ks = model.keyspaces["nengo"].return_value = mock.Mock()
        model._get_object_and_connection_id.return_value = (1, 3)

        # Create the connection that we're building
        pre = mock.Mock("pre")
        post = mock.Mock("post")
        post.size_in = 5
        connection = mock.Mock(spec_set=nengo.Connection)
        connection.pre_obj = pre
        connection.post_obj = post

        # Create a spec for the source and a spec for the sink
        source_obj = mock.Mock()
        source_spec = spec(source_obj)
        sink_obj = mock.Mock()
        sink_spec = spec(sink_obj)

        # Get the Signal
        signal = _make_signal(model, connection, source_spec, sink_spec)
        assert signal.source is source_obj
        assert signal.sinks == [sink_obj]
        assert signal.keyspace is exp_ks
        assert signal.weight == post.size_in
        assert signal.latching is False

        # Check that the keyspace was called correctly
        model.keyspaces["nengo"].assert_called_once_with(object=1,
                                                         connection=3)
示例#3
0
    def test_weights(self, source_weight, sink_weight, expected_weight):
        """Test that weights are taken from the spec.
        """
        # Create the model with it's default keyspace
        model = Model()

        # Create the connection that we're building
        pre = mock.Mock("pre")
        post = mock.Mock("post")
        post.size_in = 5
        connection = mock.Mock(spec_set=nengo.Connection)
        connection.pre_obj = pre
        connection.post_obj = post

        # Create a spec for the source and a spec for the sink
        source_obj = mock.Mock()
        source_spec = spec(source_obj, weight=source_weight)
        sink_obj = mock.Mock()
        sink_spec = spec(sink_obj, weight=sink_weight)

        # Get the Signal
        signal = _make_signal(model, connection, source_spec, sink_spec)
        assert signal.weight == expected_weight
示例#4
0
    def test_keyspace_from_sink(self):
        # Create the model with it's default keyspace
        model = Model()

        # Create the keyspace
        keyspace = mock.Mock(name="keyspace")

        # Create the connection that we're building
        pre = mock.Mock("pre")
        post = mock.Mock("post")
        post.size_in = 0
        connection = mock.Mock(spec_set=nengo.Connection)
        connection.pre_obj = pre
        connection.post_obj = post

        # Create a spec for the source and a spec for the sink
        source_obj = mock.Mock()
        source_spec = spec(source_obj)
        sink_obj = mock.Mock()
        sink_spec = spec(sink_obj, keyspace=keyspace)

        # Get the Signal
        signal = _make_signal(model, connection, source_spec, sink_spec)
        assert signal.keyspace is keyspace
示例#5
0
    def test_latching(self, make_source_spec, make_sink_spec):
        """Test that latching commands are taken from the spec.
        """
        # Create the model with it's default keyspace
        model = Model()
        model.keyspaces = {"nengo": mock.Mock()}

        # Create the connection that we're building
        pre = mock.Mock("pre")
        post = mock.Mock("post")
        post.size_in = 5
        connection = mock.Mock(spec_set=nengo.Connection)
        connection.pre_obj = pre
        connection.post_obj = post

        # Create a spec for the source and a spec for the sink
        source_obj = mock.Mock()
        source_spec = make_source_spec(source_obj)
        sink_obj = mock.Mock()
        sink_spec = make_sink_spec(sink_obj)

        # Get the Signal
        signal = _make_signal(model, connection, source_spec, sink_spec)
        assert signal.latching is True