Skip to content
Myr

test_structures.py

This file

Path

tests/test_structures.py

91 lines · 2.7 KiB · Python

Last changed by

Add tests for hasattr/getattr usage on LookupDict (#7401)Nate Prewittbefore adoption8f6cda9

History of this file

Take it

The walk stopped after 200 commits: lines older than 8812812 point at it.

Merge pull request #6519 from psf/dependabot/github_actions/actions/checkout-4.0.0Ian Stapleton Cordascobefore adoption8812812

lines 1–78why, one step back
1import pytest
23from requests.structures import CaseInsensitiveDict, LookupDict456class TestCaseInsensitiveDict:7 @pytest.fixture(autouse=True)8 def setup(self):9 """CaseInsensitiveDict instance with "Accept" header."""10 self.case_insensitive_dict = CaseInsensitiveDict()11 self.case_insensitive_dict["Accept"] = "application/json"1213 def test_list(self):14 assert list(self.case_insensitive_dict) == ["Accept"]1516 possible_keys = pytest.mark.parametrize(17 "key", ("accept", "ACCEPT", "aCcEpT", "Accept")18 )1920 @possible_keys21 def test_getitem(self, key):22 assert self.case_insensitive_dict[key] == "application/json"2324 @possible_keys25 def test_delitem(self, key):26 del self.case_insensitive_dict[key]27 assert key not in self.case_insensitive_dict2829 def test_lower_items(self):30 assert list(self.case_insensitive_dict.lower_items()) == [31 ("accept", "application/json")32 ]3334 def test_repr(self):35 assert repr(self.case_insensitive_dict) == "{'Accept': 'application/json'}"3637 def test_copy(self):38 copy = self.case_insensitive_dict.copy()39 assert copy is not self.case_insensitive_dict40 assert copy == self.case_insensitive_dict4142 @pytest.mark.parametrize(43 "other, result",44 (45 ({"AccePT": "application/json"}, True),46 ({}, False),47 (None, False),48 ),49 )50 def test_instance_equality(self, other, result):51 assert (self.case_insensitive_dict == other) is result525354class TestLookupDict:55 @pytest.fixture(autouse=True)56 def setup(self):57 """LookupDict instance with "bad_gateway" attribute."""58 self.lookup_dict = LookupDict("test")59 self.lookup_dict.bad_gateway = 5026061 def test_repr(self):62 assert repr(self.lookup_dict) == "<lookup 'test'>"6364 get_item_parameters = pytest.mark.parametrize(65 "key, value",66 (67 ("bad_gateway", 502),68 ("not_a_key", None),69 ),70 )7172 @get_item_parameters73 def test_getitem(self, key, value):74 assert self.lookup_dict[key] == value7576 @get_item_parameters77 def test_get(self, key, value):78 assert self.lookup_dict.get(key) == value

Add tests for hasattr/getattr usage on LookupDict (#7401)Nate Prewittbefore adoption8f6cda9

lines 79–91why, one step back
79
80 def test_hasattr(self):81 assert hasattr(self.lookup_dict, "bad_gateway") is True82 assert hasattr(self.lookup_dict, "not_a_key") is False8384 def test_getattr(self):85 assert getattr(self.lookup_dict, "bad_gateway") == 50286 with pytest.raises(AttributeError):87 getattr(self.lookup_dict, "not_a_key")8889 @get_item_parameters90 def test_getattr_default(self, key, value):91 assert getattr(self.lookup_dict, key, None) == value