Skip to content

Commit ca93b68

Browse files
committed
Tests: Explicitly use both TIMESTAMP {WITH,WITHOUT} TIME ZONE types
Makes sense specifically in the context when exercising date/time conversions from `TIMESTAMP` to corresponding Python types in the future.
1 parent a7fa1ee commit ca93b68

File tree

6 files changed

+28
-20
lines changed

6 files changed

+28
-20
lines changed

docs/query.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,8 @@ The cursor ``description`` might look like this:
187187

188188
>>> cursor.description
189189
(('date', None, None, None, None, None, None),
190-
('datetime', None, None, None, None, None, None),
190+
('datetime_tz', None, None, None, None, None, None),
191+
('datetime_notz', None, None, None, None, None, None),
191192
('description', None, None, None, None, None, None),
192193
...
193194
('nullable_datetime', None, None, None, None, None, None),
@@ -196,7 +197,7 @@ The cursor ``description`` might look like this:
196197
You can turn this into something more manageable with a `list comprehension`_::
197198

198199
>>> [column[0] for column in cursor.description]
199-
['date', 'datetime', 'description', ..., 'nullable_datetime', 'position']
200+
['date', 'datetime_tz', 'datetime_notz', ..., 'nullable_datetime', 'position']
200201

201202
.. _Bulk inserts: https://crate.io/docs/crate/reference/en/latest/interfaces/http.html#bulk-operations
202203
.. _Database API: http://www.python.org/dev/peps/pep-0249/

src/crate/client/doctests/client.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ supported, all other fields are 'None'::
212212
>>> result = cursor.fetchone()
213213
>>> pprint(result)
214214
['Aldebaran',
215+
1658167836758,
215216
1658167836758,
216217
1658167836758,
217218
None,
@@ -228,7 +229,8 @@ supported, all other fields are 'None'::
228229
>>> pprint(result)
229230
(('name', None, None, None, None, None, None),
230231
('date', None, None, None, None, None, None),
231-
('datetime', None, None, None, None, None, None),
232+
('datetime_tz', None, None, None, None, None, None),
233+
('datetime_notz', None, None, None, None, None, None),
232234
('nullable_datetime', None, None, None, None, None, None),
233235
('nullable_date', None, None, None, None, None, None),
234236
('kind', None, None, None, None, None, None),

src/crate/client/sqlalchemy/doctests/itests.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,18 @@ Date should have been set at the insert due to default value via python method::
8080
>>> dt.day == now.day
8181
True
8282

83-
>>> (now - location.datetime).seconds < 4
83+
>>> (now - location.datetime_tz).seconds < 4
8484
True
8585

8686
Verify the return type of date and datetime::
8787

8888
>>> type(location.date)
8989
<class 'datetime.date'>
9090

91-
>>> type(location.datetime)
91+
>>> type(location.datetime_tz)
92+
<class 'datetime.datetime'>
93+
94+
>>> type(location.datetime_notz)
9295
<class 'datetime.datetime'>
9396

9497
the location also has a date and datetime property which both are nullable and

src/crate/client/tests.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,8 @@ class Location(Base):
214214
name = sa.Column(sa.String, primary_key=True)
215215
kind = sa.Column(sa.String)
216216
date = sa.Column(sa.Date, default=date.today)
217-
datetime = sa.Column(sa.DateTime, default=datetime.utcnow)
217+
datetime_tz = sa.Column(sa.DateTime, default=datetime.utcnow)
218+
datetime_notz = sa.Column(sa.DateTime, default=datetime.utcnow)
218219
nullable_datetime = sa.Column(sa.DateTime)
219220
nullable_date = sa.Column(sa.Date)
220221
flag = sa.Column(sa.Boolean)
Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
{ "name": "North West Ripple", "date":308534400000, "datetime":308534400000, "kind": "Galaxy", "position": 1, "description": "Relative to life on NowWhat, living on an affluent world in the North West ripple of the Galaxy is said to be easier by a factor of about seventeen million."}
2-
{ "name": "Outer Eastern Rim", "date":308534400000, "datetime":308534400000, "kind": "Galaxy", "position": 2, "description": "The Outer Eastern Rim of the Galaxy where the Guide has supplanted the Encyclopedia Galactica among its more relaxed civilisations."}
3-
{ "name": "Galactic Sector QQ7 Active J Gamma", "date":1367366412345, "datetime":1367366412345, "kind": "Galaxy", "position": 4, "description": "Galactic Sector QQ7 Active J Gamma contains the Sun Zarss, the planet Preliumtarn of the famed Sevorbeupstry and Quentulus Quazgar Mountains."}
4-
{ "name": "Aldebaran", "date":1658167836758, "datetime":1658167836758, "kind": "Star System", "position": 1, "description": "Max Quordlepleen claims that the only thing left after the end of the Universe will be the sweets trolley and a fine selection of Aldebaran liqueurs."}
5-
{ "name": "Algol", "date":1658167836758, "datetime":1658167836758, "kind": "Star System", "position": 2, "description": "Algol is the home of the Algolian Suntiger, the tooth of which is one of the ingredients of the Pan Galactic Gargle Blaster."}
6-
{ "name": "Alpha Centauri", "date":308534400000, "datetime":308534400000, "kind": "Star System", "position": 3, "description": "4.1 light-years northwest of earth"}
7-
{ "name": "Altair", "date":1658167836758, "datetime":1658167836758, "kind": "Star System", "position": 4, "description": "The Altairian dollar is one of three freely convertible currencies in the galaxy, though by the time of the novels it had apparently recently collapsed."}
8-
{ "name": "Allosimanius Syneca", "date":1658167836758, "datetime":1658167836758, "kind": "Planet", "position": 1, "description": "Allosimanius Syneca is a planet noted for ice, snow, mind-hurtling beauty and stunning cold."}
9-
{ "name": "Argabuthon", "date":1658167836758, "datetime":1658167836758, "kind": "Planet", "position": 2, "description": "It is also the home of Prak, a man placed into solitary confinement after an overdose of truth drug caused him to tell the Truth in its absolute and final form, causing anyone to hear it to go insane."}
10-
{ "name": "Arkintoofle Minor", "date":308534400000, "datetime":308534400000, "kind": "Planet", "position": 3, "description": "Motivated by the fact that the only thing in the Universe that travels faster than light is bad news, the Hingefreel people native to Arkintoofle Minor constructed a starship driven by bad news."}
11-
{ "name": "Bartledan", "date":1658167836758, "datetime":1658167836758, "kind": "Planet", "position": 4, "description": "An Earthlike planet on which Arthur Dent lived for a short time, Bartledan is inhabited by Bartledanians, a race that appears human but only physically."}
12-
{ "name": "Folfanga", "date":1658167836758, "datetime":1658167836758, "kind": "Star System", "position": 5, "description": "Folfanga is a star system, the fourth planet of which is inhabited by a species of small slug, of the genus A-Rth-Urp-Hil-Ipdenu."}
13-
{ "name": "Galaxy", "date":1658167836758, "datetime":1658167836758, "kind": "Galaxy", "position": 6, "description": "The end of the Galaxy."}
1+
{ "name": "North West Ripple", "date":308534400000, "datetime_tz":308534400000, "datetime_notz":308534400000, "kind": "Galaxy", "position": 1, "description": "Relative to life on NowWhat, living on an affluent world in the North West ripple of the Galaxy is said to be easier by a factor of about seventeen million."}
2+
{ "name": "Outer Eastern Rim", "date":308534400000, "datetime_tz":308534400000, "datetime_notz":308534400000, "kind": "Galaxy", "position": 2, "description": "The Outer Eastern Rim of the Galaxy where the Guide has supplanted the Encyclopedia Galactica among its more relaxed civilisations."}
3+
{ "name": "Galactic Sector QQ7 Active J Gamma", "date":1367366412345, "datetime_tz":1367366412345, "datetime_notz":1367366412345, "kind": "Galaxy", "position": 4, "description": "Galactic Sector QQ7 Active J Gamma contains the Sun Zarss, the planet Preliumtarn of the famed Sevorbeupstry and Quentulus Quazgar Mountains."}
4+
{ "name": "Aldebaran", "date":1658167836758, "datetime_tz":1658167836758, "datetime_notz":1658167836758, "kind": "Star System", "position": 1, "description": "Max Quordlepleen claims that the only thing left after the end of the Universe will be the sweets trolley and a fine selection of Aldebaran liqueurs."}
5+
{ "name": "Algol", "date":1658167836758, "datetime_tz":1658167836758, "datetime_notz":1658167836758, "kind": "Star System", "position": 2, "description": "Algol is the home of the Algolian Suntiger, the tooth of which is one of the ingredients of the Pan Galactic Gargle Blaster."}
6+
{ "name": "Alpha Centauri", "date":308534400000, "datetime_tz":308534400000, "datetime_notz":308534400000, "kind": "Star System", "position": 3, "description": "4.1 light-years northwest of earth"}
7+
{ "name": "Altair", "date":1658167836758, "datetime_tz":1658167836758, "datetime_notz":1658167836758, "kind": "Star System", "position": 4, "description": "The Altairian dollar is one of three freely convertible currencies in the galaxy, though by the time of the novels it had apparently recently collapsed."}
8+
{ "name": "Allosimanius Syneca", "date":1658167836758, "datetime_tz":1658167836758, "datetime_notz":1658167836758, "kind": "Planet", "position": 1, "description": "Allosimanius Syneca is a planet noted for ice, snow, mind-hurtling beauty and stunning cold."}
9+
{ "name": "Argabuthon", "date":1658167836758, "datetime_tz":1658167836758, "datetime_notz":1658167836758, "kind": "Planet", "position": 2, "description": "It is also the home of Prak, a man placed into solitary confinement after an overdose of truth drug caused him to tell the Truth in its absolute and final form, causing anyone to hear it to go insane."}
10+
{ "name": "Arkintoofle Minor", "date":308534400000, "datetime_tz":308534400000, "datetime_notz":308534400000, "kind": "Planet", "position": 3, "description": "Motivated by the fact that the only thing in the Universe that travels faster than light is bad news, the Hingefreel people native to Arkintoofle Minor constructed a starship driven by bad news."}
11+
{ "name": "Bartledan", "date":1658167836758, "datetime_tz":1658167836758, "datetime_notz":1658167836758, "kind": "Planet", "position": 4, "description": "An Earthlike planet on which Arthur Dent lived for a short time, Bartledan is inhabited by Bartledanians, a race that appears human but only physically."}
12+
{ "name": "Folfanga", "date":1658167836758, "datetime_tz":1658167836758, "datetime_notz":1658167836758, "kind": "Star System", "position": 5, "description": "Folfanga is a star system, the fourth planet of which is inhabited by a species of small slug, of the genus A-Rth-Urp-Hil-Ipdenu."}
13+
{ "name": "Galaxy", "date":1658167836758, "datetime_tz":1658167836758, "datetime_notz":1658167836758, "kind": "Galaxy", "position": 6, "description": "The end of the Galaxy."}

src/crate/testing/testdata/mappings/locations.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
create table locations (
22
name string primary key,
33
date timestamp,
4-
datetime timestamp,
4+
datetime_tz timestamp with time zone,
5+
datetime_notz timestamp without time zone,
56
nullable_datetime timestamp,
67
nullable_date timestamp,
78
kind string,

0 commit comments

Comments
 (0)