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_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)
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)
def test_user_provided_credentials(self): credentials = _make_credentials() env = EnvironmentVarGuard() env.set('KAGGLE_USER_SECRETS_TOKEN', 'foobar') env.set('KAGGLE_KERNEL_INTEGRATIONS', 'NATURAL_LANGUAGE') with env: init_natural_language() client = language.LanguageServiceClient(credentials=credentials) self.assertIsNotNone(client.credentials) self.assertNotIsInstance(client.credentials, KaggleKernelCredentials)