fix test · googleapis/python-spanner@14f18f3 · GitHub | Latest TMZ Celebrity News & Gossip | Watch TMZ Live
Skip to content

Commit 14f18f3

Browse files
committed
fix test
1 parent 3432870 commit 14f18f3

File tree

3 files changed

+42
-85
lines changed

3 files changed

+42
-85
lines changed

google/cloud/spanner_v1/_helpers.py

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -343,23 +343,6 @@ def parse_num(s: str, suffix: str) -> int:
343343

344344
return cls(months=total_months, days=days, nanos=nanos)
345345

346-
347-
@dataclass
348-
class NullInterval:
349-
"""Represents a Spanner INTERVAL that may be NULL."""
350-
351-
interval: Interval
352-
valid: bool = True
353-
354-
def is_null(self) -> bool:
355-
return not self.valid
356-
357-
def __str__(self) -> str:
358-
if not self.valid:
359-
return "NULL"
360-
return str(self.interval)
361-
362-
363346
def _make_value_pb(value):
364347
"""Helper for :func:`_make_list_value_pbs`.
365348
@@ -417,10 +400,6 @@ def _make_value_pb(value):
417400
return Value(string_value=base64.b64encode(value))
418401
if isinstance(value, Interval):
419402
return Value(string_value=str(value))
420-
if isinstance(value, NullInterval):
421-
if value.is_null():
422-
return Value(null_value="NULL_VALUE")
423-
return Value(string_value=str(value.interval))
424403

425404
raise ValueError("Unknown type: %s" % (value,))
426405

tests/system/test_session_api.py

Lines changed: 42 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -2955,7 +2955,7 @@ def insert_test1(transaction):
29552955
keys, placeholders = get_param_info(
29562956
["key", "create_time", "expiry_time"], database_dialect
29572957
)
2958-
transaction.execute_sql(
2958+
transaction.execute_update(
29592959
f"""
29602960
INSERT INTO IntervalTable (key, create_time, expiry_time)
29612961
VALUES ({placeholders[0]}, {placeholders[1]}, {placeholders[2]})
@@ -2972,6 +2972,25 @@ def insert_test1(transaction):
29722972
},
29732973
)
29742974

