FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
docker-python/tests/test_natural_language.py at tf-base-image · HpcDataLab/docker-python · GitHub
HpcDataLab
docker-python
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
docker-python
/
tests
/
test_natural_language.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
67 lines (57 loc) · 2.64 KB
Breadcrumbs
docker-python
/
tests
/
test_natural_language.py
Copy path
File metadata and controls
67 lines (57 loc) · 2.64 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
import
unittest
import
inspect
from
unittest
.
mock
import
Mock
,
patch
from
kaggle_gcp
import
KaggleKernelCredentials
,
init_natural_language
from
test
.
support
import
EnvironmentVarGuard
from
google
.
cloud
import
language
def
_make_credentials
():
import
google
.
auth
.
credentials
return
Mock
(
spec
=
google
.
auth
.
credentials
.
Credentials
)
class
TestCloudNaturalLanguage
(
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.language.LanguageServiceClient"
,
new
=
FakeClient
)
def
test_default_credentials
(
self
):
env
=
EnvironmentVarGuard
()
env
.
set
(
'KAGGLE_USER_SECRETS_TOKEN'
,
'foobar'
)
env
.
set
(
'KAGGLE_KERNEL_INTEGRATIONS'
,
'CLOUDAI'
)
with
env
:
init_natural_language
()
client
=
language
.
LanguageServiceClient
()
self
.
assertIsNotNone
(
client
.
credentials
)
self
.
assertIsInstance
(
client
.
credentials
,
KaggleKernelCredentials
)
@
patch
(
"google.cloud.language.LanguageServiceClient"
,
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_natural_language
()
client
=
language
.
LanguageServiceClient
(
credentials
=
credentials
)
self
.
assertIsNotNone
(
client
.
credentials
)
self
.
assertNotIsInstance
(
client
.
credentials
,
KaggleKernelCredentials
)
def
test_monkeypatching_succeed
(
self
):
env
=
EnvironmentVarGuard
()
env
.
set
(
'KAGGLE_USER_SECRETS_TOKEN'
,
'foobar'
)
env
.
set
(
'KAGGLE_KERNEL_INTEGRATIONS'
,
'CLOUDAI'
)
with
env
:
init_natural_language
()
client
=
language
.
LanguageServiceClient
.
__init__
self
.
assertTrue
(
"kaggle_gcp"
in
inspect
.
getsourcefile
(
client
))
def
test_monkeypatching_idempotent
(
self
):
env
=
EnvironmentVarGuard
()
env
.
set
(
'KAGGLE_USER_SECRETS_TOKEN'
,
'foobar'
)
env
.
set
(
'KAGGLE_KERNEL_INTEGRATIONS'
,
'CLOUDAI'
)
with
env
:
init_natural_language
()
client1
=
language
.
LanguageServiceClient
.
__init__
init_natural_language
()
client2
=
language
.
LanguageServiceClient
.
__init__
self
.
assertEqual
(
client1
,
client2
)
Back
|
FazBrowse Home
|
New Git URL