Exemplo n.º 1
0
class TestDendroClient():
    def setup_method(self, method):

        self.data = Data(parent=[4, 4, 5, 5, 5, -1],
                         height=[5, 4, 3, 2, 1, 0],
                         label='dendro')
        self.dc = DataCollection([self.data])
        self.hub = self.dc.hub
        self.client = DendroClient(self.dc, figure=FIGURE)
        EditSubsetMode().data_collection = self.dc

    def add_subset_via_hub(self):
        self.connect()
        self.client.add_layer(self.data)
        s = self.data.new_subset()
        return s

    def connect(self):
        self.client.register_to_hub(self.hub)
        self.dc.register_to_hub(self.hub)

    def click(self, x, y):
        roi = PointROI(x=x, y=y)
        self.client.apply_roi(roi)

    def test_data_present_after_adding(self):
        assert self.data not in self.client
        self.client.add_layer(self.data)
        assert self.data in self.client

    def test_add_data_adds_subsets(self):
        s1 = self.data.new_subset()
        self.client.add_layer(self.data)
        assert s1 in self.client

    def test_remove_data(self):

        self.client.add_layer(self.data)
        self.client.remove_layer(self.data)

        assert self.data not in self.client

    def test_remove_data_removes_subsets(self):
        s = self.data.new_subset()
        self.client.add_layer(self.data)

        self.client.remove_layer(self.data)
        assert s not in self.client

    def test_add_subset_hub(self):
        s = self.add_subset_via_hub()
        assert s in self.client

    def test_new_subset_autoadd(self):
        self.connect()
        self.client.add_layer(self.data)
        s = self.data.new_subset()
        assert s in self.client

    def test_remove_subset_hub(self):

        s = self.add_subset_via_hub()
        s.delete()

        assert s not in self.client

    def test_subset_sync(self):
        s = self.add_subset_via_hub()

        self.client._update_layer = MagicMock()
        s.style.color = 'blue'
        self.client._update_layer.assert_called_once_with(s)

    def test_data_sync(self):
        self.connect()
        self.client.add_layer(self.data)

        self.client._update_layer = MagicMock()
        self.data.style.color = 'blue'
        self.client._update_layer.assert_called_once_with(self.data)

    def test_data_remove(self):
        s = self.add_subset_via_hub()
        self.dc.remove(self.data)

        assert self.data not in self.dc
        assert self.data not in self.client
        assert s not in self.client

    def test_log(self):
        self.client.ylog = True
        assert self.client.axes.get_yscale() == 'log'

    def test_1d_data_required(self):
        d = Data(x=[[1, 2], [2, 3]])
        self.dc.append(d)
        self.client.add_layer(d)
        assert d not in self.client

    def test_apply_roi(self):
        self.client.add_layer(self.data)
        self.client.select_substruct = False

        self.click(0, 4)
        s = self.data.subsets[0]

        assert_array_equal(s.to_index_list(), [1])

        self.click(0, 3)
        assert_array_equal(s.to_index_list(), [1])

        self.click(0, 0)
        assert_array_equal(s.to_index_list(), [4])

        self.click(.75, 4)
        assert_array_equal(s.to_index_list(), [0])

        self.click(0, 10)
        assert_array_equal(s.to_index_list(), [])

    def test_apply_roi_children_select(self):
        self.client.select_substruct = True
        self.client.add_layer(self.data)

        self.click(.5, .5)
        s = self.data.subsets[0]

        assert_array_equal(s.to_index_list(), [0, 1, 4])

    def test_attribute_change_triggers_relayout(self):
        self.client.add_layer(self.data)

        l = self.client._layout
        self.client.height_attr = self.data.id['parent']
        assert self.client._layout is not l

        l = self.client._layout
        self.client.parent_attr = self.data.id['height']
        assert self.client._layout is not l

        l = self.client._layout
        self.client.order_attr = self.data.id['parent']
        assert self.client._layout is not l
Exemplo n.º 2
0
    def receive_message(self, message):
        """ Receives each DataMessage relay """
        print "    MyClient received a message \n"


# create objects
hub = Hub()
client = MyClient()
data = Data()
subset = data.new_subset()
data_collection = DataCollection()

# connect them to each other
data_collection.append(data)
data_collection.register_to_hub(hub)
client.register_to_hub(hub)

# manually send a DataMessage. Relayed to MyClient
print 'Manually sending DataMessage'
message = DataMessage(data)
hub.broadcast(message)

#modify the data object. Automatically generates a DataMessage
print 'Automatically triggering DataMessage'
data.label = "New label"

