From 0c88f54157a1a3b519be170db4f2c499dd2ff52c Mon Sep 17 00:00:00 2001 From: Justin Myers Date: Fri, 17 May 2024 18:54:18 -0700 Subject: [PATCH] Update Exceptions --- adafruit_requests.py | 6 +++--- tests/files_test.py | 2 +- tests/header_test.py | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/adafruit_requests.py b/adafruit_requests.py index 93fa943..8b0539e 100644 --- a/adafruit_requests.py +++ b/adafruit_requests.py @@ -395,7 +395,7 @@ def _build_boundary_data(self, files: dict): # pylint: disable=too-many-locals is_binary = False if not is_binary: - raise AttributeError("Files must be opened in binary mode") + raise ValueError("Files must be opened in binary mode") file_handle.seek(0, SEEK_END) content_length += file_handle.tell() @@ -419,12 +419,12 @@ def _build_boundary_string(): @staticmethod def _check_headers(headers: Dict[str, str]): if not isinstance(headers, dict): - raise AttributeError("Headers must be in dict format") + raise TypeError("Headers must be in dict format") for key, value in headers.items(): if isinstance(value, (str, bytes)) or value is None: continue - raise AttributeError( + raise TypeError( f"Header part ({value}) from {key} must be of type str or bytes, not {type(value)}" ) diff --git a/tests/files_test.py b/tests/files_test.py index 8299b1b..8cac77c 100644 --- a/tests/files_test.py +++ b/tests/files_test.py @@ -209,6 +209,6 @@ def test_post_files_not_binary(requests): ), } - with pytest.raises(AttributeError) as context: + with pytest.raises(ValueError) as context: requests.post("http://" + mocket.MOCK_HOST_1 + "/post", files=file_data) assert "Files must be opened in binary mode" in str(context) diff --git a/tests/header_test.py b/tests/header_test.py index ddfd61a..196deb6 100644 --- a/tests/header_test.py +++ b/tests/header_test.py @@ -9,13 +9,13 @@ def test_check_headers_not_dict(requests): - with pytest.raises(AttributeError) as context: + with pytest.raises(TypeError) as context: requests._check_headers("") assert "Headers must be in dict format" in str(context) def test_check_headers_not_valid(requests): - with pytest.raises(AttributeError) as context: + with pytest.raises(TypeError) as context: requests._check_headers( {"Good1": "a", "Good2": b"b", "Good3": None, "Bad1": True} )