diff options
author | 2022-05-29 16:08:45 +0100 | |
---|---|---|
committer | 2022-05-29 16:08:45 +0100 | |
commit | 3fe10aa1e07fcdd8a2efb4a00118b7ec0fcdedce (patch) | |
tree | 5abae3d35fae552a73c6de8098de363830cadcff | |
parent | Raise ValueError if max_length greater than allowed by paste service (diff) |
Make small wording and style changes
-rw-r--r-- | bot/utils/services.py | 10 | ||||
-rw-r--r-- | tests/bot/utils/test_services.py | 5 |
2 files changed, 8 insertions, 7 deletions
diff --git a/bot/utils/services.py b/bot/utils/services.py index 82c7d284c..a752ac0ec 100644 --- a/bot/utils/services.py +++ b/bot/utils/services.py @@ -22,13 +22,13 @@ async def send_to_paste_service(contents: str, *, extension: str = "", max_lengt """ Upload `contents` to the paste service. - `extension` is added to the output URL. `max_length` can be used to limit the allowed contents length + Add `extension` to the output URL. Use `max_length` to limit the allowed contents length to lower than the maximum allowed by the paste service. - Raises `ValueError` if `max_length` is greater than the maximum allowed by the paste service. - Raises `PasteTooLongError` if contents is too long to upload, and `PasteUploadError` if uploading fails. + Raise `ValueError` if `max_length` is greater than the maximum allowed by the paste service. + Raise `PasteTooLongError` if `contents` is too long to upload, and `PasteUploadError` if uploading fails. - Returns the generated URL with the extension. + Return the generated URL with the extension. """ if max_length > MAX_PASTE_LENGTH: raise ValueError(f"`max_length` must not be greater than {MAX_PASTE_LENGTH}") @@ -80,4 +80,4 @@ async def send_to_paste_service(contents: str, *, extension: str = "", max_lengt f"trying again ({attempt}/{FAILED_REQUEST_ATTEMPTS})." ) - raise PasteUploadError("Failed to upload contents to pastebin") + raise PasteUploadError("Failed to upload contents to paste service") diff --git a/tests/bot/utils/test_services.py b/tests/bot/utils/test_services.py index e6b95be8e..d0e801299 100644 --- a/tests/bot/utils/test_services.py +++ b/tests/bot/utils/test_services.py @@ -79,11 +79,12 @@ class PasteTests(unittest.IsolatedAsyncioTestCase): self.assertLogs("bot.utils", logging.ERROR) async def test_raises_error_on_too_long_input(self): - contents = "a" * (MAX_PASTE_LENGTH+1) + """Ensure PasteTooLongError is raised if `contents` is longer than `MAX_PASTE_LENGTH`.""" + contents = "a" * (MAX_PASTE_LENGTH + 1) with self.assertRaises(PasteTooLongError): await send_to_paste_service(contents) async def test_raises_on_too_large_max_length(self): """Ensure ValueError is raised if `max_length` passed is greater than `MAX_PASTE_LENGTH`.""" with self.assertRaises(ValueError): - await send_to_paste_service("Hello World!", max_length=MAX_PASTE_LENGTH+1) + await send_to_paste_service("Hello World!", max_length=MAX_PASTE_LENGTH + 1) |