def test_option_values(self, options, option_entries): # Test that the box value, default value and entry value are equal for key, entry in option_entries.items(): assert (key == entry.name) assert (get_box_value(entry.box) == entry.default) assert (entry.value == get_box_value(entry.box)) repr(entry)
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_change_option_value_discard(self, qtbot, option_entries): # Obtain the align entries align_col = option_entries['align_col'] align_row = option_entries['align_row'] # Toggle the alignment value qtbot.mouseClick(align_col.box if align_row.value else align_row.box, QC.Qt.LeftButton) # Check that the alignment was toggled assert get_box_value(align_col.box) is not align_col.value assert get_box_value(align_row.box) is not align_row.value
def test_reset_options(self, qtbot, options, option_entries): # Check that the save button is currently enabled assert options.save_but.isEnabled() # Reset the options qtbot.mouseClick(options.reset_but, QC.Qt.LeftButton) # Check that the save button is currently disabled assert not options.save_but.isEnabled() # Check that the values of all entries are equal to the defaults for entry in option_entries.values(): assert (get_box_value(entry.box) == entry.default) assert (entry.value == get_box_value(entry.box))
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_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_add_editable_entry(self, qtbot, option_entries, kwargs_dicts): # Obtain the fig_kwargs page page = option_entries['fig_kwargs'].box # Check that this page currently contains at least 1 row n_rows = page.kwargs_grid.count() // 3 assert n_rows # Click on the 'add' button of this page qtbot.mouseClick(page.add_but, QC.Qt.LeftButton) # Check that an extra row has been added assert (page.kwargs_grid.count() // 3 == n_rows + 1) n_rows += 1 # Obtain the kwargs box at the last row and validate it kwargs_box = page.kwargs_grid.itemAtPosition(n_rows - 1, 1).widget() assert isinstance(kwargs_box, QW.QComboBox) # Check that this kwargs_box currently has nothing selected assert (get_box_value(kwargs_box) == '') # Add three more entries page.add_but.click() page.add_but.click() page.add_but.click() # Remove the second-last entry again row = page.kwargs_grid.count() // 3 - 2 del_but = page.kwargs_grid.itemAtPosition(row, 0).widget() del_but.click()
def test_change_option_value_reset(self, option_entries): # Obtain the auto_tile entry auto_tile = option_entries['auto_tile'] # Toggle the value of the auto_tile box auto_tile.box.click() # Check that the checkbox has been toggled assert get_box_value(auto_tile.box) is not auto_tile.value
def test_save_kwargs_dicts2(self, options, option_entries): # Try to save the options options.save_but.click() # Check that the impl_kwargs_2D entry has not changed entry = option_entries['impl_kwargs_2D'] impl_kwargs_2D = get_box_value(entry.box) assert (impl_kwargs_2D == entry.default) assert (entry.value == impl_kwargs_2D)
def test_save_kwargs_dicts(self, options, option_entries): # Try to save the options options.save_but.click() # Check that the associated fig_kwargs entry has been updated entry = option_entries['fig_kwargs'] fig_kwargs = get_box_value(entry.box) assert (fig_kwargs['a_test'] == 1.5) assert (fig_kwargs != entry.default) assert (entry.value == fig_kwargs)
def test_set_height(self, qtbot, box): # Remove the current value in the box qtbot.keyClick(box.height_box, QC.Qt.Key_A, QC.Qt.ControlModifier) qtbot.keyClick(box.height_box, QC.Qt.Key_Delete) # Try to set the value of the spinbox with qtbot.waitSignal(box.modified): qtbot.keyClicks(box.height_box, '42.10') # Check that the value is now 42.10 assert (get_box_value(box.height_box) == 42.10)
def test_set_width(self, qtbot, box): # Remove the current value in the box qtbot.keyClick(box.width_box, QC.Qt.Key_A, QC.Qt.ControlModifier) qtbot.keyClick(box.width_box, QC.Qt.Key_Delete) # Try to set the value of the spinbox with qtbot.waitSignal(box.modified): qtbot.keyClicks(box.width_box, '13.13') # Check that the value is now 13.13 assert (get_box_value(box.width_box) == 13.13)
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_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_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_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_set_color(self, qtbot, box): # Generate random color color = hex(randint(256**3)).replace('0x', '') # Remove the current value in the box qtbot.keyClick(box.color_combobox, QC.Qt.Key_A, QC.Qt.ControlModifier) qtbot.keyClick(box.color_combobox, QC.Qt.Key_Delete) # Try setting the color with qtbot.waitSignal(box.modified): qtbot.keyClicks(box.color_combobox, color) # Check that this is now the color that is set assert (get_box_value(box) == "#%s" % (color))
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_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_get_invalid_color(self, qtbot, box): # Obtain what currently the default color is assert hasattr(box, 'default_color') def_color = str(box.default_color) # Remove the current value in the box qtbot.keyClick(box.color_combobox, QC.Qt.Key_A, QC.Qt.ControlModifier) qtbot.keyClick(box.color_combobox, QC.Qt.Key_Delete) # Try setting the color to something invalid with qtbot.waitSignal(box.modified): qtbot.keyClicks(box.color_combobox, "test") # Check if the colorbox now returns the default color assert (get_box_value(box) == def_color)
def test_save_options(self, qtbot, options, option_entries): # Check that the save button is currently enabled assert options.save_but.isEnabled() # Try to save the options qtbot.mouseClick(options.save_but, QC.Qt.LeftButton) # Check that the save button is currently disabled assert not options.save_but.isEnabled() # Check that the new value of proj_res is correct proj_res = option_entries['proj_res'] proj_res_val = get_box_value(proj_res.box) assert (proj_res_val == 105) assert (proj_res_val != proj_res.default) assert (proj_res.value == proj_res_val)
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_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_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_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_change_option_value_save(self, qtbot, options, option_entries): # Make sure that the options menu is still visible assert options.isVisible() # Make sure that the save button is currently disabled assert not options.save_but.isEnabled() # Obtain the projection resolution entry proj_res = option_entries['proj_res'] # Remove the value in the proj_res box qtbot.keyClick(proj_res.box, QC.Qt.Key_A, QC.Qt.ControlModifier) qtbot.keyClick(proj_res.box, QC.Qt.Key_Delete) # Set the current projection resolution to 105 qtbot.keyClicks(proj_res.box, '105') # Check that the value has been changed to 105 assert (get_box_value(proj_res.box) == 105)
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))
def test_discarded_options(self, option_entries): # Test that every box value is equal to its entry value for entry in option_entries.values(): assert (get_box_value(entry.box) == entry.value)