Skip to content

Commit 9526cc2

Browse files
authored
Merge pull request #5 from q-logic/fix-472
fix: Couple of tests are permanently broken while running locally
2 parents c477cc2 + 216a92b commit 9526cc2

File tree

1 file changed

+32
-53
lines changed

1 file changed

+32
-53
lines changed

tests/spanner_dbapi/test_types.py

Lines changed: 32 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# https://developers.google.com/open-source/licenses/bsd
66

77
import datetime
8+
import time
89
from unittest import TestCase
910

1011
from google.cloud.spanner_dbapi.types import (
@@ -17,69 +18,47 @@
1718
)
1819
from google.cloud.spanner_dbapi.utils import PeekIterator
1920

20-
tzUTC = 0 # 0 hours offset from UTC
21-
21+
utcOffset = time.timezone # offset for current timezone
2222

2323
class TypesTests(TestCase):
2424
def test_Date(self):
25-
got = Date(2019, 11, 3)
26-
want = datetime.date(2019, 11, 3)
27-
self.assertEqual(got, want, "mismatch between conversion")
25+
actual = Date(2019, 11, 3)
26+
expected = datetime.date(2019, 11, 3)
27+
self.assertEqual(actual, expected, "mismatch between conversion")
2828

2929
def test_Time(self):
30-
got = Time(23, 8, 19)
31-
want = datetime.time(23, 8, 19)
32-
self.assertEqual(got, want, "mismatch between conversion")
30+
actual = Time(23, 8, 19)
31+
expected = datetime.time(23, 8, 19)
32+
self.assertEqual(actual, expected, "mismatch between conversion")
3333

3434
def test_Timestamp(self):
35-
got = Timestamp(2019, 11, 3, 23, 8, 19)
36-
want = datetime.datetime(2019, 11, 3, 23, 8, 19)
37-
self.assertEqual(got, want, "mismatch between conversion")
35+
actual = Timestamp(2019, 11, 3, 23, 8, 19)
36+
expected = datetime.datetime(2019, 11, 3, 23, 8, 19)
37+
self.assertEqual(actual, expected, "mismatch between conversion")
3838

3939
def test_DateFromTicks(self):
40-
epochTicks = 1572851662.9782631 # Sun Nov 03 23:14:22 2019
41-
got = DateFromTicks(epochTicks)
42-
# Since continuous integration infrastructure such as Travis CI
43-
# uses clocks on UTC, it is useful to be able to compare against
44-
# either of UTC or the known standard time.
45-
want = (
46-
datetime.date(2019, 11, 3),
47-
datetime.datetime(2019, 11, 4, tzUTC).date(),
48-
)
49-
matches = got in want
50-
self.assertTrue(
51-
matches, "`%s` not present in any of\n`%s`" % (got, want)
52-
)
40+
epochTicks = 1572822862 # Sun Nov 03 23:14:22 2019 GMT
41+
42+
actual = DateFromTicks(epochTicks + utcOffset)
43+
expected = datetime.date(2019, 11, 3)
44+
45+
self.assertEqual(actual, expected, "mismatch between conversion")
5346

5447
def test_TimeFromTicks(self):
55-
epochTicks = 1572851662.9782631 # Sun Nov 03 23:14:22 2019
56-
got = TimeFromTicks(epochTicks)
57-
# Since continuous integration infrastructure such as Travis CI
58-
# uses clocks on UTC, it is useful to be able to compare against
59-
# either of UTC or the known standard time.
60-
want = (
61-
datetime.time(23, 14, 22),
62-
datetime.datetime(2019, 11, 4, 7, 14, 22, tzUTC).time(),
63-
)
64-
matches = got in want
65-
self.assertTrue(
66-
matches, "`%s` not present in any of\n`%s`" % (got, want)
67-
)
48+
epochTicks = 1572822862 # Sun Nov 03 23:14:22 2019 GMT
49+
50+
actual = TimeFromTicks(epochTicks + utcOffset)
51+
expected = datetime.time(23, 14, 22)
52+
53+
self.assertEqual(actual, expected, "mismatch between conversion")
6854

6955
def test_TimestampFromTicks(self):
70-
epochTicks = 1572851662.9782631 # Sun Nov 03 23:14:22 2019
71-
got = TimestampFromTicks(epochTicks)
72-
# Since continuous integration infrastructure such as Travis CI
73-
# uses clocks on UTC, it is useful to be able to compare against
74-
# either of UTC or the known standard time.
75-
want = (
76-
datetime.datetime(2019, 11, 3, 23, 14, 22),
77-
datetime.datetime(2019, 11, 4, 7, 14, 22, tzUTC),
78-
)
79-
matches = got in want
80-
self.assertTrue(
81-
matches, "`%s` not present in any of\n`%s`" % (got, want)
82-
)
56+
epochTicks = 1572822862 # Sun Nov 03 23:14:22 2019 GMT
57+
58+
actual = TimestampFromTicks(epochTicks + utcOffset)
59+
expected = datetime.datetime(2019, 11, 3, 23, 14, 22)
60+
61+
self.assertEqual(actual, expected, "mismatch between conversion")
8362

8463
def test_PeekIterator(self):
8564
cases = [
@@ -90,8 +69,8 @@ def test_PeekIterator(self):
9069
("no_args", (), []),
9170
]
9271

93-
for name, data_in, want in cases:
72+
for name, data_in, expected in cases:
9473
with self.subTest(name=name):
9574
pitr = PeekIterator(data_in)
96-
got = list(pitr)
97-
self.assertEqual(got, want)
75+
actual = list(pitr)
76+
self.assertEqual(actual, expected)

0 commit comments

Comments
 (0)