Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: permanently broken date & time tests #524

Merged
merged 22 commits into from Oct 2, 2020
Merged
Changes from 21 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
11222db
feat: release 2.2a0 (#457)
larkee May 26, 2020
5551b58
feat: [WIP] The first stage of `nox` implementation (#468)
mf2199 Aug 25, 2020
bfde221
feat: refactor connect() function, cover it with unit tests (#462)
Aug 27, 2020
e017901
feat: Stage 2 of `nox` implementation - adding `docs` target (#473)
mf2199 Aug 29, 2020
144bdc2
fix: Fix black, isort compatibility (#469)
c24t Aug 31, 2020
7a1f6a6
feat: Stage 3-4 of `nox` implementation - adding auto-format targets …
mf2199 Aug 31, 2020
acd9209
feat: Stage 5 of `nox` implementation - adding coverage targets (#479)
mf2199 Aug 31, 2020
6028f88
feat: cursor must detect if the parent connection is closed (#463)
Sep 1, 2020
94ba284
feat: Stage 6 of `nox` implementation - enabling system tests (#480)
mf2199 Sep 8, 2020
59eb432
chore: Code refactoring to follow common Google API scheme - Stage I …
mf2199 Sep 14, 2020
048566c
chore: release 2.2a1 (#499)
c24t Sep 15, 2020
f5719f8
Merge branch 'master' of https://github.com/googleapis/python-spanner…
Sep 15, 2020
2c0c0a2
fix: Couple of tests are permanently broken while running locally
tina80lvl Sep 21, 2020
05bf7dc
fix: offset for current timezone
tina80lvl Sep 22, 2020
31185df
clean: whitespace
tina80lvl Sep 22, 2020
bd605a5
fix: localtime->gmtime
tina80lvl Sep 25, 2020
23f87ad
fix: gmtime->localtime
tina80lvl Sep 25, 2020
216a92b
refactor
tina80lvl Sep 30, 2020
bca6e0e
fix: lint
mf2199 Sep 30, 2020
4930aa2
Merge branch 'master' into fix-472
mf2199 Sep 30, 2020
37abcc6
test: re-trigger hanging kokoro test
mf2199 Sep 30, 2020
c46bf07
Merge branch 'master' into fix-472
Oct 1, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
85 changes: 33 additions & 52 deletions tests/spanner_dbapi/test_types.py
Expand Up @@ -5,6 +5,7 @@
# https://developers.google.com/open-source/licenses/bsd

import datetime
import time
from unittest import TestCase

from google.cloud.spanner_dbapi.types import (
Expand All @@ -17,69 +18,49 @@
)
from google.cloud.spanner_dbapi.utils import PeekIterator

tzUTC = 0 # 0 hours offset from UTC

utcOffset = time.timezone # offset for current timezone


class TypesTests(TestCase):
def test_Date(self):
got = Date(2019, 11, 3)
want = datetime.date(2019, 11, 3)
self.assertEqual(got, want, "mismatch between conversion")
actual = Date(2019, 11, 3)
expected = datetime.date(2019, 11, 3)
self.assertEqual(actual, expected, "mismatch between conversion")

def test_Time(self):
got = Time(23, 8, 19)
want = datetime.time(23, 8, 19)
self.assertEqual(got, want, "mismatch between conversion")
actual = Time(23, 8, 19)
expected = datetime.time(23, 8, 19)
self.assertEqual(actual, expected, "mismatch between conversion")

def test_Timestamp(self):
got = Timestamp(2019, 11, 3, 23, 8, 19)
want = datetime.datetime(2019, 11, 3, 23, 8, 19)
self.assertEqual(got, want, "mismatch between conversion")
actual = Timestamp(2019, 11, 3, 23, 8, 19)
expected = datetime.datetime(2019, 11, 3, 23, 8, 19)
self.assertEqual(actual, expected, "mismatch between conversion")

def test_DateFromTicks(self):
epochTicks = 1572851662.9782631 # Sun Nov 03 23:14:22 2019
got = DateFromTicks(epochTicks)
# Since continuous integration infrastructure such as Travis CI
# uses clocks on UTC, it is useful to be able to compare against
# either of UTC or the known standard time.
want = (
datetime.date(2019, 11, 3),
datetime.datetime(2019, 11, 4, tzUTC).date(),
)
matches = got in want
self.assertTrue(
matches, "`%s` not present in any of\n`%s`" % (got, want)
)
epochTicks = 1572822862 # Sun Nov 03 23:14:22 2019 GMT

actual = DateFromTicks(epochTicks + utcOffset)
expected = datetime.date(2019, 11, 3)

self.assertEqual(actual, expected, "mismatch between conversion")

def test_TimeFromTicks(self):
epochTicks = 1572851662.9782631 # Sun Nov 03 23:14:22 2019
got = TimeFromTicks(epochTicks)
# Since continuous integration infrastructure such as Travis CI
# uses clocks on UTC, it is useful to be able to compare against
# either of UTC or the known standard time.
want = (
datetime.time(23, 14, 22),
datetime.datetime(2019, 11, 4, 7, 14, 22, tzUTC).time(),
)
matches = got in want
self.assertTrue(
matches, "`%s` not present in any of\n`%s`" % (got, want)
)
epochTicks = 1572822862 # Sun Nov 03 23:14:22 2019 GMT

actual = TimeFromTicks(epochTicks + utcOffset)
expected = datetime.time(23, 14, 22)

self.assertEqual(actual, expected, "mismatch between conversion")

def test_TimestampFromTicks(self):
epochTicks = 1572851662.9782631 # Sun Nov 03 23:14:22 2019
got = TimestampFromTicks(epochTicks)
# Since continuous integration infrastructure such as Travis CI
# uses clocks on UTC, it is useful to be able to compare against
# either of UTC or the known standard time.
want = (
datetime.datetime(2019, 11, 3, 23, 14, 22),
datetime.datetime(2019, 11, 4, 7, 14, 22, tzUTC),
)
matches = got in want
self.assertTrue(
matches, "`%s` not present in any of\n`%s`" % (got, want)
)
epochTicks = 1572822862 # Sun Nov 03 23:14:22 2019 GMT

actual = TimestampFromTicks(epochTicks + utcOffset)
expected = datetime.datetime(2019, 11, 3, 23, 14, 22)

self.assertEqual(actual, expected, "mismatch between conversion")

def test_PeekIterator(self):
cases = [
Expand All @@ -90,8 +71,8 @@ def test_PeekIterator(self):
("no_args", (), []),
]

for name, data_in, want in cases:
for name, data_in, expected in cases:
with self.subTest(name=name):
pitr = PeekIterator(data_in)
got = list(pitr)
self.assertEqual(got, want)
actual = list(pitr)
self.assertEqual(actual, expected)