#send a SubsetMessage to the Hub.
print 'Manually sending SubsetMessage'
message = SubsetMessage(subset)
hub.broadcast(message) # nothing is printed
Exemplo n.º 3
0
class TestDendroClient():

    def setup_method(self, method):

        self.data = Data(parent=[4, 4, 5, 5, 5, -1],
                         height=[5, 4, 3, 2, 1, 0],
                         label='dendro')
        self.dc = DataCollection([self.data])
        self.hub = self.dc.hub
        self.client = DendroClient(self.dc, figure=FIGURE)
        EditSubsetMode().data_collection = self.dc

    def add_subset_via_hub(self):
        self.connect()
        self.client.add_layer(self.data)
        s = self.data.new_subset()
        return s

    def connect(self):
        self.client.register_to_hub(self.hub)
        self.dc.register_to_hub(self.hub)

    def click(self, x, y):
        roi = PointROI(x=x, y=y)
        self.client.apply_roi(roi)

    def test_data_present_after_adding(self):
        assert self.data not in self.client
        self.client.add_layer(self.data)
        assert self.data in self.client

    def test_add_data_adds_subsets(self):
        s1 = self.data.new_subset()
        self.client.add_layer(self.data)
        assert s1 in self.client

    def test_remove_data(self):

        self.client.add_layer(self.data)
        self.client.remove_layer(self.data)

        assert self.data not in self.client

    def test_remove_data_removes_subsets(self):
        s = self.data.new_subset()
        self.client.add_layer(self.data)

        self.client.remove_layer(self.data)
        assert s not in self.client

    def test_add_subset_hub(self):
        s = self.add_subset_via_hub()
        assert s in self.client

    def test_new_subset_autoadd(self):
        self.connect()
        self.client.add_layer(self.data)
        s = self.data.new_subset()
        assert s in self.client

    def test_remove_subset_hub(self):

        s = self.add_subset_via_hub()
        s.delete()

        assert s not in self.client

    def test_subset_sync(self):
        s = self.add_subset_via_hub()

        self.client._update_layer = MagicMock()
        s.style.color = 'blue'
        self.client._update_layer.assert_called_once_with(s)

    def test_data_sync(self):
        self.connect()
        self.client.add_layer(self.data)

        self.client._update_layer = MagicMock()
        self.data.style.color = 'blue'
        self.client._update_layer.assert_called_once_with(self.data)

    def test_data_remove(self):
        s = self.add_subset_via_hub()
        self.dc.remove(self.data)

        assert self.data not in self.dc
        assert self.data not in self.client
        assert s not in self.client

    def test_log(self):
        self.client.ylog = True
        assert self.client.axes.get_yscale() == 'log'

    def test_1d_data_required(self):
        d = Data(x=[[1, 2], [2, 3]])
        self.dc.append(d)
        self.client.add_layer(d)
        assert d not in self.client

    def test_apply_roi(self):
        self.client.add_layer(self.data)
        self.client.select_substruct = False

        self.click(0, 4)
        s = self.data.subsets[0]

        assert_array_equal(s.to_index_list(), [1])

        self.click(0, 3)
        assert_array_equal(s.to_index_list(), [1])

        self.click(0, 0)
        assert_array_equal(s.to_index_list(), [4])

        self.click(.75, 4)
        assert_array_equal(s.to_index_list(), [0])

        self.click(0, 10)
        assert_array_equal(s.to_index_list(), [])

    def test_apply_roi_children_select(self):
        self.client.select_substruct = True
        self.client.add_layer(self.data)

        self.click(.5, .5)
        s = self.data.subsets[0]

        assert_array_equal(s.to_index_list(), [0, 1, 4])

    def test_attribute_change_triggers_relayout(self):
        self.client.add_layer(self.data)

        l = self.client._layout
        self.client.height_attr = self.data.id['parent']
        assert self.client._layout is not l

        l = self.client._layout
        self.client.parent_attr = self.data.id['height']
        assert self.client._layout is not l

        l = self.client._layout
        self.client.order_attr = self.data.id['parent']
        assert self.client._layout is not l
Exemplo n.º 4
0
    def receive_message(self, message):
        """ Receives each DataMessage relay """
        print "    MyClient received a message \n"


# create objects
hub = Hub()
client = MyClient()
data = Data()
subset = data.new_subset()
data_collection = DataCollection()

# connect them to each other
data_collection.append(data)
data_collection.register_to_hub(hub)
client.register_to_hub(hub)

# manually send a DataMessage. Relayed to MyClient
print 'Manually sending DataMessage'
message = DataMessage(data)
hub.broadcast(message)

#modify the data object. Automatically generates a DataMessage
print 'Automatically triggering DataMessage'
data.label = "New label"

#send a SubsetMessage to the Hub.
print 'Manually sending SubsetMessage'
message = SubsetMessage(subset)
hub.broadcast(message)  # nothing is printed