Author: phd
Date: 2005-10-18 13:52:49 +0000 (Tue, 18 Oct 2005)
New Revision: 1119
Modified:
SQLObject/branches/0.7-bugfix/sqlobject/tests/test_datetime.py
Log:
Merged a patch from the revision 1118 from the trunk - a number of minor enhancements and fixes.
Modified: SQLObject/branches/0.7-bugfix/sqlobject/tests/test_datetime.py
===================================================================
--- SQLObject/branches/0.7-bugfix/sqlobject/tests/test_datetime.py 2005-10-18 13:52:14 UTC (rev 1118)
+++ SQLObject/branches/0.7-bugfix/sqlobject/tests/test_datetime.py 2005-10-18 13:52:49 UTC (rev 1119)
@@ -1,11 +1,6 @@
from sqlobject import *
from sqlobject.tests.dbtest import *
from sqlobject import col
-if default_datetime_implementation == DATETIME_IMPLEMENTATION:
- from datetime import datetime
- now = datetime.now
-elif default_datetime_implementation == MXDATETIME_IMPLEMENTATION:
- from mx.DateTime import now
########################################
## Date/time columns
@@ -14,39 +9,57 @@
if datetime_available:
col.default_datetime_implementation = DATETIME_IMPLEMENTATION
from datetime import date, datetime
+ now = datetime.now
class DateTime1(SQLObject):
- col1 = DateCol()
- col2 = DateTimeCol()
+ col1 = DateTimeCol()
+ col2 = DateCol()
def test_dateTime():
setupClass(DateTime1)
_now = now()
- dt1 = DateTime1(col1=_now, col2=_now)
- assert isinstance(dt1.col1, date)
- assert isinstance(dt1.col2, datetime)
+ _today = date.today()
+ dt1 = DateTime1(col1=_now, col2=_today)
- today_str = _now.strftime("%Y-%m-%d")
- now_str = _now.strftime("%Y-%m-%d %T")
- assert str(dt1.col1) == today_str
- assert str(dt1.col2) == now_str
+ assert isinstance(dt1.col1, datetime)
+ assert dt1.col1.year == _now.year
+ assert dt1.col1.month == _now.month
+ assert dt1.col1.day == _now.day
+ assert dt1.col1.hour == _now.hour
+ assert dt1.col1.minute == _now.minute
+ assert dt1.col1.second == int(_now.second)
+ assert isinstance(dt1.col2, date)
+ assert dt1.col2.year == _today.year
+ assert dt1.col2.month == _today.month
+ assert dt1.col2.day == _today.day
+
if mxdatetime_available:
col.default_datetime_implementation = MXDATETIME_IMPLEMENTATION
+ from mx.DateTime import now
class DateTime2(SQLObject):
- col1 = DateCol()
- col2 = DateTimeCol()
+ col1 = DateTimeCol()
+ col2 = DateCol(dateFormat="%Y-%m-%d %H:%M:%S")
+ # mxDateTime does not have a separate date type
def test_mxDateTime():
setupClass(DateTime2)
_now = now()
dt2 = DateTime2(col1=_now, col2=_now)
+
assert isinstance(dt2.col1, col.DateTimeType)
+ assert dt2.col1.year == _now.year
+ assert dt2.col1.month == _now.month
+ assert dt2.col1.day == _now.day
+ assert dt2.col1.hour == _now.hour
+ assert dt2.col1.minute == _now.minute
+ assert dt2.col1.second == int(_now.second)
+
assert isinstance(dt2.col2, col.DateTimeType)
-
- today_str = _now.strftime("%Y-%m-%d 00:00:00.00")
- now_str = _now.strftime("%Y-%m-%d %T.00")
- assert str(dt2.col1) == today_str
- assert str(dt2.col2) == now_str
-
+ assert dt2.col2.year == _now.year
+ assert dt2.col2.month == _now.month
+ assert dt2.col2.day == _now.day
+ assert dt2.col1.hour == _now.hour
+ assert dt2.col1.minute == _now.minute
+ assert dt2.col1.second == int(_now.second)
|