Skip to content

Commit

Permalink
formatting and linting
Browse files Browse the repository at this point in the history
  • Loading branch information
VascoSch92 committed Mar 31, 2024
1 parent 5783164 commit 8883eb2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
5 changes: 4 additions & 1 deletion sequence/core/utils/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@

class PositiveIntegerError(Exception):
"""Error raised when given a negative integer, but a positive integer was expected."""

def __init__(self, integer: int) -> None:
super().__init__(f"Expected a positive integer, but got {integer}!")
self.integer = integer


class StrictlyPositiveIntegerError(Exception):
"""Error raised when given a negative integer, but a strictly positive integer was expected."""

def __init__(self, integer: int) -> None:
super().__init__(f"Expected a strictly positive integer, but got {integer}!")
self.integer = integer


class InfiniteSequenceError(Exception):
"""Error raised when asking for finite sequence property to an infinite sequence."""

def __init__(self, sequence_name: str) -> None:
super().__init__(f"The length function is not implemented for {sequence_name}, as the sequence is infinite!")
self.sequence_name = sequence_name


class NotPeriodicSequenceError(Exception):
"""Error raised when asking period to a non-periodic sequence."""

def __init__(self, sequence_name: str) -> None:
super().__init__(f"The {sequence_name} is not periodic!")
self.sequence_name = sequence_name
22 changes: 11 additions & 11 deletions tests/tests_core/test_validation.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import pytest

from sequence.core.utils.exceptions import (
PositiveIntegerError,
StrictlyPositiveIntegerError,
)
from sequence.core.utils.validation import (
validate_integer,
validate_as_list_input,
validate_positive_integer,
validate_strictly_positive_integer,
validate_given_length_integer_tuple,
validate_as_list_input,
)
from sequence.core.utils.exceptions import (
PositiveIntegerError,
StrictlyPositiveIntegerError,
)


Expand All @@ -18,7 +19,7 @@ def test_validate_integer(integer) -> None:
raise ValueError(f"Expected: {integer}. Got {validate_integer(integer=integer)}")


@pytest.mark.parametrize("integer", [ 23.23, "asd", [], {'asd': 23.23}, {123}])
@pytest.mark.parametrize("integer", [23.23, "asd", [], {"asd": 23.23}, {123}])
def test_error_validate_integer(integer) -> None:
with pytest.raises(ValueError):
_ = validate_integer(integer=integer)
Expand All @@ -36,7 +37,7 @@ def test_validate_positive_integer(integer) -> None:
(23.23, ValueError),
("asd", ValueError),
(-12, PositiveIntegerError),
]
],
)
def test_error_validate_positive_integer(integer, error) -> None:
with pytest.raises(error):
Expand All @@ -56,9 +57,9 @@ def test_validate_strictly_positive_integer(integer) -> None:
("asd", ValueError),
(-12, StrictlyPositiveIntegerError),
(0, StrictlyPositiveIntegerError),
]
],
)
def test_error_validate_positive_integer(integer, error) -> None:
def test_error_validate_strictly_positive_integer(integer, error) -> None:
with pytest.raises(error):
_ = validate_strictly_positive_integer(integer=integer)

Expand All @@ -75,8 +76,7 @@ def test_error_validate_given_length_integer_tuple(tuple, length) -> None:


@pytest.mark.parametrize(
"input_values, expected_values",
[((2, 1, 3), (2, 1, 3)), ((2, None, 3), (2, 0, 3)), ((2, 1, None), (2, 1, 1))]
"input_values, expected_values", [((2, 1, 3), (2, 1, 3)), ((2, None, 3), (2, 0, 3)), ((2, 1, None), (2, 1, 1))]
)
def test_validate_as_list_input(input_values, expected_values) -> None:
output = validate_as_list_input(
Expand Down

0 comments on commit 8883eb2

Please sign in to comment.