def test_context_menu_added_for_scripted_plot_with_errors(self): self.ax.plot([0, 15000], [0, 15000], label='MyLabel') self.ax.errorbar([0, 15000], [0, 14000], yerr=[10, 10000], label='MyLabel 2') self.ax.containers[0][2][0].axes.creation_args = [{'errorevery': 1}] main_menu = QMenu() # QMenu always seems to have 1 child when empty, # but just making sure the count as expected at this point in the test self.assertEqual(1, len(main_menu.children())) # plot above doesn't have errors, nor is a MantidAxes # so no context menu will be added self.interactor.add_error_bars_menu(main_menu, self.ax) added_menu = main_menu.children()[1] # actions should have been added now, which for this case are only `Show all` and `Hide all` self.assertTrue( any(FigureInteraction.SHOW_ERROR_BARS_BUTTON_TEXT == child.text() for child in added_menu.children())) self.assertTrue( any(FigureInteraction.HIDE_ERROR_BARS_BUTTON_TEXT == child.text() for child in added_menu.children()))
def test_context_menu_does_not_include_plot_type_if_plot_has_one_line(self): fig, self.ax = plt.subplots(subplot_kw={'projection': 'mantid'}) self.ax.errorbar([0, 1], [0, 1], capsize=1) main_menu = QMenu() # QMenu always seems to have 1 child when empty, # but just making sure the count as expected at this point in the test self.assertEqual(1, len(main_menu.children())) self.interactor._add_plot_type_option_menu(main_menu, self.ax) # Number of children should remain unchanged self.assertEqual(1, len(main_menu.children()))
def test_context_menu_includes_plot_type_if_plot_has_multiple_lines(self): fig, self.ax = plt.subplots(subplot_kw={'projection': 'mantid'}) self.ax.plot([0, 1], [0, 1]) self.ax.plot([0, 1], [0, 1]) main_menu = QMenu() # QMenu always seems to have 1 child when empty, # but just making sure the count as expected at this point in the test self.assertEqual(1, len(main_menu.children())) self.interactor._add_plot_type_option_menu(main_menu, self.ax) added_menu = main_menu.children()[1] self.assertEqual(added_menu.children()[0].text(), "Plot Type")
def test_context_menu_not_added_for_scripted_plot_without_errors(self): self.ax.plot([0, 15000], [0, 15000], label='MyLabel') self.ax.plot([0, 15000], [0, 14000], label='MyLabel 2') main_menu = QMenu() # QMenu always seems to have 1 child when empty, # but just making sure the count as expected at this point in the test self.assertEqual(1, len(main_menu.children())) # plot above doesn't have errors, nor is a MantidAxes # so no context menu will be added self.interactor.add_error_bars_menu(main_menu, self.ax) # number of children should remain unchanged self.assertEqual(1, len(main_menu.children()))
def test_scripted_plot_line_without_label_handled_properly(self): # having the special nolabel is usually present on lines with errors, # but sometimes can be present on lines without errors, this test covers that case self.ax.plot([0, 15000], [0, 15000], label='_nolegend_') self.ax.plot([0, 15000], [0, 15000], label='_nolegend_') main_menu = QMenu() # QMenu always seems to have 1 child when empty, # but just making sure the count as expected at this point in the test self.assertEqual(1, len(main_menu.children())) # plot above doesn't have errors, nor is a MantidAxes # so no context menu will be added for error bars self.interactor.add_error_bars_menu(main_menu, self.ax) # number of children should remain unchanged self.assertEqual(1, len(main_menu.children()))
def test_add_error_bars_menu(self): main_menu = QMenu() self.errors_manager.add_error_bars_menu(main_menu, self.ax) # Check the expected sub-menu with buttons is added added_menu = main_menu.children()[1] self.assertTrue( any(FigureErrorsManager.SHOW_ERROR_BARS_BUTTON_TEXT == child.text() for child in added_menu.children())) self.assertTrue( any(FigureErrorsManager.HIDE_ERROR_BARS_BUTTON_TEXT == child.text() for child in added_menu.children()))
def test_add_error_bars_menu(self): self.ax.errorbar([0, 15000], [0, 14000], yerr=[10, 10000], label='MyLabel 2') main_menu = QMenu() self.interactor.add_error_bars_menu(main_menu, self.ax) # Check the expected sub-menu with buttons is added added_menu = main_menu.children()[1] self.assertTrue( any(FigureInteraction.SHOW_ERROR_BARS_BUTTON_TEXT == child.text() for child in added_menu.children())) self.assertTrue( any(FigureInteraction.HIDE_ERROR_BARS_BUTTON_TEXT == child.text() for child in added_menu.children()))