def test_decode_property_value_font_family(self):
     valid_property_name = 'font-family'
     encoded_property_values = [
         'serif', 'sans-serif', 'monospace', 'fantasy',
         'cambria', 'didot', 'garamond',
         'arial', 'helvetica', 'gadget',
         'courier', 'monaco', 'consolas',
         'copperplate', 'papyrus',
         'invalid', 'wrong',     # These just pass through.
     ]
     expected_property_values = [
         'serif', 'sans-serif', 'monospace', 'fantasy',
         'cambria, serif', 'didot, serif', 'garamond, serif',
         'arial, sans-serif', 'helvetica, sans-serif', 'gadget, sans-serif',
         'courier, monospace', 'monaco, monospace', 'consolas, monospace',
         'copperplate, fantasy', 'papyrus, fantasy',
         'invalid', 'wrong',     # These just pass through.
     ]
     property_parser = CSSPropertyValueParser(property_name=valid_property_name)
     for i, value in enumerate(encoded_property_values):
         self.assertEquals(
             property_parser.decode_property_value(value=value),
             expected_property_values[i],
             msg=value
         )
 def test_decode_property_value_pass_through_invalid_patterns(self):
     valid_property_name = 'color'
     encoded_property_values = ['bold-50', '5u5', 'b1-a5-c1p-e5', '5pxrem', '1ap-10xp-3qp-1mp3', 'p12px']
     expected_property_values = ['bold 50', '5u5', 'b1 a5 c1% e5', '5pxrem', '1a% 10x% 3q% 1mp3', 'p12px']
     property_parser = CSSPropertyValueParser(property_name=valid_property_name)
     for i, value in enumerate(encoded_property_values):
         self.assertEquals(
             property_parser.decode_property_value(value=value),
             expected_property_values[i],
             msg=value
         )
 def test_decode_property_value_px_to_em(self):
     valid_property_name = 'padding'
     encoded_property_values = [
         '55', '1-5-1-5', '1_32rem', '1p-10p-3p-1p', 'n12px', 'n5_25in-n6_1in', 'n0_0435p',
     ]
     expected_property_values = [
         '3.4375em', '0.0625em 0.3125em 0.0625em 0.3125em', '1.32rem', '1% 10% 3% 1%', '-0.75em',
         '-5.25in -6.1in', '-0.0435%',
     ]
     property_parser = CSSPropertyValueParser(property_name=valid_property_name)
     for i, value in enumerate(encoded_property_values):
         self.assertEquals(
             property_parser.decode_property_value(value=value),
             expected_property_values[i],
             msg=value
         )
 def test_decode_property_value(self):
     valid_property_name = 'color'
     encoded_property_values = [
         'bold', '55', '1-5-1-5', '1_32rem', '1p-10p-3p-1p', 'n12px', 'n5_25in-n6_1in', 'n0_0435p',
         'h0ff48f', 'hfff', 'rgba-255-0-0-0_5', 'hsla-120-60p-70p-0_3',
     ]
     expected_property_values = [
         'bold', '55', '1 5 1 5', '1.32rem', '1% 10% 3% 1%', '-12px', '-5.25in -6.1in', '-0.0435%',
         '#0ff48f', '#fff', 'rgba(255, 0, 0, 0.5)', 'hsla(120, 60%, 70%, 0.3)',
     ]
     property_parser = CSSPropertyValueParser(property_name=valid_property_name)
     for i, value in enumerate(encoded_property_values):
         self.assertEquals(
             property_parser.decode_property_value(value=value),
             expected_property_values[i],
             msg=value
         )
예제 #5
0
    def get_property_value(self, property_name='', encoded_property_value=''):
        """
        Accepts an encoded_property_value that's been stripped of it's property named and priority
        Uses CSSPropertyValueParser, and returns a valid css property value or ''.

        Usage Note: Invalid CSS values can be returned by this method.  CSS validation occurs at a later step.

        :raises ValueError: If either property_name or css_class are empty or only contain whitespace values.

        :type property_name: str
        :type encoded_property_value: str

        :param property_name: Name of CSS property that matches a key in ``property_alias_dict``.
        :param encoded_property_value: A property value that may or may not contain dashes and underscores.
        :return: (str) -- An unvalidated / potential CSS property value.

        **Examples:**

        >>> property_parser = ClassPropertyParser(set(), False)                 # Turn OFF unit conversion.
        >>> property_parser.get_property_value('font-weight', 'bold')           # Special case: alias == property value
        'bold'
        >>> property_parser.get_property_value('padding', '1-10-10-5')          # Multi-value encoding contains dashes.
        '1px 10px 10px 5px'
        >>> property_parser.get_property_value('width', '7_25rem')              # Single value contains underscores.
        '7.25rem'
        >>> property_parser.get_property_value('margin', '1ap-10xp-3qp-1mp3')   # Invalid CSS returned.
        '1a% 10x% 3q% 1mp3'
        >>> property_parser.get_property_value('', 'c-lime')
        ValueError
        >>> property_parser.get_property_value('color', '  ')
        ValueError

        """
        deny_empty_or_whitespace(string=property_name, variable_name='property_name')
        deny_empty_or_whitespace(string=encoded_property_value, variable_name='encoded_property_value')

        value_parser = CSSPropertyValueParser(property_name=property_name)
        value = value_parser.decode_property_value(value=encoded_property_value)
        return value