Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Exceptions #193

Merged
merged 1 commit into from
May 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading