diff --git a/adafruit_progressbar/__init__.py b/adafruit_progressbar/__init__.py index fae1577..d5466d0 100755 --- a/adafruit_progressbar/__init__.py +++ b/adafruit_progressbar/__init__.py @@ -76,29 +76,30 @@ def __init__( value_range: Union[Tuple[int, int], Tuple[float, float]] = (0, 100), ) -> None: - assert ( - value_range[0] < value_range[1] - ), "The minimum value must be less than the maximum value" + if value_range[0] >= value_range[1]: + raise ValueError("The minimum value must be less than the maximum value") - assert ( - size[0] > 0 and size[1] > 0 - ), "The width and the height must be greater than zero" + if size[0] <= 0 or size[1] <= 0: + raise ValueError("The width and the height must be greater than zero") - assert ( - value_range[0] <= value <= value_range[1] - ), "The starting value must be within the range of minimum to maximum" + if not value_range[0] <= value <= value_range[1]: + raise ValueError( + "The starting value must be within the range of minimum to maximum" + ) _edge_size = 2 * margin_size + 2 * border_thickness - assert _edge_size < size[0], ( - "The size of the borders and margins combined must be " - "less than the width of the widget" - ) + if _edge_size >= size[0]: + raise ValueError( + "The size of the borders and margins combined must be " + "less than the width of the widget" + ) - assert _edge_size < size[1], ( - "The size of the borders and margins combined must be " - "less than the height of the widget" - ) + if _edge_size >= size[1]: + raise ValueError( + "The size of the borders and margins combined must be " + "less than the height of the widget" + ) self._progress = 0.0 self._widget_size = size @@ -201,9 +202,8 @@ def border_color(self, color: Union[int, Tuple[int, int, int]]) -> None: :rtype: None """ - assert ( - isinstance(color, int) or color is None - ), "A color must be represented by a integer value" + if not (isinstance(color, int) or color is None): + raise TypeError("A color must be represented by a integer value") self._border_color = color @@ -285,13 +285,13 @@ def value(self, value: Union[int, float]) -> None: :rtype: None """ - assert isinstance( - value, (int, float) - ), "The value to set must be either an integer or a float" + if not isinstance(value, (int, float)): + raise TypeError("The value to set must be either an integer or a float") - assert ( - self.minimum <= value <= self.maximum - ), f"The value must be between minimum ({self.minimum}) and maximum ({self.maximum})" + if not self.minimum <= value <= self.maximum: + raise ValueError( + f"The value must be between minimum ({self.minimum}) and maximum ({self.maximum})" + ) # Save off the previous value, so we can pass it in the # call to "Render" @@ -332,9 +332,11 @@ def progress(self, value: float) -> None: :rtype: None """ - assert [isinstance(value, (float, int)), "'progress' must be an int or a float"] + if not isinstance(value, (float, int)): + raise TypeError("'progress' must be an int or a float") - assert 0.0 <= value <= 100.0, "'progress' must be between 0 and 100" + if not 0.0 <= value <= 100.0: + raise ValueError("'progress' must be between 0 and 100") self.value = (self.minimum + (self.maximum - self.minimum)) * (value * 0.01) @@ -449,19 +451,22 @@ def margin_size(self, value: int) -> None: :rtype: None """ - assert isinstance(value, int), "The margin size must be an integer" + if not isinstance(value, int): + raise TypeError("The margin size must be an integer") margin_spacing = (2 * value) + (2 * self._border_thickness) - assert margin_spacing < self.widget_width, ( - "The size of the borders and margins combined can total the same or more" - "than the widget's width." - ) - - assert margin_spacing < self.widget_height, ( - "The size of the borders and margins combined can total the same or more" - "than the widget's height." - ) + if margin_spacing >= self.widget_width: + raise ValueError( + "The size of the borders and margins combined can total the same or more" + "than the widget's width." + ) + + if margin_spacing >= self.widget_height: + raise ValueError( + "The size of the borders and margins combined can total the same or more" + "than the widget's height." + ) self._margin_size = value self._set_progress(self._progress) # For a render pass diff --git a/adafruit_progressbar/progressbar.py b/adafruit_progressbar/progressbar.py index 5f1eeb3..ab1069d 100755 --- a/adafruit_progressbar/progressbar.py +++ b/adafruit_progressbar/progressbar.py @@ -65,7 +65,8 @@ def __init__( # This needs to remain for backward compatibility, the default ProgressBar class # should only be able to handle values of type "float" - assert isinstance(progress, float), "Progress must be a floating point value." + if not isinstance(progress, float): + raise TypeError("Progress must be a floating point value.") super().__init__( (x, y),