def test_menu(self): with self.create_temporary_view() as ui: node_adapter, obj, sim_node_id, _ = get_node_data_list_element(ui) group_items = get_group_items(node_adapter, obj) all_actions = [item.action.name for item in group_items] self.assertIn(RUN_ACTION, set(all_actions)) self.assertIn(PLOT_ACTION, set(all_actions)) self.assertIn(DUPLIC_ACTION, set(all_actions))
def right_click_on_list_data_and_action(self, ds, list_name, action_name): """ Programmatically create a tree view for the provided datasource, right click on the first element of one its lists and select an action. """ with create_temporary_view(list_name, ds) as ui: node_adapter, obj, node_id, _ = get_node_data_list_element(ui) group_items = get_group_items(node_adapter, obj) action = [ item.action for item in group_items if item.action.name == action_name ][0] tree_editor = get_tree_editor_in_ui(ui) tree_editor._data = (node_adapter, obj, node_id) tree_editor._perform(action)
def test_duplicate_menu_action(self): with self.create_temporary_view() as ui: editor = ui._editors[0] node_adapter, obj, sim_node_id, _ = get_node_data_list_element(ui) group_items = get_group_items(node_adapter, obj) duplicate_action = [ item.action for item in group_items if item.action.name == DUPLIC_ACTION ][0] self.assertEqual(len(self.study.simulations), 1) # Set up the tree editor to fake a right click on a editor._data = node_adapter, obj, sim_node_id editor.perform(duplicate_action) self.assertEqual(len(self.study.simulations), 2)
def assert_menu_content(container_obj, list_name, expected_actions, node_data_getter, assert_func=None): """ Build a UI for the container object displaying a list of object, and assert the menu content on an tree element. """ if assert_func is None: assert_func = assert_equal with create_temporary_view(list_name, container_obj) as ui: node_adapter, obj, sim_node_id, _ = node_data_getter(ui) group_items = get_group_items(node_adapter, obj) actions = [item.action for item in group_items] assert_func(set(actions), expected_actions)
def test_datasource_data_menu(self): # loop over the name of all lists in both datasources, build a UI and # collect the first node inside each list to analyze the node's menu # entries: entries = self.user_ds_entries + self.in_study_ds_entries num_study_entries = len(self.in_study_ds_entries) datasources = [self.user_ds] * len(self.user_ds_entries) + \ [self.study.study_datasource] * num_study_entries for entry, ds in zip(entries, datasources): with create_temporary_view(entry, ds) as ui: node_adapter, obj, sim_node_id, _ = get_node_data_list_element( ui) group_items = get_group_items(node_adapter, obj) actions = [item.action for item in group_items] self.assertEqual(set(actions), set(self.standard_actions)) for action in actions: if action.name in ["Cut", "Copy"]: self.assertTrue(action.enabled) self.assertTrue(action.visible)