-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_datetime.py
More file actions
86 lines (72 loc) · 2.89 KB
/
Copy pathtest_datetime.py
File metadata and controls
86 lines (72 loc) · 2.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
from sqlobject import *
from sqlobject.tests.dbtest import *
########################################
## Date/time columns
########################################
from sqlobject import col
col.default_datetime_implementation = DATETIME_IMPLEMENTATION
from datetime import datetime, date, time
class DateTime1(SQLObject):
col1 = DateTimeCol()
col2 = DateCol()
col3 = TimeCol()
def test_dateTime():
setupClass(DateTime1)
_now = datetime.now()
dt1 = DateTime1(col1=_now, col2=_now, col3=_now.time())
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 not isinstance(dt1.col2, datetime)
assert dt1.col2.year == _now.year
assert dt1.col2.month == _now.month
assert dt1.col2.day == _now.day
assert isinstance(dt1.col3, time)
assert dt1.col3.hour == _now.hour
assert dt1.col3.minute == _now.minute
assert dt1.col3.second == int(_now.second)
if mxdatetime_available:
col.default_datetime_implementation = MXDATETIME_IMPLEMENTATION
from mx.DateTime import now, Time
dateFormat = None # use default
if getConnection().dbName == "sqlite":
from sqlobject.sqlite.sqliteconnection import using_sqlite2
if using_sqlite2:
# mxDateTime sends and PySQLite2 returns full date/time for dates
dateFormat = "%Y-%m-%d %H:%M:%S"
class DateTime2(SQLObject):
col1 = DateTimeCol()
col2 = DateCol(dateFormat=dateFormat)
col3 = TimeCol()
def test_mxDateTime():
setupClass(DateTime2)
_now = now()
dt2 = DateTime2(col1=_now, col2=_now, col3=Time(_now.hour, _now.minute, int(_now.second)))
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)
assert dt2.col2.year == _now.year
assert dt2.col2.month == _now.month
assert dt2.col2.day == _now.day
if getConnection().dbName == "sqlite":
assert dt2.col2.hour == _now.hour
assert dt2.col2.minute == _now.minute
assert dt2.col2.second == int(_now.second)
else:
assert dt2.col2.hour == 0
assert dt2.col2.minute == 0
assert dt2.col2.second == 0
assert isinstance(dt2.col3, (col.DateTimeType, col.TimeType))
assert dt2.col3.hour == _now.hour
assert dt2.col3.minute == _now.minute
assert dt2.col3.second == int(_now.second)