Skip to content

Commit

Permalink
generate_page_range: warn, not raise, if start==end, fix #1106
Browse files Browse the repository at this point in the history
  • Loading branch information
kba committed Sep 28, 2023
1 parent 39e755d commit 66f440a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion ocrd_utils/ocrd_utils/str.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import json
from .constants import REGEX_FILE_ID
from .deprecate import deprecation_warning
from warnings import warn

__all__ = [
'assert_file_grp_cardinality',
Expand Down Expand Up @@ -202,7 +203,7 @@ def generate_range(start, end):
except IndexError:
raise ValueError("Range '%s..%s': could not find numeric part" % (start, end))
if start_num == end_num:
raise ValueError("Range '%s..%s': evaluates to the same number")
warn("Range '%s..%s': evaluates to the same number")
for i in range(int(start_num), int(end_num) + 1):
ret.append(start.replace(start_num, str(i).zfill(len(start_num))))
return ret
4 changes: 2 additions & 2 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from PIL import Image

from tests.base import TestCase, main, assets, create_ocrd_file
from pytest import raises
from pytest import raises, warns
from ocrd_utils import (
abspath,

Expand Down Expand Up @@ -317,7 +317,7 @@ def test_generate_range(self):
assert generate_range('PHYS_0001', 'PHYS_0005') == ['PHYS_0001', 'PHYS_0002', 'PHYS_0003', 'PHYS_0004', 'PHYS_0005']
with self.assertRaisesRegex(ValueError, 'could not find numeric part'):
generate_range('NONUMBER', 'ALSO_NONUMBER')
with self.assertRaisesRegex(ValueError, 'evaluates to the same number'):
with warns(UserWarning, match='same number'):
generate_range('PHYS_0001_123', 'PHYS_0010_123')

def test_safe_filename(self):
Expand Down

0 comments on commit 66f440a

Please sign in to comment.