FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
docker-python/tests/test_automl.py at master · HpcDataLab/docker-python · GitHub
HpcDataLab
/
docker-python
Public
forked from
Kaggle/docker-python
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
docker-python
/
tests
/
test_automl.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
137 lines (121 loc) · 6.48 KB
Breadcrumbs
docker-python
/
tests
/
test_automl.py
Copy path
File metadata and controls
137 lines (121 loc) · 6.48 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
import
unittest
from
unittest
.
mock
import
Mock
,
patch
from
kaggle_gcp
import
KaggleKernelCredentials
,
init_automl
from
test
.
support
import
EnvironmentVarGuard
from
google
.
cloud
import
storage
,
automl_v1beta1
,
automl
def
_make_credentials
():
import
google
.
auth
.
credentials
return
Mock
(
spec
=
google
.
auth
.
credentials
.
Credentials
)
class
TestAutoMl
(
unittest
.
TestCase
):
class
FakeClient
:
def
__init__
(
self
,
credentials
=
None
,
client_info
=
None
,
**
kwargs
):
self
.
credentials
=
credentials
class
FakeConnection
():
def
__init__
(
self
,
user_agent
):
self
.
user_agent
=
user_agent
if
(
client_info
is
not
None
):
self
.
_connection
=
FakeConnection
(
client_info
.
user_agent
)
@
patch
(
"google.cloud.automl.AutoMlClient"
,
new
=
FakeClient
)
def
test_user_provided_credentials
(
self
):
credentials
=
_make_credentials
()
env
=
EnvironmentVarGuard
()
env
.
set
(
'KAGGLE_USER_SECRETS_TOKEN'
,
'foobar'
)
env
.
set
(
'KAGGLE_KERNEL_INTEGRATIONS'
,
'CLOUDAI'
)
with
env
:
init_automl
()
client
=
automl
.
AutoMlClient
(
credentials
=
credentials
)
self
.
assertNotIsInstance
(
client
.
credentials
,
KaggleKernelCredentials
)
self
.
assertIsNotNone
(
client
.
credentials
)
def
test_tables_gcs_client
(
self
):
# The GcsClient can't currently be monkeypatched for default
# credentials because it requires a project which can't be set.
# Verify that creating an automl_v1beta1.GcsClient given an actual
# storage.Client sets the client properly.
gcs_client
=
storage
.
Client
(
project
=
"xyz"
,
credentials
=
_make_credentials
())
tables_gcs_client
=
automl_v1beta1
.
GcsClient
(
client
=
gcs_client
)
self
.
assertIs
(
tables_gcs_client
.
client
,
gcs_client
)
@
patch
(
"google.cloud.automl_v1beta1.gapic.auto_ml_client.AutoMlClient"
,
new
=
FakeClient
)
def
test_tables_client_credentials
(
self
):
credentials
=
_make_credentials
()
env
=
EnvironmentVarGuard
()
env
.
set
(
'KAGGLE_USER_SECRETS_TOKEN'
,
'foobar'
)
env
.
set
(
'KAGGLE_KERNEL_INTEGRATIONS'
,
'CLOUDAI'
)
with
env
:
init_automl
()
tables_client
=
automl_v1beta1
.
TablesClient
(
credentials
=
credentials
)
self
.
assertEqual
(
tables_client
.
auto_ml_client
.
credentials
,
credentials
)
@
patch
(
"google.cloud.automl.AutoMlClient"
,
new
=
FakeClient
)
def
test_default_credentials_automl_client
(
self
):
env
=
EnvironmentVarGuard
()
env
.
set
(
'KAGGLE_USER_SECRETS_TOKEN'
,
'foobar'
)
env
.
set
(
'KAGGLE_KERNEL_INTEGRATIONS'
,
'CLOUDAI'
)
with
env
:
init_automl
()
automl_client
=
automl
.
AutoMlClient
()
self
.
assertIsNotNone
(
automl_client
.
credentials
)
self
.
assertIsInstance
(
automl_client
.
credentials
,
KaggleKernelCredentials
)
self
.
assertTrue
(
automl_client
.
_connection
.
user_agent
.
startswith
(
"kaggle-gcp-client/1.0"
))
@
patch
(
"google.cloud.automl_v1beta1.AutoMlClient"
,
new
=
FakeClient
)
def
test_default_credentials_automl_v1beta1_client
(
self
):
env
=
EnvironmentVarGuard
()
env
.
set
(
'KAGGLE_USER_SECRETS_TOKEN'
,
'foobar'
)
env
.
set
(
'KAGGLE_KERNEL_INTEGRATIONS'
,
'CLOUDAI'
)
with
env
:
init_automl
()
automl_client
=
automl_v1beta1
.
AutoMlClient
()
self
.
assertIsNotNone
(
automl_client
.
credentials
)
self
.
assertIsInstance
(
automl_client
.
credentials
,
KaggleKernelCredentials
)
self
.
assertTrue
(
automl_client
.
_connection
.
user_agent
.
startswith
(
"kaggle-gcp-client/1.0"
))
@
patch
(
"google.cloud.automl_v1beta1.TablesClient"
,
new
=
FakeClient
)
def
test_default_credentials_tables_client
(
self
):
env
=
EnvironmentVarGuard
()
env
.
set
(
'KAGGLE_USER_SECRETS_TOKEN'
,
'foobar'
)
env
.
set
(
'KAGGLE_KERNEL_INTEGRATIONS'
,
'CLOUDAI'
)
with
env
:
init_automl
()
tables_client
=
automl_v1beta1
.
TablesClient
()
self
.
assertIsNotNone
(
tables_client
.
credentials
)
self
.
assertIsInstance
(
tables_client
.
credentials
,
KaggleKernelCredentials
)
self
.
assertTrue
(
tables_client
.
_connection
.
user_agent
.
startswith
(
"kaggle-gcp-client/1.0"
))
@
patch
(
"google.cloud.automl.PredictionServiceClient"
,
new
=
FakeClient
)
def
test_default_credentials_prediction_client
(
self
):
env
=
EnvironmentVarGuard
()
env
.
set
(
'KAGGLE_USER_SECRETS_TOKEN'
,
'foobar'
)
env
.
set
(
'KAGGLE_KERNEL_INTEGRATIONS'
,
'CLOUDAI'
)
with
env
:
prediction_client
=
automl
.
PredictionServiceClient
()
self
.
assertIsNotNone
(
prediction_client
.
credentials
)
self
.
assertIsInstance
(
prediction_client
.
credentials
,
KaggleKernelCredentials
)
self
.
assertTrue
(
prediction_client
.
_connection
.
user_agent
.
startswith
(
"kaggle-gcp-client/1.0"
))
@
patch
(
"google.cloud.automl_v1beta1.PredictionServiceClient"
,
new
=
FakeClient
)
def
test_default_credentials_prediction_v1beta1_client
(
self
):
env
=
EnvironmentVarGuard
()
env
.
set
(
'KAGGLE_USER_SECRETS_TOKEN'
,
'foobar'
)
env
.
set
(
'KAGGLE_KERNEL_INTEGRATIONS'
,
'CLOUDAI'
)
with
env
:
prediction_client
=
automl_v1beta1
.
PredictionServiceClient
()
self
.
assertIsNotNone
(
prediction_client
.
credentials
)
self
.
assertIsInstance
(
prediction_client
.
credentials
,
KaggleKernelCredentials
)
self
.
assertTrue
(
prediction_client
.
_connection
.
user_agent
.
startswith
(
"kaggle-gcp-client/1.0"
))
def
test_monkeypatching_idempotent
(
self
):
env
=
EnvironmentVarGuard
()
env
.
set
(
'KAGGLE_USER_SECRETS_TOKEN'
,
'foobar'
)
env
.
set
(
'KAGGLE_KERNEL_INTEGRATIONS'
,
'CLOUDAI'
)
with
env
:
client1
=
automl
.
AutoMlClient
.
__init__
init_automl
()
client2
=
automl
.
AutoMlClient
.
__init__
self
.
assertEqual
(
client1
,
client2
)
@
patch
(
"google.cloud.automl_v1beta1.PredictionServiceClient"
,
new
=
FakeClient
)
def
test_legacy_AUTOML_variable_v1beta1_client
(
self
):
"""
Tests previous KAGGLE_KERNEL_INTEGRATIONS="AUTOML" environment setting
"""
env
=
EnvironmentVarGuard
()
env
.
set
(
'KAGGLE_USER_SECRETS_TOKEN'
,
'foobar'
)
env
.
set
(
'KAGGLE_KERNEL_INTEGRATIONS'
,
'AUTOML'
)
with
env
:
prediction_client
=
automl_v1beta1
.
PredictionServiceClient
()
self
.
assertIsNotNone
(
prediction_client
.
credentials
)
self
.
assertIsInstance
(
prediction_client
.
credentials
,
KaggleKernelCredentials
)
self
.
assertTrue
(
prediction_client
.
_connection
.
user_agent
.
startswith
(
"kaggle-gcp-client/1.0"
))
Back
|
FazBrowse Home
|
New Git URL