Skip to content

Commit

Permalink
Raise ValueError for incorrect arguments.
Browse files Browse the repository at this point in the history
This improves error reporting in that case.
  • Loading branch information
aaugustin committed Jan 20, 2024
1 parent 83e89c9 commit 1001d36
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/sequences/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ def get_next_value(
# Inner import because models cannot be imported before their application.
from .models import Sequence

if reset_value is not None:
assert initial_value < reset_value
if reset_value is not None and reset_value <= initial_value:
raise ValueError("reset_value must be greater than initial_value")

if using is None:
using = router.db_for_write(Sequence)
Expand Down Expand Up @@ -170,8 +170,8 @@ def __init__(
*,
using=None,
):
if reset_value is not None:
assert initial_value < reset_value
if reset_value is not None and reset_value <= initial_value:
raise ValueError("reset_value must be greater than initial_value")
self.sequence_name = sequence_name
self.initial_value = initial_value
self.reset_value = reset_value
Expand Down
4 changes: 2 additions & 2 deletions tests/test_sequences.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def test_functions_reset_value(self):
self.assertEqual(get_next_value("reference", 1, 3), 2)

def test_functions_reset_value_smaller_than_initial_value(self):
with self.assertRaises(AssertionError):
with self.assertRaises(ValueError):
get_next_value("error", initial_value=1, reset_value=1)

def test_class_defaults(self):
Expand Down Expand Up @@ -101,7 +101,7 @@ def test_class_reset_value(self):
self.assertEqual(reference_seq.get_next_value(), 2)

def test_class_reset_value_smaller_than_initial_value(self):
with self.assertRaises(AssertionError):
with self.assertRaises(ValueError):
Sequence("error", initial_value=1, reset_value=1)


Expand Down

0 comments on commit 1001d36

Please sign in to comment.