Skip to content

Commit

Permalink
Tests: Explicitly use both TIMESTAMP {WITH,WITHOUT} TIME ZONE types
Browse files Browse the repository at this point in the history
Makes sense specifically in the context when exercising date/time
conversions from `TIMESTAMP` to corresponding Python types in the
future.
  • Loading branch information
amotl committed Jul 19, 2022
1 parent 979e82a commit 1f5f30c
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 20 deletions.
5 changes: 3 additions & 2 deletions docs/query.rst
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,8 @@ The cursor ``description`` might look like this:

>>> cursor.description
(('date', None, None, None, None, None, None),
('datetime', None, None, None, None, None, None),
('datetime_tz', None, None, None, None, None, None),
('datetime_notz', None, None, None, None, None, None),
('description', None, None, None, None, None, None),
...
('nullable_datetime', None, None, None, None, None, None),
Expand All @@ -196,7 +197,7 @@ The cursor ``description`` might look like this:
You can turn this into something more manageable with a `list comprehension`_::

>>> [column[0] for column in cursor.description]
['date', 'datetime', 'description', ..., 'nullable_datetime', 'position']
['date', 'datetime_tz', 'datetime_notz', ..., 'nullable_datetime', 'position']

.. _Bulk inserts: https://crate.io/docs/crate/reference/en/latest/interfaces/http.html#bulk-operations
.. _Database API: http://www.python.org/dev/peps/pep-0249/
Expand Down
4 changes: 3 additions & 1 deletion src/crate/client/doctests/client.txt
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ supported, all other fields are 'None'::
>>> result = cursor.fetchone()
>>> pprint(result)
['Aldebaran',
1658167836758,
1658167836758,
1658167836758,
None,
Expand All @@ -228,7 +229,8 @@ supported, all other fields are 'None'::
>>> pprint(result)
(('name', None, None, None, None, None, None),
('date', None, None, None, None, None, None),
('datetime', None, None, None, None, None, None),
('datetime_tz', None, None, None, None, None, None),
('datetime_notz', None, None, None, None, None, None),
('nullable_datetime', None, None, None, None, None, None),
('nullable_date', None, None, None, None, None, None),
('kind', None, None, None, None, None, None),
Expand Down
7 changes: 5 additions & 2 deletions src/crate/client/sqlalchemy/doctests/itests.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,18 @@ Date should have been set at the insert due to default value via python method::
>>> dt.day == now.day
True

>>> (now - location.datetime).seconds < 4
>>> (now - location.datetime_tz).seconds < 4
True

Verify the return type of date and datetime::

>>> type(location.date)
<class 'datetime.date'>

>>> type(location.datetime)
>>> type(location.datetime_tz)
<class 'datetime.datetime'>

>>> type(location.datetime_notz)
<class 'datetime.datetime'>

the location also has a date and datetime property which both are nullable and
Expand Down
3 changes: 2 additions & 1 deletion src/crate/client/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,8 @@ class Location(Base):
name = sa.Column(sa.String, primary_key=True)
kind = sa.Column(sa.String)
date = sa.Column(sa.Date, default=date.today)
datetime = sa.Column(sa.DateTime, default=datetime.utcnow)
datetime_tz = sa.Column(sa.DateTime, default=datetime.utcnow)
datetime_notz = sa.Column(sa.DateTime, default=datetime.utcnow)
nullable_datetime = sa.Column(sa.DateTime)
nullable_date = sa.Column(sa.Date)
flag = sa.Column(sa.Boolean)
Expand Down
26 changes: 13 additions & 13 deletions src/crate/testing/testdata/data/test_a.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{ "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."}
{ "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."}
{ "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."}
{ "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."}
{ "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."}
{ "name": "Alpha Centauri", "date":308534400000, "datetime":308534400000, "kind": "Star System", "position": 3, "description": "4.1 light-years northwest of earth"}
{ "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."}
{ "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."}
{ "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."}
{ "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."}
{ "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."}
{ "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."}
{ "name": "Galaxy", "date":1658167836758, "datetime":1658167836758, "kind": "Galaxy", "position": 6, "description": "The end of the Galaxy."}
{ "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."}
{ "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."}
{ "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."}
{ "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."}
{ "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."}
{ "name": "Alpha Centauri", "date":308534400000, "datetime_tz":308534400000, "datetime_notz":308534400000, "kind": "Star System", "position": 3, "description": "4.1 light-years northwest of earth"}
{ "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."}
{ "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."}
{ "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."}
{ "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."}
{ "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."}
{ "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."}
{ "name": "Galaxy", "date":1658167836758, "datetime_tz":1658167836758, "datetime_notz":1658167836758, "kind": "Galaxy", "position": 6, "description": "The end of the Galaxy."}
3 changes: 2 additions & 1 deletion src/crate/testing/testdata/mappings/locations.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
create table locations (
name string primary key,
date timestamp,
datetime timestamp,
datetime_tz timestamp with time zone,
datetime_notz timestamp without time zone,
nullable_datetime timestamp,
nullable_date timestamp,
kind string,
Expand Down

0 comments on commit 1f5f30c

Please sign in to comment.