示例#1
0
    def test_numerical_values_changed(self):

        # Here we slice two of the dimensions and then compare the results to a
        # manually sliced dataset.

        derived = IndexedData(self.data, (None, 2, None, 4, None))
        data_collection = DataCollection([self.data, derived])

        class CustomListener(HubListener):
            def __init__(self, hub):
                self.received = 0
                hub.subscribe(self,
                              NumericalDataChangedMessage,
                              handler=self.receive_message)

            def receive_message(self, message):
                self.received += 1

        listener = CustomListener(data_collection.hub)

        assert listener.received == 0

        derived.indices = (None, 3, None, 5, None)

        assert listener.received == 1

        derived.indices = (None, 3, None, 5, None)

        assert listener.received == 1
示例#2
0
    def test_numerical_values_changed(self):

        # Here we slice two of the dimensions and then compare the results to a
        # manually sliced dataset.

        derived = IndexedData(self.data, (None, 2, None, 4, None))
        data_collection = DataCollection([self.data, derived])

        class CustomListener(HubListener):

            def __init__(self, hub):
                self.received = 0
                hub.subscribe(self, NumericalDataChangedMessage,
                              handler=self.receive_message)

            def receive_message(self, message):
                self.received += 1

        listener = CustomListener(data_collection.hub)

        assert listener.received == 0

        derived.indices = (None, 3, None, 5, None)

        assert listener.received == 1

        derived.indices = (None, 3, None, 5, None)

        assert listener.received == 1
示例#3
0
    def test_invalid_indices_changed(self):

        derived = IndexedData(self.data, (None, 2, None, 4, None))

        with pytest.raises(TypeError) as exc:
            derived.indices = (2, None, 4, None, 5)
        assert exc.value.args[0] == "Can't change where the ``None`` values are in indices"

        with pytest.raises(ValueError) as exc:
            derived.indices = (2, None, 4, None)
        assert exc.value.args[0] == "The 'indices' tuple should have length 5"
示例#4
0
    def test_invalid_indices_changed(self):

        derived = IndexedData(self.data, (None, 2, None, 4, None))

        with pytest.raises(TypeError) as exc:
            derived.indices = (2, None, 4, None, 5)
        assert exc.value.args[
            0] == "Can't change where the ``None`` values are in indices"

        with pytest.raises(ValueError) as exc:
            derived.indices = (2, None, 4, None)
        assert exc.value.args[0] == "The 'indices' tuple should have length 5"