MCPcopy Create free account
hub / github.com/Kaggle/docker-python / TestCloudVision

Class TestCloudVision

tests/test_vision.py:14–66  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

12 return Mock(spec=google.auth.credentials.Credentials)
13
14class TestCloudVision(unittest.TestCase):
15 class FakeClient:
16 def __init__(self, credentials=None, client_info=None, **kwargs):
17 self.credentials = credentials
18
19 class FakeConnection():
20 def __init__(self, user_agent):
21 self.user_agent = user_agent
22 if (client_info is not None):
23 self._connection = FakeConnection(client_info.user_agent)
24
25 @patch("google.cloud.vision.ImageAnnotatorClient", new=FakeClient)
26 def test_default_credentials(self):
27 env = EnvironmentVarGuard()
28 env.set('KAGGLE_USER_SECRETS_TOKEN', 'foobar')
29 env.set('KAGGLE_KERNEL_INTEGRATIONS', 'CLOUDAI')
30 with env:
31 init_vision()
32 client = vision.ImageAnnotatorClient()
33 self.assertIsNotNone(client.credentials)
34 self.assertIsInstance(client.credentials, KaggleKernelCredentials)
35
36 @patch("google.cloud.vision.ImageAnnotatorClient", new=FakeClient)
37 def test_user_provided_credentials(self):
38 credentials = _make_credentials()
39 env = EnvironmentVarGuard()
40 env.set('KAGGLE_USER_SECRETS_TOKEN', 'foobar')
41 env.set('KAGGLE_KERNEL_INTEGRATIONS', 'CLOUDAI')
42 with env:
43 init_vision()
44 client = vision.ImageAnnotatorClient(credentials=credentials)
45 self.assertNotIsInstance(client.credentials, KaggleKernelCredentials)
46 self.assertIsNotNone(client.credentials)
47
48 def test_monkeypatching_succeed(self):
49 env = EnvironmentVarGuard()
50 env.set('KAGGLE_USER_SECRETS_TOKEN', 'foobar')
51 env.set('KAGGLE_KERNEL_INTEGRATIONS', 'CLOUDAI')
52 with env:
53 init_vision()
54 client = vision.ImageAnnotatorClient.__init__
55 self.assertTrue("kaggle_gcp" in inspect.getsourcefile(client))
56
57 def test_monkeypatching_idempotent(self):
58 env = EnvironmentVarGuard()
59 env.set('KAGGLE_USER_SECRETS_TOKEN', 'foobar')
60 env.set('KAGGLE_KERNEL_INTEGRATIONS', 'CLOUDAI')
61 with env:
62 init_vision()
63 client1 = vision.ImageAnnotatorClient.__init__
64 init_vision()
65 client2 = vision.ImageAnnotatorClient.__init__
66 self.assertEqual(client1, client2)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected