1from cpython.datetime cimport import_datetime 2from cpython.datetime cimport time_new, date_new, datetime_new, timedelta_new 3from cpython.datetime cimport time_tzinfo, datetime_tzinfo 4from cpython.datetime cimport time_hour, time_minute, time_second, time_microsecond 5from cpython.datetime cimport date_day, date_month, date_year 6from cpython.datetime cimport datetime_day, datetime_month, datetime_year 7from cpython.datetime cimport datetime_hour, datetime_minute, datetime_second, \ 8 datetime_microsecond 9from cpython.datetime cimport timedelta_days, timedelta_seconds, timedelta_microseconds 10 11import_datetime() 12 13def test_date(int year, int month, int day): 14 ''' 15 >>> test_date(2012,12,31) 16 (True, True, True) 17 ''' 18 o = date_new(year, month, day) 19 return o.year == date_year(o), \ 20 o.month == date_month(o), \ 21 o.day == date_day(o) 22 23def test_datetime(int year, int month, int day, 24 int hour, int minute, int second, int microsecond): 25 ''' 26 >>> test_datetime(2012, 12, 31, 12, 30, 59, 12345) 27 (True, True, True, True, True, True, True) 28 ''' 29 o = datetime_new(year, month, day, hour, minute, second, microsecond, None) 30 return o.year == datetime_year(o), \ 31 o.month == datetime_month(o), \ 32 o.day == datetime_day(o), \ 33 o.hour == datetime_hour(o), \ 34 o.minute == datetime_minute(o), \ 35 o.second == datetime_second(o), \ 36 o.microsecond == datetime_microsecond(o) 37 38def test_time(int hour, int minute, int second, int microsecond): 39 ''' 40 >>> test_time(12, 30, 59, 12345) 41 (True, True, True, True) 42 ''' 43 o = time_new(hour, minute, second, microsecond, None) 44 return o.hour == time_hour(o), \ 45 o.minute == time_minute(o), \ 46 o.second == time_second(o), \ 47 o.microsecond == time_microsecond(o) 48 49def test_timedelta(int days, int seconds, int microseconds): 50 ''' 51 >>> test_timedelta(30, 1440, 123456) 52 (True, True, True) 53 ''' 54 o = timedelta_new(days, seconds, microseconds) 55 return o.days == timedelta_days(o), \ 56 o.seconds == timedelta_seconds(o), \ 57 o.microseconds == timedelta_microseconds(o) 58 59