Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_set_limit_key(self):
valid_css_classes = ['inline-small-up', 'inline-giant-down-i', 'green-xxsmall-only', 'padding-10-large-up', ]
names = ['display', 'display', 'color', 'padding', ]
values = ['inline', 'inline', 'green', '10', ]
priorities = ['', 'important', '', '', ]
expected = ['-up', '-down', '-only', '-up', ]
for i, css_class in enumerate(valid_css_classes):
css_property = Property(name=names[i], value=values[i], priority=priorities[i])
breakpoint_parser = BreakpointParser(css_class=css_class, css_property=css_property)
breakpoint_parser.set_limit_key()
self.assertEqual(breakpoint_parser.limit_key, expected[i])
def test_css_for_down_general_usage(self):
css_class = 'padding-100-medium-down'
name = 'padding'
value = px_to_em('100')
expected = (
'@media only screen and (max-width: 45.0em) {\n' +
'\t.padding-100-medium-down {\n' +
'\t\tpadding: 6.25em;\n' +
'\t}\n' +
'}\n\n'
)
css_property = Property(name=name, value=value, priority='')
breakpoint_parser = BreakpointParser(css_class=css_class, css_property=css_property)
css = breakpoint_parser.css_for_down()
self.assertEqual(css, expected)
def test_is_scaling_True(self):
valid_css_classes = ['font-size-24-s', 'font-size-24-s-i', 'padding-10-s', 'margin-30-s-i', ]
names = ['font-size', 'font-size', 'padding', 'margin', ]
values = ['24px', '24px', '10px', '30px']
priorities = ['', 'important', '', 'important', ]
for i, css_class in enumerate(valid_css_classes):
css_property = Property(name=names[i], value=values[i], priority=priorities[i])
scaling_parser = ScalingParser(css_class=css_class, css_property=css_property)
self.assertTrue(scaling_parser.is_scaling)
def test_build_media_query_up_general_usage(self):
css_class = 'padding-100-small-up'
name = 'padding'
value = px_to_em('100')
expected = (
'@media only screen and (min-width: 15.0625em) {\n' +
'\t.padding-100-small-up {\n' +
'\t\tpadding: 6.25em;\n' +
'\t}\n' +
'}\n\n'
)
css_property = Property(name=name, value=value, priority='')
breakpoint_parser = BreakpointParser(css_class=css_class, css_property=css_property)
css = breakpoint_parser.build_media_query()
self.assertEqual(css, expected)
def test_strip_scaling_flag(self):
valid_css_classes = [
'font-size-34-s', 'font-size-24-s-i', 'padding-12-s', 'margin-31-s-i',
'font-size-10', 'font-size-13-i',
]
names = ['font-size', 'font-size', 'padding', 'margin', 'font-size', 'font-size', ]
values = ['34px', '24px', '12px', '31px', '15px', '52px', '10px', '13px', ]
priorities = ['', 'important', '', 'important', '', '', '', '', ]
expected = [
'font-size-34', 'font-size-24-i', 'padding-12', 'margin-31-i',
'font-size-10', 'font-size-13-i',
]
for i, css_class in enumerate(valid_css_classes):
css_property = Property(name=names[i], value=values[i], priority=priorities[i])
scaling_parser = ScalingParser(css_class=css_class, css_property=css_property)
clean_css_class = scaling_parser.strip_scaling_flag()
self.assertEqual(clean_css_class, expected[i])
def __get_prefixed_prop(self, prefix=None):
name = self.prop.name
if prefix:
name = '-%s-%s' % (prefix, self.prop.name)
newValues = []
for value in self.prop.value.split(','):
parts = value.strip().split(' ')
parts[0] = prefixRegex.sub('', parts[0])
if parts[0] in rules and prefix and rules[parts[0]].should_prefix():
parts[0] = '-%s-%s' % (prefix, parts[0])
newValues.append(' '.join(parts))
return cssutils.css.Property(
name=name,
value=', '.join(newValues),
priority=self.prop.priority
)
**Examples:**
>>> value_parser = CSSPropertyValueParser()
>>> value_parser.property_is_valid(
>>> name='padding', value='1px', priority=''
>>> )
True
>>> value_parser.property_is_valid(
>>> name='padding', value='invalid', priority=''
>>> )
False
"""
try:
css_property = Property(name=name, value=value, priority=priority)
is_valid = css_property.valid
return is_valid
except SyntaxErr:
return False
"""
if not self.is_scaling:
return ''
name = self.css_property.name
value = self.css_property.value
units = ''.join(filter(lambda x: x.isalpha(), value)) # Only keep letters.
priority = self.css_property.priority
deny_empty_or_whitespace(str(value), variable_name='value')
float_value = float(value.replace(units, '')) # Remove units.
_max = 1
large_property = Property(name=name, value=value, priority=priority)
medium_property = Property(name=name, value=value, priority=priority)
small_property = Property(name=name, value=value, priority=priority)
large_value = round(float_value / self.scale_dict['large'], 4) # Scale to large screen
large_property.value = str(large_value) + units # Add units
medium_value = round(float_value / self.scale_dict['medium'], 4) # Scale to medium screen
medium_property.value = str(medium_value) + units # Add units
small_value = round(float_value / self.scale_dict['small'], 4) # Scale to small screen
small_property.value = str(small_value) + units # Add units
return (
'.' + self.css_class + ' { ' + self.css_property.cssText + '; }\n\n' +
'@media only screen and (max-width: ' + large[_max] + ') {\n' +
'\t.' + self.css_class + ' { ' + large_property.cssText + '; }\n' +
'}\n\n' +
def _char(expected, seq, token, tokenizer=None):
# starting a feature which basically is a CSS Property
# but may simply be a property name too
val = self._tokenvalue(token)
if val == u'(' and expected == 'feature':
proptokens = self._tokensupto2(
tokenizer, funcendonly=True)
if proptokens and u')' == self._tokenvalue(proptokens[-1]):
proptokens.pop()
property = cssutils.css.Property(_mediaQuery=True)
property.cssText = proptokens
seq.append(property)
return 'and or EOF'
else:
new['wellformed'] = False
self._log.error(
u'MediaQuery: Unexpected syntax, expected "and" but found "%s".' %
val, token)
return expected
def __init__(self, css_class='', css_property=Property()):
deny_empty_or_whitespace(css_class, variable_name='css_class')
deny_empty_or_whitespace(css_property.cssText, variable_name='css_property')
self.css_class = css_class
self.css_property = css_property
self.scale_dict = {
'large': 1.043,
'medium': 1.125,
'small': 1.25,
}
self.scaling_flag = '-s'
self.is_scaling = self._is_scaling()