def test_draw_save_action(self, actions, proj_list, overview, main_window): # Make sure that this action is valid assert 'Draw Save' in actions # Make sure the first item is selected proj_list.setCurrentRow(0) # Get the name of the selected hcube item item = proj_list.item(0) hcube_name = item.text() hcube = overview.hcubes[overview.names.index(hcube_name)] # Turn the option for smoothing on set_box_value(main_window.options.option_entries['smooth'].box, True) main_window.options.save_options() # Trigger the action actions['Draw Save'].trigger() # Set the options back to default main_window.options.reset_options() # Check if a new figure has been saved figpath = overview.call_proj_attr('get_fig_path', hcube)[1] assert path.exists(figpath) # Close the figure that was just drawn overview.close_projection_figures([item])
def test_create_draw_action(self, actions, proj_list, overview, main_window): # Make sure that this action is valid assert 'Create Draw' in actions # Make sure the first item is selected proj_list.setCurrentRow(0) # Get the name of the selected hcube item item = proj_list.item(0) hcube_name = item.text() # Use a threaded progress dialog for this box = main_window.options.option_entries['use_progress_dialog'].box set_box_value(box, True) main_window.options.save_options() # Trigger the show action actions['Create Draw'].trigger() # Do not use a threaded progress dialog anymore main_window.options.reset_options() # Check if its corresponding entry exists assert hcube_name in overview.proj_fig_registry # Check the entry itself proj_fig_entry = overview.proj_fig_registry[hcube_name] assert isinstance(proj_fig_entry[0], plt.Figure) assert isinstance(proj_fig_entry[1], QW.QMdiSubWindow) assert isinstance(proj_fig_entry[1].widget(), FigureCanvas)
def test_set_bad_cmap(self, monkeypatch, box): # Monkey patch the QMessagebox.warning function monkeypatch.setattr(QW.QMessageBox, 'warning', lambda *args: QW.QMessageBox.Ok) # Set the value of the box set_box_value(box, cm.get_cmap('jet'))
def test_connect_modified_signal(self, qtbot, box): # Create a checkbox checkbox = QW.QCheckBox() qtbot.addWidget(checkbox) # Connect signals box.connect_box(checkbox) # Check if modifying checkbox automatically triggers modified signal with qtbot.waitSignal(box.modified): set_box_value(checkbox, True)
def test_invalid_BaseBox(self, qtbot): # Create a CustomBox box = CustomBox() qtbot.addWidget(box) # Try to set the value of this box with pytest.raises(NotImplementedError): set_box_value(box, 150) # Try to get the value of this box with pytest.raises(NotImplementedError): get_box_value(box)
def test_bool(self, qtbot, box): # Request a bool box set_box_value(box.type_box, 'bool') # Check that the value box is now a check box assert isinstance(box.value_box, QW.QCheckBox) # Try to toggle the value box with qtbot.waitSignal(box.modified): box.value_box.click() # Check that the value is now True assert get_box_value(box)
def test_button(self, qtbot): # Create a button box = QW.QCheckBox() qtbot.addWidget(box) # Obtain modified signal of this box signal = get_modified_box_signal(box) # Set the value of this box with qtbot.waitSignal(signal): set_box_value(box, True) # Check the value of this box assert get_box_value(box)
def test_spinbox(self, qtbot): # Create a spinbox box = QW.QSpinBox() qtbot.addWidget(box) # Obtain modified signal of this box signal = get_modified_box_signal(box) # Set the value of this box with qtbot.waitSignal(signal): set_box_value(box, 50) # Check the value of this box assert (get_box_value(box) == 50)
def test_lineedit(self, qtbot): # Create a lineedit box = QW.QLineEdit() qtbot.addWidget(box) # Obtain modified signal of this box signal = get_modified_box_signal(box) # Set the value of this box with qtbot.waitSignal(signal): set_box_value(box, "This is a test!") # Check the value of this box assert (get_box_value(box) == "This is a test!")
def test_valid_BaseBox(self, qtbot): # Create a ProperBox box = ProperBox() qtbot.addWidget(box) # Obtain modified signal of this box signal = get_modified_box_signal(box) # Set the value of this box with qtbot.waitSignal(signal): set_box_value(box, 150) # Check the value of this box assert (get_box_value(box) == 150)
def test_BaseBox_parent(self, qtbot, box): # Create a layout for the CustomBox layout = QW.QHBoxLayout(box) # Create a checkbox child checkbox = QW.QCheckBox() layout.addWidget(checkbox) # Check if modifying checkbox automatically triggers modified signal with qtbot.waitSignal(box.modified): set_box_value(checkbox, True) # Check if attempting to set the signal again ignores it box.connect_box(checkbox)
def test_combobox(self, qtbot): # Create a combobox box = QW.QComboBox() box.addItems(['a', 'b', 'c']) qtbot.addWidget(box) # Obtain modified signal of this box signal = get_modified_box_signal(box) # Set the value of this box with qtbot.waitSignal(signal): set_box_value(box, 'b') # Check the value of this box assert (get_box_value(box) == 'b')
def test_set_entry_duplicate(self, qtbot, option_entries, kwargs_dicts): # Obtain the fig_kwargs page and the index of the last row page = option_entries['fig_kwargs'].box row = page.kwargs_grid.count() // 3 - 2 # Obtain the kwargs_box kwargs_box = page.kwargs_grid.itemAtPosition(row, 1).widget() # Set the value of this kwargs_box qtbot.keyClicks(kwargs_box, 'a_test') # Set the field box to a float of 1.5 field_box = page.kwargs_grid.itemAtPosition(row, 2).widget() set_box_value(field_box.type_box, 'float') set_box_value(field_box.value_box, 1.5)
def test_invalid_box(self, qtbot): # Create a label box = QW.QLabel() qtbot.addWidget(box) # Try to obtain the modified signal of this box with pytest.raises(NotImplementedError): get_modified_box_signal(box) # Try to set the value of this box with pytest.raises(NotImplementedError): set_box_value(box, 'test') # Try to get the value of this box with pytest.raises(NotImplementedError): get_box_value(box)
def test_float(self, qtbot, box): # Request a float box set_box_value(box.type_box, 'float') # Check that the value box is now a double spinbox assert isinstance(box.value_box, QW.QDoubleSpinBox) # Remove the current value in the box qtbot.keyClick(box.value_box, QC.Qt.Key_A, QC.Qt.ControlModifier) qtbot.keyClick(box.value_box, QC.Qt.Key_Delete) # Try to set the value of the spinbox with qtbot.waitSignal(box.modified): qtbot.keyClicks(box.value_box, '13.13') # Check that the value is now 13.13 assert (get_box_value(box) == 13.13)
def test_int(self, qtbot, box): # Request an integer box set_box_value(box.type_box, 'int') # Check that the value box is now a spinbox assert isinstance(box.value_box, QW.QSpinBox) # Remove the current value in the box qtbot.keyClick(box.value_box, QC.Qt.Key_A, QC.Qt.ControlModifier) qtbot.keyClick(box.value_box, QC.Qt.Key_Delete) # Try to set the value of the spinbox with qtbot.waitSignal(box.modified): qtbot.keyClicks(box.value_box, '100') # Check that the value is now 100 assert (get_box_value(box) == 100)
def test_set_entry_empty(self, option_entries, kwargs_dicts): # Obtain the fig_kwargs page page = option_entries['fig_kwargs'].box # Check which row should have 'a_test' row = option_entries['fig_kwargs'].value.keys().index('a_test') + 1 # Check that this row indeed has 'a_test' kwargs_box = page.kwargs_grid.itemAtPosition(row, 1).widget() assert (get_box_value(kwargs_box) == 'a_test') # Set the kwargs_box to empty set_box_value(kwargs_box, '') # Check that the associated field_box is now an empty label field_box = page.kwargs_grid.itemAtPosition(row, 2).widget() assert isinstance(field_box, QW.QLabel) assert (field_box.text() == '')
def test_str(self, qtbot, box): # Request a string box set_box_value(box.type_box, 'str') # Check that the value box is now a line edit assert isinstance(box.value_box, QW.QLineEdit) # Remove the current value in the box qtbot.keyClick(box.value_box, QC.Qt.Key_A, QC.Qt.ControlModifier) qtbot.keyClick(box.value_box, QC.Qt.Key_Delete) # Try to set the value of the line edit text = "This iS a Te$t! ;)" with qtbot.waitSignal(box.modified): qtbot.keyClicks(box.value_box, text) # Check that the value is correct assert (get_box_value(box) == text)
def test_set_standard_entry(self, page_name, entry_type, field_type, field_value, option_entries, kwargs_dicts): # Obtain the proper page page = option_entries[page_name].box # Add a new entry to this page page.add_but.click() # Set the kwargs_box to entry_type row = page.kwargs_grid.count() // 3 - 1 kwargs_box = page.kwargs_grid.itemAtPosition(row, 1).widget() set_box_value(kwargs_box, entry_type) # Check that the field box is an instance of given field_type field_box = page.kwargs_grid.itemAtPosition(row, 2).widget() assert isinstance(field_box, field_type) # Set the value of this box set_box_value(field_box, field_value)
def test_set_entry_banned(self, option_entries, kwargs_dicts): # Obtain the impl_kwargs_2D page page = option_entries['impl_kwargs_2D'].box # Add a new entry to this page page.add_but.click() # Obtain a banned entry assert len(page.banned_entries) entry_type = page.banned_entries[0] # Set the corresponding kwargs_box to this entry_type row = page.kwargs_grid.count() // 3 - 1 kwargs_box = page.kwargs_grid.itemAtPosition(row, 1).widget() set_box_value(kwargs_box, entry_type) # Check that the field_box is now a non-empty label field_box = page.kwargs_grid.itemAtPosition(row, 2).widget() assert isinstance(field_box, QW.QLabel) assert (field_box.text() != '')
def test_set_box_value(self, box): # Set the box value to a bool and check set_box_value(box, True) assert (get_box_value(box.type_box) == 'bool') # Set the box value to a float and check set_box_value(box, 13.13) assert (get_box_value(box.type_box) == 'float') # Set the box value to an integer and check set_box_value(box, 100) assert (get_box_value(box.type_box) == 'int') # Set the box value to a string and check set_box_value(box, "More Te3t1ng! -.-") assert (get_box_value(box.type_box) == 'str')
def test_set_entry_default(self, qtbot, option_entries, kwargs_dicts): # Obtain the fig_kwargs page and the index of the second-last row page = option_entries['fig_kwargs'].box row = page.kwargs_grid.count() // 3 - 3 # Obtain the kwargs_box kwargs_box = page.kwargs_grid.itemAtPosition(row, 1).widget() # Make sure that 'a_test' is not a default entry type assert 'a_test' not in page.std_entries # Set the value of this kwargs_box qtbot.keyClicks(kwargs_box, 'a_test') # Check that the current value of the kwargs_box is 'a_test' assert (get_box_value(kwargs_box) == 'a_test') # Check that the field_box is an instance of the DefaultBox field_box = page.kwargs_grid.itemAtPosition(row, 2).widget() assert isinstance(field_box, DefaultBox) # Set the field_box to bool and False set_box_value(field_box.type_box, 'bool') set_box_value(field_box.value_box, False)
def test_set_sizes(self, box): # Set the value of the figsize box set_box_value(box, (13.13, 42.10)) # Check that this is now the current value of the box assert (get_box_value(box) == (13.13, 42.10))