def test_background_gradient_type_from_string(self): """ Test the from_string method of :class:`BackgroundGradientType` """ # GIVEN: The BackgroundGradientType strings background_gradient_horizontal = 'horizontal' background_gradient_vertical = 'vertical' background_gradient_circular = 'circular' background_gradient_left_top = 'leftTop' background_gradient_left_bottom = 'leftBottom' # WHEN: Calling BackgroundGradientType.from_string # THEN: The enum equivalents should be returned assert BackgroundGradientType.from_string( background_gradient_horizontal ) == BackgroundGradientType.Horizontal assert BackgroundGradientType.from_string( background_gradient_vertical) == BackgroundGradientType.Vertical assert BackgroundGradientType.from_string( background_gradient_circular) == BackgroundGradientType.Circular assert BackgroundGradientType.from_string( background_gradient_left_top) == BackgroundGradientType.LeftTop assert BackgroundGradientType.from_string( background_gradient_left_bottom ) == BackgroundGradientType.LeftBottom
def gradient_type(self, value): if isinstance(value, str): self.gradient_combo_box.setCurrentIndex( BackgroundGradientType.from_string(value)) elif isinstance(value, int): self.gradient_combo_box.setCurrentIndex(value) else: raise TypeError('gradient_type must either be a string or an int')