Skip to content
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
25 changes: 25 additions & 0 deletions promgen/tests/test_util.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright (c) 2026 LY Corporation
# These sources are released under the terms of the MIT license: see LICENSE

from django.test import SimpleTestCase
from requests import HTTPError
from requests.models import Response

from promgen import util


class UtilTest(SimpleTestCase):
def test_categorize_error(self):
response = Response()
response.status_code = 404

cases = [
(ImportError("missing dependency"), "import_error"),
(HTTPError(response=response), "404_http_error"),
(HTTPError(), "other_error"),
(ValueError("bad input"), "other_error"),
]

for error, expected in cases:
with self.subTest(error=type(error).__name__, expected=expected):
self.assertEqual(util.categorize_error(error), expected)
4 changes: 3 additions & 1 deletion promgen/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,9 @@ def categorize_error(e: Exception) -> str:
if isinstance(e, ImportError):
return "import_error"
elif isinstance(e, requests.HTTPError):
return str(e.response.status_code) + "_http_error" if e.response else "other_error"
return (
str(e.response.status_code) + "_http_error" if e.response is not None else "other_error"
)
else:
return "other_error"

Expand Down
Loading