Skip to content

Commit 0c88f54

Browse files
committed
Update Exceptions
1 parent d28ab9d commit 0c88f54

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

adafruit_requests.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ def _build_boundary_data(self, files: dict): # pylint: disable=too-many-locals
395395
is_binary = False
396396

397397
if not is_binary:
398-
raise AttributeError("Files must be opened in binary mode")
398+
raise ValueError("Files must be opened in binary mode")
399399

400400
file_handle.seek(0, SEEK_END)
401401
content_length += file_handle.tell()
@@ -419,12 +419,12 @@ def _build_boundary_string():
419419
@staticmethod
420420
def _check_headers(headers: Dict[str, str]):
421421
if not isinstance(headers, dict):
422-
raise AttributeError("Headers must be in dict format")
422+
raise TypeError("Headers must be in dict format")
423423

424424
for key, value in headers.items():
425425
if isinstance(value, (str, bytes)) or value is None:
426426
continue
427-
raise AttributeError(
427+
raise TypeError(
428428
f"Header part ({value}) from {key} must be of type str or bytes, not {type(value)}"
429429
)
430430

tests/files_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,6 @@ def test_post_files_not_binary(requests):
209209
),
210210
}
211211

212-
with pytest.raises(AttributeError) as context:
212+
with pytest.raises(ValueError) as context:
213213
requests.post("http://" + mocket.MOCK_HOST_1 + "/post", files=file_data)
214214
assert "Files must be opened in binary mode" in str(context)

tests/header_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99

1010

1111
def test_check_headers_not_dict(requests):
12-
with pytest.raises(AttributeError) as context:
12+
with pytest.raises(TypeError) as context:
1313
requests._check_headers("")
1414
assert "Headers must be in dict format" in str(context)
1515

1616

1717
def test_check_headers_not_valid(requests):
18-
with pytest.raises(AttributeError) as context:
18+
with pytest.raises(TypeError) as context:
1919
requests._check_headers(
2020
{"Good1": "a", "Good2": b"b", "Good3": None, "Bad1": True}
2121
)

0 commit comments

Comments
 (0)