From 1f5f30cf7b17503b76bd2c4c747804a91b1684ae Mon Sep 17 00:00:00 2001 From: Andreas Motl Date: Mon, 18 Jul 2022 21:49:18 +0200 Subject: [PATCH] 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. --- docs/query.rst | 5 ++-- src/crate/client/doctests/client.txt | 4 ++- .../client/sqlalchemy/doctests/itests.txt | 7 +++-- src/crate/client/tests.py | 3 ++- src/crate/testing/testdata/data/test_a.json | 26 +++++++++---------- .../testing/testdata/mappings/locations.sql | 3 ++- 6 files changed, 28 insertions(+), 20 deletions(-) diff --git a/docs/query.rst b/docs/query.rst index 4f0b22ac..10c6b42a 100644 --- a/docs/query.rst +++ b/docs/query.rst @@ -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), @@ -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/ diff --git a/src/crate/client/doctests/client.txt b/src/crate/client/doctests/client.txt index 08940820..109c7401 100644 --- a/src/crate/client/doctests/client.txt +++ b/src/crate/client/doctests/client.txt @@ -212,6 +212,7 @@ supported, all other fields are 'None':: >>> result = cursor.fetchone() >>> pprint(result) ['Aldebaran', + 1658167836758, 1658167836758, 1658167836758, None, @@ -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), diff --git a/src/crate/client/sqlalchemy/doctests/itests.txt b/src/crate/client/sqlalchemy/doctests/itests.txt index 1697f291..6f285610 100644 --- a/src/crate/client/sqlalchemy/doctests/itests.txt +++ b/src/crate/client/sqlalchemy/doctests/itests.txt @@ -80,7 +80,7 @@ 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:: @@ -88,7 +88,10 @@ Verify the return type of date and datetime:: >>> type(location.date) - >>> type(location.datetime) + >>> type(location.datetime_tz) + + + >>> type(location.datetime_notz) the location also has a date and datetime property which both are nullable and diff --git a/src/crate/client/tests.py b/src/crate/client/tests.py index b63da6d0..fe0a8300 100644 --- a/src/crate/client/tests.py +++ b/src/crate/client/tests.py @@ -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) diff --git a/src/crate/testing/testdata/data/test_a.json b/src/crate/testing/testdata/data/test_a.json index 1a5971b7..9435ffa3 100644 --- a/src/crate/testing/testdata/data/test_a.json +++ b/src/crate/testing/testdata/data/test_a.json @@ -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."} diff --git a/src/crate/testing/testdata/mappings/locations.sql b/src/crate/testing/testdata/mappings/locations.sql index 76bc62a3..3b2dabcd 100644 --- a/src/crate/testing/testdata/mappings/locations.sql +++ b/src/crate/testing/testdata/mappings/locations.sql @@ -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,