示例#1
0
 def test_default_credentials_v2(self):
     env = EnvironmentVarGuard()
     env.set('KAGGLE_USER_SECRETS_TOKEN', 'foobar')
     env.set('KAGGLE_KERNEL_INTEGRATIONS', 'CLOUDAI')
     with env:
         init_translation_v2()
         client = translate_v2.Client()
         self.assertIsNotNone(client.credentials)
         self.assertIsInstance(client.credentials, KaggleKernelCredentials)
示例#2
0
 def test_user_provided_credentials_v2(self):
     credentials = _make_credentials()
     env = EnvironmentVarGuard()
     env.set('KAGGLE_USER_SECRETS_TOKEN', 'foobar')
     env.set('KAGGLE_KERNEL_INTEGRATIONS', 'TRANSLATION')
     with env:
         init_translation_v2()
         client = translate_v2.Client(credentials=credentials)
         self.assertIsNotNone(client.credentials)
         self.assertNotIsInstance(client.credentials, KaggleKernelCredentials)
示例#3
0
 def test_monkeypatching_succeed(self):
     env = EnvironmentVarGuard()
     env.set('KAGGLE_USER_SECRETS_TOKEN', 'foobar')
     env.set('KAGGLE_KERNEL_INTEGRATIONS', 'CLOUDAI')
     with env:
         init_translation_v2()
         init_translation_v3()
         # Translation V2
         client2 = translate_v2.Client.__init__
         self.assertTrue("kaggle_gcp" in inspect.getsourcefile(client2))
         # Translation V3
         client3 = translate.TranslationServiceClient.__init__
         self.assertTrue("kaggle_gcp" in inspect.getsourcefile(client3))
示例#4
0
    def test_monkeypatching_idempotent(self):
        env = EnvironmentVarGuard()
        env.set('KAGGLE_USER_SECRETS_TOKEN', 'foobar')
        env.set('KAGGLE_KERNEL_INTEGRATIONS', 'CLOUDAI')
        with env:
            init_translation_v2()
            init_translation_v3()
            # Translation V2
            client2_1 = translate_v2.client.Client.__init__
            # Translation V3
            client3_1 = translate.TranslationServiceClient.__init__

            init_translation_v2()
            init_translation_v3()

            client2_2 = translate_v2.Client.__init__
            client3_2 = translate.TranslationServiceClient.__init__
            self.assertEqual(client2_1, client2_2)
            self.assertEqual(client3_1, client3_2)