Example #1
0
 def run(self):
     token = HfFolder.get_token()
     if token is None:
         print("Not logged in")
         exit()
     HfFolder.delete_token()
     self._api.logout(token)
     print("Successfully logged out.")
Example #2
0
 def run(self):
     print(
         ANSI.red(
             "WARNING! `transformers-cli logout` is deprecated and will be removed in v5. Please use "
             "`huggingface-cli logout` instead."))
     token = HfFolder.get_token()
     if token is None:
         print("Not logged in")
         exit()
     HfFolder.delete_token()
     self._api.logout(token)
     print("Successfully logged out.")
Example #3
0
 def test_token_workflow(self):
     """
     Test the whole token save/get/delete workflow,
     with the desired behavior with respect to non-existent tokens.
     """
     token = "token-{}".format(int(time.time()))
     HfFolder.save_token(token)
     self.assertEqual(HfFolder.get_token(), token)
     HfFolder.delete_token()
     HfFolder.delete_token()
     # ^^ not an error, we test that the
     # second call does not fail.
     self.assertEqual(HfFolder.get_token(), None)
Example #4
0
 def run(self):
     token = HfFolder.get_token()
     if token is None:
         print("Not logged in")
         exit()
     HfFolder.delete_token()
     HfApi.unset_access_token()
     try:
         self._api.logout(token)
     except HTTPError as e:
         # Logging out with an access token will return a client error.
         if not e.response.status_code == 400:
             raise e
     print("Successfully logged out.")
 def test_token_workflow(self):
     """
     Test the whole token save/get/delete workflow,
     with the desired behavior with respect to non-existent tokens.
     """
     token = "token-{}".format(int(time.time()))
     HfFolder.save_token(token)
     self.assertEqual(HfFolder.get_token(), token)
     HfFolder.delete_token()
     HfFolder.delete_token()
     # ^^ not an error, we test that the
     # second call does not fail.
     self.assertEqual(HfFolder.get_token(), None)
     # test TOKEN in env
     self.assertEqual(HfFolder.get_token(), None)
     with unittest.mock.patch.dict(os.environ,
                                   {"HUGGING_FACE_HUB_TOKEN": token}):
         self.assertEqual(HfFolder.get_token(), token)
 def tearDownClass(cls) -> None:
     HfFolder.delete_token()
     cls._hf_folder_patch.stop()