Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions imgix/validators.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from .errors import WidthRangeError, WidthToleranceError
from .constants import IMAGE_MAX_WIDTH as MAX_WIDTH
from .constants import IMAGE_ZERO_WIDTH as ZERO_WIDTH
from .constants import SRCSET_MIN_WIDTH_TOLERANCE as ONE_PERCENT

Expand Down Expand Up @@ -33,7 +32,8 @@ def validate_min_width(value):
if not isinstance(value, (float, int)):
raise WidthRangeError(invalid_width_type_error)

invalid_min_error = '`start` width must be greater than zero'
invalid_min_error = \
'`start` width must be greater than, or equal to, zero'
if not value > ZERO_WIDTH:
raise WidthRangeError(invalid_min_error)

Expand Down Expand Up @@ -70,9 +70,9 @@ def validate_max_width(value):
raise WidthRangeError(invalid_width_error)

invalid_max_error = \
'`stop` width value must be > 0 && <= `constants.IMAGE_MAX_WIDTH`'
'`stop` width value must be greater than, or equal to, zero'

if not ZERO_WIDTH < value <= MAX_WIDTH:
if not ZERO_WIDTH <= value:
raise WidthRangeError(invalid_max_error)


Expand Down
10 changes: 4 additions & 6 deletions tests/test_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@

from imgix.errors import WidthRangeError, WidthToleranceError

LESS_THAN_ZERO = IMAGE_ZERO_WIDTH - 1

class TestValidators(unittest.TestCase):

class TestValidators(unittest.TestCase):
def test_validate_min_raises(self):
with self.assertRaises(WidthRangeError):
validate_min_width(-1)
Expand All @@ -19,7 +20,7 @@ def test_validate_min_raises(self):
validate_min_width("1")

with self.assertRaises(WidthRangeError):
validate_min_width(IMAGE_ZERO_WIDTH)
validate_min_width(LESS_THAN_ZERO)

with self.assertRaises(WidthRangeError):
validate_min_width([-1])
Expand All @@ -32,14 +33,11 @@ def test_validate_max_raises(self):
validate_max_width("1")

with self.assertRaises(WidthRangeError):
validate_max_width(IMAGE_ZERO_WIDTH)
validate_max_width(LESS_THAN_ZERO)

with self.assertRaises(WidthRangeError):
validate_max_width([-1])

with self.assertRaises(WidthRangeError):
validate_max_width(IMAGE_MAX_WIDTH+1)

def test_validate_range_raises(self):

with self.assertRaises(WidthRangeError):
Expand Down