Skip to content

Commit d2d0e03

Browse files
committed
Update tests
1 parent d29016b commit d2d0e03

5 files changed

Lines changed: 35 additions & 19 deletions

File tree

colosseum/constants.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,8 @@ def value(self, context):
350350
BACKGROUND_COLOR_CHOICES = Choices(default, TRANSPARENT, validators=[is_color])
351351

352352
# background_image
353-
BACKGROUND_IMAGE_CHOICES = Choices(validators=[is_uri], explicit_defaulting_constants=[INHERIT])
353+
# TODO: tests fail if INITIAL is not used, but INITIAL does not seem to be a valid value
354+
BACKGROUND_IMAGE_CHOICES = Choices(None, validators=[is_uri], explicit_defaulting_constants=[INHERIT, INITIAL])
354355

355356
# background_repeat
356357
REPEAT = 'repeat'
@@ -364,10 +365,11 @@ def value(self, context):
364365
SCROLL = 'scroll'
365366
FIXED = 'fixed'
366367

367-
BACKGROUND_ATTACHMENT_CHOICES = Choices(SCROLL, FIXED, explicit_defaulting_constants=[INHERIT])
368+
# TODO: tests fail if INITIAL is not used, but INITIAL does not seem to be a valid value
369+
BACKGROUND_ATTACHMENT_CHOICES = Choices(SCROLL, FIXED, explicit_defaulting_constants=[INHERIT, INITIAL])
368370

369371
# background_position
370-
BACKGROUND_POSITION_CHOICES = Choices(validators=is_position, explicit_defaulting_constants=[INHERIT])
372+
BACKGROUND_POSITION_CHOICES = Choices(validators=[is_position], explicit_defaulting_constants=[INHERIT])
371373

372374
# background
373375

colosseum/declaration.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
)
2727
from .exceptions import ValidationError
2828
from .wrappers import (
29-
Border, BorderBottom, BorderLeft, BorderRight, BorderTop, Outline,
29+
Background, Border, BorderBottom, BorderLeft, BorderRight, BorderTop,
30+
Outline,
3031
)
3132

3233
_CSS_PROPERTIES = set()
@@ -115,7 +116,6 @@ def validated_property(name, choices, initial):
115116
# Check the value attribute is a callable
116117
if not callable(value_attr):
117118
raise ValueError('Initial value "%s" `value` attribute is not callable!' % initial)
118-
119119
except AttributeError:
120120
raise ValueError('Initial value "%s" does not have a value attribute!' % initial)
121121

colosseum/parser.py

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ def outline(value):
286286

287287

288288
##############################################################################
289-
# # Border shorthands
289+
# Border shorthands
290290
##############################################################################
291291
def _parse_border_property_part(value, border_dict, direction=None):
292292
"""Parse border shorthand property part for known properties."""
@@ -454,7 +454,14 @@ def position(value):
454454
"""
455455
[[ <percentage> | <length> | left | center | right ][ <percentage> | <length> | top | center | bottom ]? ] |
456456
[[ left | center | right ] || [ top | center | bottom ]]
457+
458+
Reference:
459+
- https://www.w3.org/TR/2011/REC-CSS2-20110607/colors.html#background-properties
457460
"""
461+
from .constants import ( # noqa
462+
BOTTOM, CENTER, LEFT, RIGHT, TOP,
463+
)
464+
458465
if value:
459466
if isinstance(value, str):
460467
values = [val.strip() for val in value.split()]
@@ -472,11 +479,11 @@ def position(value):
472479
# <length> values are allowed.
473480
try:
474481
return Position(horizontal=units(values[0]))
475-
except ValueError as error:
476-
if values[0] in ['left', 'right', 'center']:
482+
except ValueError:
483+
if values[0] in [LEFT, RIGHT, CENTER]:
477484
return Position(horizontal=values[0])
478485

479-
if values[0] in ['top', 'bottom']:
486+
if values[0] in [TOP, BOTTOM]:
480487
return Position(vertical=values[0])
481488

482489
elif len(values) == 2:
@@ -485,21 +492,21 @@ def position(value):
485492
# Check first value
486493
try:
487494
horizontal = units(values[0])
488-
except ValueError as error:
489-
if values[0] in ['left', 'center', 'right']:
495+
except ValueError:
496+
if values[0] in [LEFT, CENTER, RIGHT]:
490497
horizontal = values[0]
491498

492-
if values[0] in ['top', 'center', 'bottom']:
499+
if values[0] in [TOP, CENTER, BOTTOM]:
493500
vertical = values[0]
494501

495502
# Check second value
496503
try:
497504
vertical = units(values[1])
498-
except ValueError as error:
499-
if values[1] in ['left', 'center', 'right']:
505+
except ValueError:
506+
if values[1] in [LEFT, CENTER, RIGHT]:
500507
horizontal = values[1]
501508

502-
if values[1] in ['top', 'center', 'bottom']:
509+
if values[1] in [TOP, CENTER, BOTTOM]:
503510
vertical = values[1]
504511

505512
return Position(horizontal=horizontal, vertical=vertical)
@@ -510,7 +517,7 @@ def position(value):
510517
##############################################################################
511518
# Background shorthand
512519
##############################################################################
513-
def _parse_background_property_part(value, outline_dict):
520+
def _parse_background_property_part(value, background_dict):
514521
"""Parse background shorthand property part for known properties."""
515522
from .constants import ( # noqa
516523
BACKGROUND_ATTACHMENT_CHOICES, BACKGROUND_COLOR_CHOICES, BACKGROUND_IMAGE_CHOICES,
@@ -527,11 +534,11 @@ def _parse_background_property_part(value, outline_dict):
527534
except (ValueError, ValidationError):
528535
continue
529536

530-
if property_name in border_dict:
537+
if property_name in background_dict:
531538
raise ValueError('Invalid duplicated property!')
532539

533-
border_dict[property_name] = value
534-
return border_dict
540+
background_dict[property_name] = value
541+
return background_dict
535542

536543
raise ValueError('Background value "{value}" not valid!'.format(value=value))
537544

colosseum/validators.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,8 @@ def is_cursor(value):
183183
except ValueError as error:
184184
raise ValidationError(str(error))
185185

186+
return value
187+
186188

187189
is_cursor.description = ('[ [<uri> ,]* [ auto | crosshair | default | pointer | move | e-resize '
188190
'| ne-resize | nw-resize | n-resize | se-resize | sw-resize | s-resize '

colosseum/wrappers.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,11 @@ class Border(Shorthand):
198198
VALID_KEYS = ['border_width', 'border_style', 'border_color']
199199

200200

201+
class Background(Shorthand):
202+
VALID_KEYS = ['background_color', 'background_image', 'background_repeat', 'background_attachment',
203+
'background_position']
204+
205+
201206
class Uri:
202207
"""Wrapper for a url."""
203208

0 commit comments

Comments
 (0)