This repository was archived by the owner on Mar 6, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 324
Expand file tree
/
Copy pathtest_remote_function_options.py
More file actions
145 lines (122 loc) · 4.52 KB
/
test_remote_function_options.py
File metadata and controls
145 lines (122 loc) · 4.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# -*- coding: utf-8 -*-
#
# Copyright 2023 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import pytest
ENDPOINT = "https://some.endpoint"
CONNECTION = "connection_string"
MAX_BATCHING_ROWS = 50
USER_DEFINED_CONTEXT = {
"foo": "bar",
}
@pytest.fixture
def target_class():
from google.cloud.bigquery.routine import RemoteFunctionOptions
return RemoteFunctionOptions
def test_ctor(target_class):
options = target_class(
endpoint=ENDPOINT,
connection=CONNECTION,
max_batching_rows=MAX_BATCHING_ROWS,
user_defined_context=USER_DEFINED_CONTEXT,
container_cpu="1.0",
container_memory="512M",
)
assert options.endpoint == ENDPOINT
assert options.connection == CONNECTION
assert options.max_batching_rows == MAX_BATCHING_ROWS
assert options.user_defined_context == USER_DEFINED_CONTEXT
assert options.container_cpu == "1.0"
assert options.container_memory == "512M"
def test_empty_ctor(target_class):
options = target_class()
assert options._properties == {}
options = target_class(_properties=None)
assert options._properties == {}
options = target_class(_properties={})
assert options._properties == {}
def test_ctor_bad_context(target_class):
with pytest.raises(ValueError, match="value must be dictionary"):
target_class(user_defined_context=[1, 2, 3, 4])
def test_from_api_repr(target_class):
resource = {
"endpoint": ENDPOINT,
"connection": CONNECTION,
"maxBatchingRows": MAX_BATCHING_ROWS,
"userDefinedContext": USER_DEFINED_CONTEXT,
"containerCpu": "1.0",
"containerMemory": "512M",
"someRandomField": "someValue",
}
options = target_class.from_api_repr(resource)
assert options.endpoint == ENDPOINT
assert options.connection == CONNECTION
assert options.max_batching_rows == MAX_BATCHING_ROWS
assert options.user_defined_context == USER_DEFINED_CONTEXT
assert options.container_cpu == "1.0"
assert options.container_memory == "512M"
assert options._properties["someRandomField"] == "someValue"
def test_from_api_repr_w_minimal_resource(target_class):
resource = {}
options = target_class.from_api_repr(resource)
assert options.endpoint is None
assert options.connection is None
assert options.max_batching_rows is None
assert options.user_defined_context is None
assert options.container_cpu is None
assert options.container_memory is None
def test_from_api_repr_w_unknown_fields(target_class):
resource = {"thisFieldIsNotInTheProto": "just ignore me"}
options = target_class.from_api_repr(resource)
assert options._properties is resource
def test_eq(target_class):
options = target_class(
endpoint=ENDPOINT,
connection=CONNECTION,
max_batching_rows=MAX_BATCHING_ROWS,
user_defined_context=USER_DEFINED_CONTEXT,
container_cpu="1.0",
container_memory="512M",
)
other_options = target_class(
endpoint=ENDPOINT,
connection=CONNECTION,
max_batching_rows=MAX_BATCHING_ROWS,
user_defined_context=USER_DEFINED_CONTEXT,
container_cpu="1.0",
container_memory="512M",
)
assert options == other_options
assert not (options != other_options)
empty_options = target_class()
assert not (options == empty_options)
assert options != empty_options
notanarg = object()
assert not (options == notanarg)
assert options != notanarg
def test_repr(target_class):
options = target_class(
endpoint=ENDPOINT,
connection=CONNECTION,
max_batching_rows=MAX_BATCHING_ROWS,
user_defined_context=USER_DEFINED_CONTEXT,
container_cpu="1.0",
container_memory="512M",
)
actual_repr = repr(options)
assert actual_repr == (
"RemoteFunctionOptions(connection='connection_string', container_cpu='1.0', "
"container_memory='512M', endpoint='https://some.endpoint', "
"max_batching_rows=50, user_defined_context={'foo': 'bar'})"
)