# Path: cartographer/field_types/date_attribute.py
# class DateAttribute(SchemaAttribute):
#     @classmethod
#     def format_value_for_json(cls, value):
#         return as_utc(value).isoformat()
# 
#     def from_json(self, serialized_value):
#         if self.is_nullable and serialized_value is None:
#             return None
# 
#         try:
#             # ciso8601 is significantly faster than dateutil.parser for parsing iso8601 strings, so we try it first
#             parsed_value = ciso8601.parse_datetime(serialized_value)
#             assert parsed_value is not None  # Caveat: asserts won't run if python is run with -O.
#         except Exception as e:
#             parsed_value = dateutil.parser.parse(serialized_value)
# 
#         return make_naive(parsed_value)


import nose.tools as t
from cartographer.field_types.date_attribute import DateAttribute



def test_not_nullable_date_field_errors_on_none():
    attribute = DateAttribute().self_explanatory()

    with t.assert_raises(AttributeError):
        attribute.from_json(None)


def test_nullable_date_field_can_parse_none():

# Path: cartographer/field_types/date_attribute.py
# class DateAttribute(SchemaAttribute):
#     @classmethod
#     def format_value_for_json(cls, value):
#         return as_utc(value).isoformat()
# 
#     def from_json(self, serialized_value):
#         if self.is_nullable and serialized_value is None:
#             return None
# 
#         try:
#             # ciso8601 is significantly faster than dateutil.parser for parsing iso8601 strings, so we try it first
#             parsed_value = ciso8601.parse_datetime(serialized_value)
#             assert parsed_value is not None  # Caveat: asserts won't run if python is run with -O.
#         except Exception as e:
#             parsed_value = dateutil.parser.parse(serialized_value)
# 
#         return make_naive(parsed_value)


# Path: test/field_types/test_date_attribute.py
import nose.tools as t
from cartographer.field_types.date_attribute import DateAttribute




def test_not_nullable_date_field_errors_on_none():
    attribute = DateAttribute().self_explanatory()

    with t.assert_raises(AttributeError):
        attribute.from_json(None)


def test_nullable_date_field_can_parse_none():

    attribute = DateAttribute().self_explanatory().nullable()