def test_build_form_minimum_needs(self): """Test that we can build a form by passing it params. """ dialog = FunctionOptionsDialog() # Define threshold threshold = InputListParameter() threshold.name = 'Thresholds [m]' threshold.is_required = True threshold.element_type = float threshold.expected_type = list threshold.ordering = InputListParameter.AscendingOrder threshold.minimum_item_count = 1 threshold.maximum_item_count = 3 threshold.value = [1.0] # default value parameters = { 'thresholds': threshold, 'postprocessors': OrderedDict([ ('Gender', default_gender_postprocessor()), ('Age', age_postprocessor()), ('MinimumNeeds', minimum_needs_selector()), ]) } dialog.build_form(parameters) assert dialog.tabWidget.count() == 2 children = dialog.tabWidget.findChildren(QLineEdit) assert len(children) == 4
def test_build_form(self): """Test that we can build a form by passing params. """ dialog = FunctionOptionsDialog() # Define rice for minimum needs rice = ResourceParameter() rice.value = 2.8 rice.frequency = 'weekly' rice.minimum_allowed_value = 1.4 rice.maximum_allowed_value = 5.6 rice.name = 'Rice' rice.unit.abbreviation = 'kg' rice.unit.name = 'kilogram' rice.unit.plural = 'kilograms' # Define threshold threshold = InputListParameter() threshold.name = 'Thresholds [m]' threshold.is_required = True threshold.element_type = float threshold.expected_type = list threshold.ordering = InputListParameter.AscendingOrder threshold.minimum_item_count = 1 threshold.maximum_item_count = 3 threshold.value = [1.0] # default value parameter = { 'thresholds': threshold, 'postprocessors': OrderedDict([ ('Gender', default_gender_postprocessor()), ('Age', age_postprocessor()), ('MinimumNeeds', minimum_needs_selector()), ]), 'minimum needs': [rice] } dialog.build_form(parameter) message = 'There should be %s tabwidget but got %s' % ( 3, dialog.tabWidget.count()) self.assertEqual(dialog.tabWidget.count(), 3, message) children = dialog.tabWidget.findChildren(QLineEdit) message = 'There should be %s QLineEdit but got %s' % (5, len(children)) self.assertEqual(len(children), 5, message)
def distance(): field = InputListParameter() field.name = "Distances [km]" field.is_required = True field.minimum_item_count = 1 # Rizky: no reason for the number below. It can be any values to describe # maximum item count. Feel free to change it when necessary. # PS: it was my birthdate field.maximum_item_count = 19 field.element_type = float field.ordering = InputListParameter.AscendingOrder field.value = [3.0, 5.0, 10.0] field.help_text = tr("The list of radii for volcano buffer.") field.description = tr("This list contains radii of volcano buffer in increasing order.") return field
def test_build_form(self): """Test that we can build a form by passing params. """ dialog = FunctionOptionsDialog() # Define rice for minimum needs rice = ResourceParameter() rice.value = 2.8 rice.frequency = 'weekly' rice.minimum_allowed_value = 1.4 rice.maximum_allowed_value = 5.6 rice.name = 'Rice' rice.unit.abbreviation = 'kg' rice.unit.name = 'kilogram' rice.unit.plural = 'kilograms' # Define threshold threshold = InputListParameter() threshold.name = 'Thresholds [m]' threshold.is_required = True threshold.element_type = float threshold.expected_type = list threshold.ordering = InputListParameter.AscendingOrder threshold.minimum_item_count = 1 threshold.maximum_item_count = 3 threshold.value = [1.0] # default value parameter = { 'thresholds': threshold, 'postprocessors': OrderedDict([ ('Gender', default_gender_postprocessor()), ('Age', age_postprocessor()), ('MinimumNeeds', minimum_needs_selector()), ]), 'minimum needs': [rice] } dialog.build_form(parameter) message = 'There should be %s tabwidget but got %s' % ( 3, dialog.tabWidget.count()) self.assertEqual(dialog.tabWidget.count(), 3, message) children = dialog.tabWidget.findChildren(QLineEdit) message = 'There should be %s QLineEdit but got %s' % ( 5, len(children)) self.assertEqual(len(children), 5, message)
def threshold(): """Generator for the default threshold parameter. :return: List of InputListParameter :rtype: list[InputListParameter] """ field = InputListParameter() field.name = 'Thresholds [m]' field.is_required = True field.element_type = float field.expected_type = list field.ordering = InputListParameter.AscendingOrder field.minimum_item_count = 1 # Rizky: no reason for the number below. It can be any values to describe # maximum item count. Feel free to change it when necessary. # PS: it was my birthdate field.maximum_item_count = 19 field.value = [1.0] # default value field.help_text = tr( 'Thresholds value to categorize inundated area.') field.description = tr( 'Up to three thresholds (in meters) can be set in an increasing ' 'order. The impact function will report the number of people per ' 'threshold you define here. Specify the upper bound for each ' 'threshold. The lower bound of the first threshold shall be zero. ' 'People in water depths above the maximum threshold will be ' 'classified as needing evacuation.') return field
def test_build_widget(self): dialog = FunctionOptionsDialog() # Define threshold threshold = InputListParameter() threshold.name = 'Thresholds [m]' threshold.is_required = True threshold.element_type = float threshold.expected_type = list threshold.ordering = InputListParameter.AscendingOrder threshold.minimum_item_count = 1 threshold.maximum_item_count = 3 threshold.value = [2.3] # default value value = dialog.build_widget(dialog.configLayout, 'foo', threshold) widget = dialog.findChild(QLineEdit) add_button = dialog.findChildren(QPushButton)[0] remove_button = dialog.findChildren(QPushButton)[1] list_widget = dialog.findChild(QListWidget) # initial value must be same with default expected_value = [2.3] real_value = value().value message = 'Expected %s but got %s' % (expected_value, real_value) self.assertEqual(expected_value, real_value, message) # change to 5.9 # select 2.3 list item self.click_list_widget_item(list_widget, '2.3') # remove 2.3 list item remove_button.click() # typing 5.9 widget.setText('5.9') # add it to list add_button.click() expected_value = [5.9] real_value = value().value message = 'Expected %s but got %s' % (expected_value, real_value) self.assertEqual(expected_value, real_value, message) # add 70 widget.setText('70') # add it to list add_button.click() expected_value = [5.9, 70] real_value = value().value message = 'Expected %s but got %s' % (expected_value, real_value) self.assertEqual(expected_value, real_value, message) widget.setText('bar') self.assertEqual('bar', widget.text()) def trigger_error(error): message = 'Expected %s type but got %s' % ( ValueError, type(error)) self.assertIsInstance(error, ValueError, message) threshold.add_row_error_handler = trigger_error add_button.click() bool_param = BooleanParameter() bool_param.name = 'boolean checkbox' bool_param.value = True dialog = FunctionOptionsDialog() value = dialog.build_widget(dialog.configLayout, 'foo', bool_param) widget = dialog.findChild(QCheckBox) # initial value must be same with default expected_value = True real_value = value().value message = 'Expected %s but got %s' % (expected_value, real_value) self.assertEqual(expected_value, real_value, message) widget.setChecked(False) expected_value = False real_value = value().value message = 'Expected %s but got %s' % (expected_value, real_value) self.assertEqual(expected_value, real_value, message) dict_param = DictParameter() dict_param.name = 'Dictionary tree' dict_param.element_type = int dict_param.value = {'a': 1, 'b': 2} dialog = FunctionOptionsDialog() value = dialog.build_widget(dialog.configLayout, 'foo', dict_param) widget = dialog.findChild(QTreeWidget) # initial value must be same with default expected_value = {'a': 1, 'b': 2} real_value = value().value message = 'Expected %s but got %s' % (expected_value, real_value) self.assertEqual(expected_value, real_value, message) expected_value = {'a': 2, 'b': 1} # get tree items tree_items = widget.invisibleRootItem() # set the input tree_items.child(0).setText(1, str(2)) tree_items.child(1).setText(1, str(1)) real_value = value().value message = 'Expected %s but got %s' % (expected_value, real_value) self.assertEqual(expected_value, real_value, message)
def threshold(): """Generator for the default threshold parameter. :return: List of InputListParameter :rtype: list[InputListParameter] """ field = InputListParameter() field.name = 'Thresholds [m]' field.is_required = True field.element_type = float field.expected_type = list field.ordering = InputListParameter.AscendingOrder field.minimum_item_count = 1 # Rizky: no reason for the number below. It can be any values to describe # maximum item count. Feel free to change it when necessary. # PS: it was my birthdate field.maximum_item_count = 19 field.value = [1.0] # default value field.help_text = tr('Thresholds value to categorize inundated area.') field.description = tr( 'Up to three thresholds (in meters) can be set in an increasing ' 'order. The impact function will report the number of people per ' 'threshold you define here. Specify the upper bound for each ' 'threshold. The lower bound of the first threshold shall be zero. ' 'People in water depths above the maximum threshold will be ' 'classified as needing evacuation.') return field
def distance(): field = InputListParameter() field.name = 'Distances [km]' field.is_required = True field.minimum_item_count = 1 # Ismail: I choose 8 since in the IF, we only provide 8 colors in the # style. More than 8 item, will create IndexError field.maximum_item_count = 8 field.element_type = float field.ordering = InputListParameter.AscendingOrder field.value = [3.0, 5.0, 10.0] field.help_text = tr('The list of radii for volcano buffer.') field.description = tr( 'This list contains radii of volcano buffer in increasing order.') return field
def test_build_widget(self): dialog = FunctionOptionsDialog() # Define threshold threshold = InputListParameter() threshold.name = 'Thresholds [m]' threshold.is_required = True threshold.element_type = float threshold.expected_type = list threshold.ordering = InputListParameter.AscendingOrder threshold.minimum_item_count = 1 threshold.maximum_item_count = 3 threshold.value = [2.3] # default value value = dialog.build_widget(dialog.configLayout, 'foo', threshold) widget = dialog.findChild(QLineEdit) add_button = dialog.findChildren(QPushButton)[0] remove_button = dialog.findChildren(QPushButton)[1] list_widget = dialog.findChild(QListWidget) # initial value must be same with default expected_value = [2.3] real_value = value().value message = 'Expected %s but got %s' % (expected_value, real_value) self.assertEqual(expected_value, real_value, message) # change to 5.9 # select 2.3 list item self.click_list_widget_item(list_widget, '2.3') # remove 2.3 list item remove_button.click() # typing 5.9 widget.setText('5.9') # add it to list add_button.click() expected_value = [5.9] real_value = value().value message = 'Expected %s but got %s' % (expected_value, real_value) self.assertEqual(expected_value, real_value, message) # add 70 widget.setText('70') # add it to list add_button.click() expected_value = [5.9, 70] real_value = value().value message = 'Expected %s but got %s' % (expected_value, real_value) self.assertEqual(expected_value, real_value, message) widget.setText('bar') self.assertEqual('bar', widget.text()) def trigger_error(error): message = 'Expected %s type but got %s' % (ValueError, type(error)) self.assertIsInstance(error, ValueError, message) threshold.add_row_error_handler = trigger_error add_button.click() bool_param = BooleanParameter() bool_param.name = 'boolean checkbox' bool_param.value = True dialog = FunctionOptionsDialog() value = dialog.build_widget(dialog.configLayout, 'foo', bool_param) widget = dialog.findChild(QCheckBox) # initial value must be same with default expected_value = True real_value = value().value message = 'Expected %s but got %s' % (expected_value, real_value) self.assertEqual(expected_value, real_value, message) widget.setChecked(False) expected_value = False real_value = value().value message = 'Expected %s but got %s' % (expected_value, real_value) self.assertEqual(expected_value, real_value, message) dict_param = DictParameter() dict_param.name = 'Dictionary tree' dict_param.element_type = int dict_param.value = {'a': 1, 'b': 2} dialog = FunctionOptionsDialog() value = dialog.build_widget(dialog.configLayout, 'foo', dict_param) widget = dialog.findChild(QTreeWidget) # initial value must be same with default expected_value = {'a': 1, 'b': 2} real_value = value().value message = 'Expected %s but got %s' % (expected_value, real_value) self.assertEqual(expected_value, real_value, message) expected_value = {'a': 2, 'b': 1} # get tree items tree_items = widget.invisibleRootItem() # set the input tree_items.child(0).setText(1, str(2)) tree_items.child(1).setText(1, str(1)) real_value = value().value message = 'Expected %s but got %s' % (expected_value, real_value) self.assertEqual(expected_value, real_value, message)
def distance(): field = InputListParameter() field.name = 'Distances [km]' field.is_required = True field.minimum_item_count = 1 # Rizky: no reason for the number below. It can be any values to describe # maximum item count. Feel free to change it when necessary. # PS: it was my birthdate field.maximum_item_count = 19 field.element_type = float field.ordering = InputListParameter.AscendingOrder field.value = [3.0, 5.0, 10.0] field.help_text = tr('The list of radii for volcano buffer.') field.description = tr( 'This list contains radii of volcano buffer in increasing order.') return field