File: test_pickling.py

package info (click to toggle)
python-azure 20250603%2Bgit-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 851,724 kB
  • sloc: python: 7,362,925; ansic: 804; javascript: 287; makefile: 195; sh: 145; xml: 109
file content (33 lines) | stat: -rw-r--r-- 1,098 bytes parent folder | download
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
# ------------------------------------
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# ------------------------------------
import pickle
from azure.identity import DefaultAzureCredential, SharedTokenCacheCredential
from azure.identity._internal.msal_credentials import MsalCredential


def test_pickle_dac():
    cred = DefaultAzureCredential()
    with open("data.pkl", "wb") as outfile:
        pickle.dump(cred, outfile)
    with open("data.pkl", "rb") as infile:
        data_loaded = pickle.load(infile)


def test_pickle_shared_token_cache():
    cred = SharedTokenCacheCredential()
    cred._credential._initialize_cache()
    with open("data.pkl", "wb") as outfile:
        pickle.dump(cred, outfile)
    with open("data.pkl", "rb") as infile:
        data_loaded = pickle.load(infile)


def test_pickle_msal_credential():
    cred = MsalCredential(client_id="CLIENT_ID")
    app = cred._get_app()
    with open("data.pkl", "wb") as outfile:
        pickle.dump(cred, outfile)
    with open("data.pkl", "rb") as infile:
        data_loaded = pickle.load(infile)