# Path: giotto/exceptions.py
# class InvalidInput(GiottoException):
#     def __init__(self, message='', **kwargs):
#         self.message = message
#         for k, v in kwargs.items():
#             setattr(self, k, v)
# 
#     def __str__(self):
#         return self.message
# 
#     def __setattr__(self, attr, value):
#         """
#         When setting values, make into a dictionary with 'message' and 'value'
#         keys.
#         """
#         if attr == 'message':
#             return super(InvalidInput, self).__setattr__(attr, value)
#         if value is None:
#             return super(InvalidInput, self).__setattr__(attr, None)
#         if type(value) is not dict:
#             value = {'value': value, 'message': ''}
#             return super(InvalidInput, self).__setattr__(attr, value)
#         if not 'message' in value:
#             value['message'] = ''
#         if not 'value' in value:
#             value['value'] = ''
# 
#         super(InvalidInput, self).__setattr__(attr, value)
# 
#     def __getitem__(self, item):
#         # be permissive of attribute errors because jinja templates
#         # need to not blow up when there are no errors.
#         if not item in self.__dict__:
#             return Mock()


import unittest
from giotto.exceptions import InvalidInput


class InvalidInputTest(unittest.TestCase):

    def test_just_message(self):
        exc1 = InvalidInput("Message")
        exc2 = InvalidInput(message="Message")

        self.assertEquals(exc1.message, "Message")
        self.assertEquals(str(exc1), "Message")
        self.assertEquals(str(exc1), str(exc2))

    def test_basic_kwargs(self):
        exc = InvalidInput("Message", x=3, y=2)
        self.assertEquals(exc.x['message'], '')
        self.assertEquals(exc.x['value'], 3)

    def test_complex_kwargs(self):
        exc = InvalidInput("Message", x={'message': "too large", "value": 4})
        self.assertEquals(exc.x['message'], "too large")
        self.assertEquals(exc.x['value'], 4)
        self.assertEquals(str(exc), "Message")

    def test_empty_template_safe(self):
        """
        Undefined vars on the exception are treated as empty vars
        """

# Path: giotto/exceptions.py
# class InvalidInput(GiottoException):
#     def __init__(self, message='', **kwargs):
#         self.message = message
#         for k, v in kwargs.items():
#             setattr(self, k, v)
# 
#     def __str__(self):
#         return self.message
# 
#     def __setattr__(self, attr, value):
#         """
#         When setting values, make into a dictionary with 'message' and 'value'
#         keys.
#         """
#         if attr == 'message':
#             return super(InvalidInput, self).__setattr__(attr, value)
#         if value is None:
#             return super(InvalidInput, self).__setattr__(attr, None)
#         if type(value) is not dict:
#             value = {'value': value, 'message': ''}
#             return super(InvalidInput, self).__setattr__(attr, value)
#         if not 'message' in value:
#             value['message'] = ''
#         if not 'value' in value:
#             value['value'] = ''
# 
#         super(InvalidInput, self).__setattr__(attr, value)
# 
#     def __getitem__(self, item):
#         # be permissive of attribute errors because jinja templates
#         # need to not blow up when there are no errors.
#         if not item in self.__dict__:
#             return Mock()


# Path: giotto/tests/exception_tests.py
import unittest
from giotto.exceptions import InvalidInput



class InvalidInputTest(unittest.TestCase):

    def test_just_message(self):
        exc1 = InvalidInput("Message")
        exc2 = InvalidInput(message="Message")

        self.assertEquals(exc1.message, "Message")
        self.assertEquals(str(exc1), "Message")
        self.assertEquals(str(exc1), str(exc2))

    def test_basic_kwargs(self):
        exc = InvalidInput("Message", x=3, y=2)
        self.assertEquals(exc.x['message'], '')
        self.assertEquals(exc.x['value'], 3)

    def test_complex_kwargs(self):
        exc = InvalidInput("Message", x={'message': "too large", "value": 4})
        self.assertEquals(exc.x['message'], "too large")
        self.assertEquals(exc.x['value'], 4)
        self.assertEquals(str(exc), "Message")

    def test_empty_template_safe(self):
        """
        Undefined vars on the exception are treated as empty vars
        """

        exc = InvalidInput("Message", x={'message': "too large", "value": 4})