def test_text_from_property_fstring(properties): """Test setting text with an f-string from the property value""" shape = (10, 4, 2) np.random.seed(0) data = 20 * np.random.random(shape) layer = Shapes(data, properties=copy(properties), text='type: {shape_type}') expected_text = ['type: ' + v for v in properties['shape_type']] np.testing.assert_equal(layer.text.values, expected_text) # test updating the text layer.text = 'type-ish: {shape_type}' expected_text_2 = ['type-ish: ' + v for v in properties['shape_type']] np.testing.assert_equal(layer.text.values, expected_text_2) # copy/paste layer.selected_data = {0} layer._copy_data() layer._paste_data() expected_text_3 = expected_text_2 + ['type-ish: A'] np.testing.assert_equal(layer.text.values, expected_text_3) # add shape layer.selected_data = {0} new_shape = np.random.random((1, 4, 2)) layer.add(new_shape) expected_text_4 = expected_text_3 + ['type-ish: A'] np.testing.assert_equal(layer.text.values, expected_text_4)
def test_change_text_updates_node_string(): shapes = np.random.rand(3, 4, 2) properties = { 'class': np.array(['A', 'B', 'C']), 'name': np.array(['D', 'E', 'F']), } layer = Shapes(shapes, properties=properties, text='class') vispy_layer = VispyShapesLayer(layer) text_node = vispy_layer._get_text_node() np.testing.assert_array_equal(text_node.text, properties['class']) layer.text = 'name' np.testing.assert_array_equal(text_node.text, properties['name'])