2975+
def insert_test2(transaction):
2976+
keys, placeholders = get_param_info(["key", "create_time", "expiry_time"], database_dialect)
2977+
transaction.execute_update(
2978+
f"""
2979+
INSERT INTO IntervalTable (key, create_time, expiry_time)
2980+
VALUES ({placeholders[0]}, {placeholders[1]}, {placeholders[2]})
2981+
""",
2982+
params={
2983+
keys[0]: "test2",
2984+
keys[1]: datetime.datetime(2004, 8, 30, 4, 53, 54, tzinfo=UTC),
2985+
keys[2]: datetime.datetime(2004, 12, 15, 4, 53, 54, tzinfo=UTC),
2986+
},
2987+
param_types={
2988+
keys[0]: spanner_v1.param_types.STRING,
2989+
keys[1]: spanner_v1.param_types.TIMESTAMP,
2990+
keys[2]: spanner_v1.param_types.TIMESTAMP,
2991+
},
2992+
)
2993+
29752994
def test_computed_columns(transaction):
29762995
keys, placeholders = get_param_info(["key"], database_dialect)
29772996
results = list(
@@ -3003,34 +3022,13 @@ def test_interval_arithmetic(transaction):
30033022
assert interval.days == 1
30043023
assert interval.nanos == 0
30053024

3006-
def insert_test2(transaction):
3007-
keys, placeholders = get_param_info(
3008-
["key", "create_time", "expiry_time"], database_dialect
3009-
)
3010-
transaction.execute_sql(
3011-
f"""
3012-
INSERT INTO IntervalTable (key, create_time, expiry_time)
3013-
VALUES ({placeholders[0]}, {placeholders[1]}, {placeholders[2]})
3014-
""",
3015-
params={
3016-
keys[0]: "test2",
3017-
keys[1]: datetime.datetime(2004, 8, 30, 4, 53, 54, tzinfo=UTC),
3018-
keys[2]: datetime.datetime(2004, 12, 15, 4, 53, 54, tzinfo=UTC),
3019-
},
3020-
param_types={
3021-
keys[0]: spanner_v1.param_types.STRING,
3022-
keys[1]: spanner_v1.param_types.TIMESTAMP,
3023-
keys[2]: spanner_v1.param_types.TIMESTAMP,
3024-
},
3025-
)
3026-
30273025
def test_interval_timestamp_comparison(transaction):
30283026
timestamp = "2004-11-30T10:23:54+0530"
30293027
keys, placeholders = get_param_info(["interval"], database_dialect)
30303028
if database_dialect == DatabaseDialect.POSTGRESQL:
3031-
query = f"SELECT COUNT(*) FROM IntervalTable WHERE create_time < TIMESTAMPTZ %s - {placeholders[0]}"
3029+
query = f"SELECT COUNT(*) FROM IntervalTable WHERE create_time < TIMESTAMPTZ '%s' - {placeholders[0]}"
30323030
else:
3033-
query = f"SELECT COUNT(*) FROM IntervalTable WHERE create_time < TIMESTAMP(%s) - {placeholders[0]}"
3031+
query = f"SELECT COUNT(*) FROM IntervalTable WHERE create_time < TIMESTAMP('%s') - {placeholders[0]}"
30343032

30353033
results = list(
30363034
transaction.execute_sql(
@@ -3042,12 +3040,12 @@ def test_interval_timestamp_comparison(transaction):
30423040
assert len(results) == 1
30433041
assert results[0][0] == 1
30443042

3045-
def test_interval_array_param(transaction, database_dialect):
3043+
def test_interval_array_param(transaction):
30463044
intervals = [
30473045
Interval(months=14, days=3, nanos=14706000000000),
30483046
Interval(),
30493047
Interval(months=-14, days=-3, nanos=-14706000000000),
3050-
Interval(),
3048+
None,
30513049
]
30523050
keys, placeholders = get_param_info(["intervals"], database_dialect)
30533051
array_type = spanner_v1.Type(
@@ -3066,26 +3064,20 @@ def test_interval_array_param(transaction, database_dialect):
30663064
intervals = row[0]
30673065
assert len(intervals) == 4
30683066

3069-
# Check first interval
3070-
assert intervals[0].valid is True
3071-
assert intervals[0].interval.months == 14
3072-
assert intervals[0].interval.days == 3
3073-
assert intervals[0].interval.nanos == 14706000000000
3067+
assert intervals[0].months == 14
3068+
assert intervals[0].days == 3
3069+
assert intervals[0].nanos == 14706000000000
3070+
3071+
assert intervals[1].months == 0
3072+
assert intervals[1].days == 0
3073+
assert intervals[1].nanos == 0
30743074

3075-
assert intervals[1].valid is True
3076-
assert intervals[1].interval.months == 0
3077-
assert intervals[1].interval.days == 0
3078-
assert intervals[1].interval.nanos == 0
3075+
assert intervals[2].months == -14
3076+
assert intervals[2].days == -3
3077+
assert intervals[2].nanos == -14706000000000
30793078

3080-
assert intervals[2].valid is True
3081-
assert intervals[2].interval.months == -14
3082-
assert intervals[2].interval.days == -3
3083-
assert intervals[2].interval.nanos == -14706000000000
3079+
assert intervals[3] is None
30843080

3085-
assert intervals[3].valid is True
3086-
assert intervals[3].interval.months == 0
3087-
assert intervals[3].interval.days == 0
3088-
assert intervals[3].interval.nanos == 0
30893081

30903082
def test_interval_array_cast(transaction):
30913083
results = list(
@@ -3104,17 +3096,15 @@ def test_interval_array_cast(transaction):
31043096
intervals = row[0]
31053097
assert len(intervals) == 3
31063098

3107-
assert intervals[0].valid is True
3108-
assert intervals[0].interval.months == 14 # 1 year + 2 months
3109-
assert intervals[0].interval.days == 3
3110-
assert intervals[0].interval.nanos == 14706789123000 # 4h5m6.789123s in nanos
3099+
assert intervals[0].months == 14 # 1 year + 2 months
3100+
assert intervals[0].days == 3
3101+
assert intervals[0].nanos == 14706789123000 # 4h5m6.789123s in nanos
31113102

3112-
assert intervals[1].valid is False
3103+
assert intervals[1] is None
31133104

3114-
assert intervals[2].valid is True
3115-
assert intervals[2].interval.months == -14
3116-
assert intervals[2].interval.days == -3
3117-
assert intervals[2].interval.nanos == -14706789123000
3105+
assert intervals[2].months == -14
3106+
assert intervals[2].days == -3
3107+
assert intervals[2].nanos == -14706789123000
31183108

31193109
setup_table()
31203110
sessions_database.run_in_transaction(insert_test1)

tests/unit/test__helpers.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1200,18 +1200,6 @@ def test_zero_interval(self):
12001200
self.assertIsInstance(value_pb, Value)
12011201
self.assertEqual(value_pb.string_value, "P0Y")
12021202

1203-
def test_null_interval(self):
1204-
from google.protobuf.struct_pb2 import Value
1205-
from google.cloud.spanner_v1 import Type
1206-
from google.cloud.spanner_v1 import TypeCode
1207-
from google.cloud.spanner_v1._helpers import NullInterval, Interval
1208-
1209-
interval = NullInterval(interval=Interval(), valid=False)
1210-
field_type = Type(code=TypeCode.INTERVAL)
1211-
value_pb = self._callFUT(interval)
1212-
self.assertIsInstance(value_pb, Value)
1213-
self.assertTrue(value_pb.HasField("null_value"))
1214-
12151203

12161204
class Test_parse_interval(unittest.TestCase):
12171205
def _callFUT(self, *args, **kw):

0 commit comments

Comments
 (0)

TMZ Celebrity News – Breaking Stories, Videos & Gossip

Looking for the latest TMZ celebrity news? You've come to the right place. From shocking Hollywood scandals to exclusive videos, TMZ delivers it all in real time.

Whether it’s a red carpet slip-up, a viral paparazzi moment, or a legal drama involving your favorite stars, TMZ news is always first to break the story. Stay in the loop with daily updates, insider tips, and jaw-dropping photos.

🎥 Watch TMZ Live

TMZ Live brings you daily celebrity news and interviews straight from the TMZ newsroom. Don’t miss a beat—watch now and see what’s trending in Hollywood.