Skip to content

Commit

Permalink
Merge pull request #193 from justmobilize/exception-type-updates
Browse files Browse the repository at this point in the history
Update Exceptions
  • Loading branch information
dhalbert committed May 18, 2024
2 parents d28ab9d + 0c88f54 commit fac4012
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions adafruit_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)}"
)

Expand Down
2 changes: 1 addition & 1 deletion tests/files_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
4 changes: 2 additions & 2 deletions tests/header_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}
)
Expand Down

0 comments on commit fac4012

Please sign in to comment.