Skip to content

Commit

Permalink
Fix replace_sublist when empty sublist is passed
Browse files Browse the repository at this point in the history
  • Loading branch information
Anaaa committed Aug 27, 2024
1 parent 6e08cbe commit d7a3342
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/listwiz/replace.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ def replace_sublist(l, sublist, replacement):
"""
len_sublist = len(sublist)
if len_sublist == 0:
raise ValueError("The sublist cannot be empty. Please provide at least one element.")
result = l[:] # copy the input list

i = 0
Expand Down
4 changes: 2 additions & 2 deletions tests/test_replace.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ def test_replace_sublist_overlap():


def test_replace_sublist_empty():
# This is a stub for testing the bug with empty sublists.
pass
with pytest.raises(ValueError, match="The sublist cannot be empty. Please provide at least one element."):
lwr.replace_sublist([1, 2, 3], [], [5, 6])

0 comments on commit d7a3342

Please sign in to comment.