feat: scan.resolve_index with end-of-batch error
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -28,3 +28,11 @@ def list_images(folder, depth=0):
|
|||||||
results.append(str(cur / name))
|
results.append(str(cur / name))
|
||||||
results.sort(key=lambda p: natural_key(os.path.relpath(p, root)))
|
results.sort(key=lambda p: natural_key(os.path.relpath(p, root)))
|
||||||
return results
|
return results
|
||||||
|
|
||||||
|
|
||||||
|
def resolve_index(count, index):
|
||||||
|
if count == 0:
|
||||||
|
raise FileNotFoundError("No images found in folder")
|
||||||
|
if index < 0 or index >= count:
|
||||||
|
raise IndexError(f"index {index} out of range: {count} images")
|
||||||
|
return index
|
||||||
|
|||||||
@@ -37,3 +37,19 @@ def test_list_images_bad_path_raises(tmp_path):
|
|||||||
import pytest
|
import pytest
|
||||||
with pytest.raises(NotADirectoryError):
|
with pytest.raises(NotADirectoryError):
|
||||||
scan.list_images(str(tmp_path / "nope"))
|
scan.list_images(str(tmp_path / "nope"))
|
||||||
|
|
||||||
|
def test_resolve_index_ok():
|
||||||
|
assert scan.resolve_index(5, 0) == 0
|
||||||
|
assert scan.resolve_index(5, 4) == 4
|
||||||
|
|
||||||
|
def test_resolve_index_out_of_range_raises():
|
||||||
|
import pytest
|
||||||
|
with pytest.raises(IndexError):
|
||||||
|
scan.resolve_index(5, 5)
|
||||||
|
with pytest.raises(IndexError):
|
||||||
|
scan.resolve_index(5, -1)
|
||||||
|
|
||||||
|
def test_resolve_index_empty_raises():
|
||||||
|
import pytest
|
||||||
|
with pytest.raises(FileNotFoundError):
|
||||||
|
scan.resolve_index(0, 0)
|
||||||
|
|||||||
Reference in New Issue
Block a user