# Path: css2video/constants.py
# class ValueType(object):
#     """Class to define constants for value types"""
# 
#     number = 'number'
#     length = 'length'
#     percentage = 'percentage'
#     time = 'time'
#     color = 'color'
#     text = 'text'
#     url = 'url'
#     function = 'function'
#     array = 'array'
# 
# Path: css2video/parsers/value.py
# class Length(BaseParser):
#     """Parse a length value that has a unit attached along with the number"""
# 
#     ParseException = LengthParseException
# 
#     UNITS = ['em', 'ex', 'px', 'cm', 'mm', 'in', 'pt', 'pc', 'deg']
# 
#     @classmethod
#     def grammar(cls):
#         """Grammar to parse the length value"""
#         number = Number.grammar()
#         units = pp.CaselessLiteral(cls.UNITS[0])
#         for unit in cls.UNITS[1:]:
#             units |= pp.Literal(unit)
#         return number + units.leaveWhitespace()
# 
#     @classmethod
#     def parse_action(cls, tokens):
#         """Returns a dictionary from the parsed tokens"""
#         return {
#             'type': ValueType.length,
#             'value': float(tokens[0]),
#             'unit': tokens[1].lower()  # normalizing the units
#         }
# 
# class LengthParseException(Exception):
#     """Raised when there is an execption while parsing a length"""
#     pass


import unittest
from css2video.constants import ValueType
from css2video.parsers.value import Length, LengthParseException



class TestCase(unittest.TestCase):

    def test_parser(self):
        response = Length.parse('20px')
        self.assertEqual(
            response, dict(type=ValueType.length, value=20., unit='px')
        )

        response = Length.parse('-40.5EM')
        self.assertEqual(
            response, dict(type=ValueType.length, value=-40.5, unit='em')
        )

        with self.assertRaises(LengthParseException):
            Length.parse('20')


# Path: css2video/constants.py
# class ValueType(object):
#     """Class to define constants for value types"""
# 
#     number = 'number'
#     length = 'length'
#     percentage = 'percentage'
#     time = 'time'
#     color = 'color'
#     text = 'text'
#     url = 'url'
#     function = 'function'
#     array = 'array'
# 
# Path: css2video/parsers/value.py
# class Length(BaseParser):
#     """Parse a length value that has a unit attached along with the number"""
# 
#     ParseException = LengthParseException
# 
#     UNITS = ['em', 'ex', 'px', 'cm', 'mm', 'in', 'pt', 'pc', 'deg']
# 
#     @classmethod
#     def grammar(cls):
#         """Grammar to parse the length value"""
#         number = Number.grammar()
#         units = pp.CaselessLiteral(cls.UNITS[0])
#         for unit in cls.UNITS[1:]:
#             units |= pp.Literal(unit)
#         return number + units.leaveWhitespace()
# 
#     @classmethod
#     def parse_action(cls, tokens):
#         """Returns a dictionary from the parsed tokens"""
#         return {
#             'type': ValueType.length,
#             'value': float(tokens[0]),
#             'unit': tokens[1].lower()  # normalizing the units
#         }
# 
# class LengthParseException(Exception):
#     """Raised when there is an execption while parsing a length"""
#     pass


# Path: tests/parsers/value/test_length.py
import unittest
from css2video.constants import ValueType
from css2video.parsers.value import Length, LengthParseException




class TestCase(unittest.TestCase):

    def test_parser(self):
        response = Length.parse('20px')
        self.assertEqual(
            response, dict(type=ValueType.length, value=20., unit='px')
        )

        response = Length.parse('-40.5EM')
        self.assertEqual(
            response, dict(type=ValueType.length, value=-40.5, unit='em')
        )

        with self.assertRaises(LengthParseException):
            Length.parse('20')


        with self.assertRaises(LengthParseException):