aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorGravatar Leon Sandøy <[email protected]>2020-05-28 01:29:34 +0200
committerGravatar Leon Sandøy <[email protected]>2020-05-28 01:29:34 +0200
commitf66a63501fe1ef8fb5390dfbe42ae9f95ea2bc28 (patch)
tree0e462b216dd21d9434bfcb9ef0c2206aed7fc4be /tests
parentMake prefix consts private and more precise. (diff)
Add custom exceptions for each error state.
The bot can get into trouble in three distinct ways: - It has no Bot instance - It has no namespace - It has no parent instance. These happen only if you're using it wrong. To make the test more precise, and to add a little bit more readability (RuntimeError could be anything!), we'll introduce some custom exceptions for these three states. This addresses a review comment by @aeros.
Diffstat (limited to 'tests')
-rw-r--r--tests/bot/utils/test_redis_cache.py7
1 files changed, 4 insertions, 3 deletions
diff --git a/tests/bot/utils/test_redis_cache.py b/tests/bot/utils/test_redis_cache.py
index 4f95dff03..8c1a40640 100644
--- a/tests/bot/utils/test_redis_cache.py
+++ b/tests/bot/utils/test_redis_cache.py
@@ -4,6 +4,7 @@ import unittest
import fakeredis.aioredis
from bot.utils import RedisCache
+from bot.utils.redis_cache import NoBotInstanceError, NoNamespaceError, NoParentInstanceError
from tests import helpers
@@ -260,13 +261,13 @@ class RedisCacheTests(unittest.IsolatedAsyncioTestCase):
cog = MyCog()
# Raises "No Bot instance"
- with self.assertRaises(RuntimeError):
+ with self.assertRaises(NoBotInstanceError):
await cog.cache.get("john")
# Raises "RedisCache has no namespace"
- with self.assertRaises(RuntimeError):
+ with self.assertRaises(NoNamespaceError):
await cog.other_cache.get("was")
# Raises "You must access the RedisCache instance through the cog instance"
- with self.assertRaises(RuntimeError):
+ with self.assertRaises(NoParentInstanceError):
await MyCog.cache.get("afraid")