Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
goanpeca committed Apr 27, 2020
1 parent d29016b commit d2d0e03
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 19 deletions.
8 changes: 5 additions & 3 deletions colosseum/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,8 @@ def value(self, context):
BACKGROUND_COLOR_CHOICES = Choices(default, TRANSPARENT, validators=[is_color])

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

# background_repeat
REPEAT = 'repeat'
Expand All @@ -364,10 +365,11 @@ def value(self, context):
SCROLL = 'scroll'
FIXED = 'fixed'

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

# background_position
BACKGROUND_POSITION_CHOICES = Choices(validators=is_position, explicit_defaulting_constants=[INHERIT])
BACKGROUND_POSITION_CHOICES = Choices(validators=[is_position], explicit_defaulting_constants=[INHERIT])

# background

Expand Down
4 changes: 2 additions & 2 deletions colosseum/declaration.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
)
from .exceptions import ValidationError
from .wrappers import (
Border, BorderBottom, BorderLeft, BorderRight, BorderTop, Outline,
Background, Border, BorderBottom, BorderLeft, BorderRight, BorderTop,
Outline,
)

_CSS_PROPERTIES = set()
Expand Down Expand Up @@ -115,7 +116,6 @@ def validated_property(name, choices, initial):
# Check the value attribute is a callable
if not callable(value_attr):
raise ValueError('Initial value "%s" `value` attribute is not callable!' % initial)

except AttributeError:
raise ValueError('Initial value "%s" does not have a value attribute!' % initial)

Expand Down
35 changes: 21 additions & 14 deletions colosseum/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ def outline(value):


##############################################################################
# # Border shorthands
# Border shorthands
##############################################################################
def _parse_border_property_part(value, border_dict, direction=None):
"""Parse border shorthand property part for known properties."""
Expand Down Expand Up @@ -454,7 +454,14 @@ def position(value):
"""
[[ <percentage> | <length> | left | center | right ][ <percentage> | <length> | top | center | bottom ]? ] |
[[ left | center | right ] || [ top | center | bottom ]]
Reference:
- https://www.w3.org/TR/2011/REC-CSS2-20110607/colors.html#background-properties
"""
from .constants import ( # noqa
BOTTOM, CENTER, LEFT, RIGHT, TOP,
)

if value:
if isinstance(value, str):
values = [val.strip() for val in value.split()]
Expand All @@ -472,11 +479,11 @@ def position(value):
# <length> values are allowed.
try:
return Position(horizontal=units(values[0]))
except ValueError as error:
if values[0] in ['left', 'right', 'center']:
except ValueError:
if values[0] in [LEFT, RIGHT, CENTER]:
return Position(horizontal=values[0])

if values[0] in ['top', 'bottom']:
if values[0] in [TOP, BOTTOM]:
return Position(vertical=values[0])

elif len(values) == 2:
Expand All @@ -485,21 +492,21 @@ def position(value):
# Check first value
try:
horizontal = units(values[0])
except ValueError as error:
if values[0] in ['left', 'center', 'right']:
except ValueError:
if values[0] in [LEFT, CENTER, RIGHT]:
horizontal = values[0]

if values[0] in ['top', 'center', 'bottom']:
if values[0] in [TOP, CENTER, BOTTOM]:
vertical = values[0]

# Check second value
try:
vertical = units(values[1])
except ValueError as error:
if values[1] in ['left', 'center', 'right']:
except ValueError:
if values[1] in [LEFT, CENTER, RIGHT]:
horizontal = values[1]

if values[1] in ['top', 'center', 'bottom']:
if values[1] in [TOP, CENTER, BOTTOM]:
vertical = values[1]

return Position(horizontal=horizontal, vertical=vertical)
Expand All @@ -510,7 +517,7 @@ def position(value):
##############################################################################
# Background shorthand
##############################################################################
def _parse_background_property_part(value, outline_dict):
def _parse_background_property_part(value, background_dict):
"""Parse background shorthand property part for known properties."""
from .constants import ( # noqa
BACKGROUND_ATTACHMENT_CHOICES, BACKGROUND_COLOR_CHOICES, BACKGROUND_IMAGE_CHOICES,
Expand All @@ -527,11 +534,11 @@ def _parse_background_property_part(value, outline_dict):
except (ValueError, ValidationError):
continue

if property_name in border_dict:
if property_name in background_dict:
raise ValueError('Invalid duplicated property!')

border_dict[property_name] = value
return border_dict
background_dict[property_name] = value
return background_dict

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

Expand Down
2 changes: 2 additions & 0 deletions colosseum/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ def is_cursor(value):
except ValueError as error:
raise ValidationError(str(error))

return value


is_cursor.description = ('[ [<uri> ,]* [ auto | crosshair | default | pointer | move | e-resize '
'| ne-resize | nw-resize | n-resize | se-resize | sw-resize | s-resize '
Expand Down
5 changes: 5 additions & 0 deletions colosseum/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,11 @@ class Border(Shorthand):
VALID_KEYS = ['border_width', 'border_style', 'border_color']


class Background(Shorthand):
VALID_KEYS = ['background_color', 'background_image', 'background_repeat', 'background_attachment',
'background_position']


class Uri:
"""Wrapper for a url."""

Expand Down

0 comments on commit d2d0e03

Please sign in to comment.