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_external_runtime_options.py
More file actions
157 lines (119 loc) · 5.15 KB
/
test_external_runtime_options.py
File metadata and controls
157 lines (119 loc) · 5.15 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
146
147
148
149
150
151
152
153
154
155
156
157
# -*- coding: utf-8 -*-
#
# Copyright 2024 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
@pytest.fixture
def target_class():
from google.cloud.bigquery.routine.routine import ExternalRuntimeOptions
return ExternalRuntimeOptions
@pytest.fixture
def object_under_test(target_class):
return target_class()
def test_ctor(target_class):
container_memory = "1G"
container_cpu = 1
runtime_connection = "projects/my-project/locations/us-central1/connections/my-connection"
max_batching_rows = 100
runtime_version = "python-3.11"
instance = target_class(
container_memory=container_memory,
container_cpu=container_cpu,
runtime_connection=runtime_connection,
max_batching_rows=max_batching_rows,
runtime_version=runtime_version,
)
assert instance.container_memory == container_memory
assert instance.container_cpu == container_cpu
assert instance.runtime_connection == runtime_connection
assert instance.max_batching_rows == max_batching_rows
assert instance.runtime_version == runtime_version
def test_container_memory(object_under_test):
container_memory = "512Mi"
object_under_test.container_memory = container_memory
assert object_under_test.container_memory == container_memory
def test_container_cpu(object_under_test):
container_cpu = 1
object_under_test.container_cpu = container_cpu
assert object_under_test.container_cpu == container_cpu
def test_runtime_connection(object_under_test):
runtime_connection = "projects/my-project/locations/us-central1/connections/my-connection"
object_under_test.runtime_connection = runtime_connection
assert object_under_test.runtime_connection == runtime_connection
def test_max_batching_rows(object_under_test):
max_batching_rows = 100
object_under_test.max_batching_rows = max_batching_rows
assert object_under_test.max_batching_rows == max_batching_rows
def test_runtime_version(object_under_test):
runtime_version = "python-3.11"
object_under_test.runtime_version = runtime_version
assert object_under_test.runtime_version == runtime_version
def test_from_api_repr(target_class):
resource = {
"containerMemory": "1G",
"containerCpu": 1,
"runtimeConnection": "projects/my-project/locations/us-central1/connections/my-connection",
"maxBatchingRows": "100",
"runtimeVersion": "python-3.11",
}
instance = target_class.from_api_repr(resource)
assert instance.container_memory == "1G"
assert instance.container_cpu == 1
assert (
instance.runtime_connection
== "projects/my-project/locations/us-central1/connections/my-connection"
)
assert instance.max_batching_rows == 100
assert instance.runtime_version == "python-3.11"
def test_to_api_repr(target_class):
instance = target_class(
container_memory="1G",
container_cpu=1,
runtime_connection="projects/my-project/locations/us-central1/connections/my-connection",
max_batching_rows=100,
runtime_version="python-3.11",
)
resource = instance.to_api_repr()
assert resource == {
"containerMemory": "1G",
"containerCpu": 1,
"runtimeConnection": "projects/my-project/locations/us-central1/connections/my-connection",
"maxBatchingRows": "100",
"runtimeVersion": "python-3.11",
}
def test_repr(target_class):
instance = target_class(
container_memory="1G",
container_cpu=1,
)
expected_repr = (
"ExternalRuntimeOptions(container_cpu=1, container_memory='1G', "
"max_batching_rows=None, runtime_connection=None, runtime_version=None)"
)
assert repr(instance) == expected_repr
def test_invalid_container_memory(object_under_test):
with pytest.raises(ValueError, match="container_memory must be a string or None."):
object_under_test.container_memory = 123
def test_invalid_container_cpu(object_under_test):
with pytest.raises(ValueError, match="container_cpu must be an integer or None."):
object_under_test.container_cpu = "1"
def test_invalid_runtime_connection(object_under_test):
with pytest.raises(ValueError, match="runtime_connection must be a string or None."):
object_under_test.runtime_connection = 123
def test_invalid_max_batching_rows(object_under_test):
with pytest.raises(ValueError, match="max_batching_rows must be an integer or None."):
object_under_test.max_batching_rows = "100"
def test_invalid_runtime_version(object_under_test):
with pytest.raises(ValueError, match="runtime_version must be a string or None."):
object_under_test.runtime_version = 123