<s> import datetime <EOL> from twisted . trial import unittest <EOL> from twisted . internet import defer <EOL> from piped . processors import datetime_processors <EOL> class DateTimeParserTest ( unittest . TestCase ) : <EOL> @ defer . inlineCallbacks <EOL> def test_parsing_and_getting_date ( self ) : <EOL> processor = datetime_processors . DateTimeParser ( format_string = '<STR_LIT>' , as_date = True ) <EOL> result = yield processor . process ( '<STR_LIT>' ) <EOL> self . assertEquals ( result , datetime . date ( <NUM_LIT> , <NUM_LIT:2> , <NUM_LIT:3> ) ) <EOL> @ defer . inlineCallbacks <EOL> def test_parse_with_different_formats ( self ) : <EOL> simple_tests = dict ( ) <EOL> simple_tests [ ( '<STR_LIT>' , '<STR_LIT>' ) ] = datetime . datetime ( <NUM_LIT> , <NUM_LIT:2> , <NUM_LIT:3> ) <EOL> simple_tests [ ( '<STR_LIT>' , '<STR_LIT>' ) ] = datetime . datetime ( <NUM_LIT> , <NUM_LIT:2> , <NUM_LIT:3> ) <EOL> simple_tests [ ( '<STR_LIT>' , '<STR_LIT>' ) ] = datetime . datetime ( <NUM_LIT> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:15> , <NUM_LIT> , <NUM_LIT:12> ) <EOL> for ( datetime_string , format_string ) , expected_datetime in simple_tests . items ( ) : <EOL> processor = datetime_processors . DateTimeParser ( format_string = format_string ) <EOL> result = yield processor . process ( datetime_string ) <EOL> self . assertEquals ( expected_datetime , result ) <EOL> processor = datetime_processors . DateTimeParser ( format_string = '<STR_LIT>' ) <EOL> self . assertRaises ( ValueError , processor . process_input , '<STR_LIT>' , baton = None ) <EOL> class DateFormatterTest ( unittest . TestCase ) : <EOL> @ defer . inlineCallbacks <EOL> def test_parse_simple ( self ) : <EOL> simple_tests = dict ( ) <EOL> simple_tests [ ( datetime . datetime ( <NUM_LIT> , <NUM_LIT:2> , <NUM_LIT:3> ) , '<STR_LIT>' ) ] = '<STR_LIT>' <EOL> simple_tests [ ( datetime . datetime ( <NUM_LIT> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:15> , <NUM_LIT> , <NUM_LIT:12> ) , '<STR_LIT>' ) ] = '<STR_LIT>' <EOL> simple_tests [ ( datetime . date ( <NUM_LIT> , <NUM_LIT:2> , <NUM_LIT:3> ) , '<STR_LIT>' ) ] = '<STR_LIT>' <EOL> for ( date_like , format_string ) , expected_result in simple_tests . items ( ) : <EOL> processor = datetime_processors . DateFormatter ( format_string = format_string ) <EOL> result = yield processor . process ( date_like ) <EOL> self . assertEquals ( expected_result , result ) <EOL> processor = datetime_processors . DateFormatter ( format_string = '<STR_LIT>' ) <EOL> self . assertRaises ( ValueError , processor . process_input , datetime . datetime . now ( ) , baton = None ) </s>
