-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[core] Make case insensitive dict public (#23206)
- Loading branch information
1 parent
3f0c457
commit a10c604
Showing
11 changed files
with
78 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# ------------------------------------ | ||
# Copyright (c) Microsoft Corporation. | ||
# Licensed under the MIT License. | ||
# ------------------------------------ | ||
import pytest | ||
from azure.core.utils import case_insensitive_dict | ||
|
||
@pytest.fixture() | ||
def accept_cases(): | ||
return ["accept", "Accept", "ACCEPT", "aCCePT"] | ||
|
||
def test_case_insensitive_dict_basic(accept_cases): | ||
my_dict = case_insensitive_dict({"accept": "application/json"}) | ||
for accept_case in accept_cases: | ||
assert my_dict[accept_case] == "application/json" | ||
|
||
def test_case_insensitive_dict_override(accept_cases): | ||
for accept_case in accept_cases: | ||
my_dict = case_insensitive_dict({accept_case: "should-not/be-me"}) | ||
my_dict["accept"] = "application/json" | ||
assert my_dict[accept_case] == my_dict["accept"] == "application/json" | ||
|
||
def test_case_insensitive_dict_initialization(): | ||
dict_response = { | ||
"platformUpdateDomainCount": 5, | ||
"platformFaultDomainCount": 3, | ||
"virtualMachines": [] | ||
} | ||
a = case_insensitive_dict(platformUpdateDomainCount=5, platformFaultDomainCount=3, virtualMachines=[]) | ||
b = case_insensitive_dict(zip(['platformUpdateDomainCount', 'platformFaultDomainCount', 'virtualMachines'], [5, 3, []])) | ||
c = case_insensitive_dict([('platformFaultDomainCount', 3), ('platformUpdateDomainCount', 5), ('virtualMachines', [])]) | ||
d = case_insensitive_dict({'virtualMachines': [], 'platformFaultDomainCount': 3, 'platformUpdateDomainCount': 5}) | ||
e = case_insensitive_dict({'platformFaultDomainCount': 3, 'virtualMachines': []}, platformUpdateDomainCount=5) | ||
f = case_insensitive_dict(dict_response) | ||
g = case_insensitive_dict(**dict_response) | ||
assert a == b == c == d == e == f == g | ||
dicts = [a, b, c, d, e, f, g] | ||
for d in dicts: | ||
assert len(d) == 3 | ||
assert d['platformUpdateDomainCount'] == d['platformupdatedomaincount'] == d['PLATFORMUPDATEDOMAINCOUNT'] == 5 | ||
assert d['platformFaultDomainCount'] == d['platformfaultdomaincount'] == d['PLATFORMFAULTDOMAINCOUNT'] == 3 | ||
assert d['virtualMachines'] == d['virtualmachines'] == d['VIRTUALMACHINES'] == [] |