aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Leon Sandøy <[email protected]>2020-05-26 19:06:57 +0200
committerGravatar Leon Sandøy <[email protected]>2020-05-26 19:07:14 +0200
commit1ab34dd48fce2de70db1fb2dd6da06f752460829 (patch)
treeb3fab2600ee302edfb21323d2631b52bc3b7271a
parentSwap the order for the validate_cache checks. (diff)
Add a test for RuntimeErrors.
This just tests that the various RuntimeErrors are reachable - that includes the error about not having a bot instance, the one about not being a class attribute, and the one about not having instantiated the class. This test addresses a concern raised by @MarkKoz in a review. I've decided not to test that actual contents of these RuntimeErrors, because I believe that sort of testing is a bit too brittle. It shouldn't break a test just to change the content of an error string.
-rw-r--r--tests/bot/utils/test_redis_cache.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/tests/bot/utils/test_redis_cache.py b/tests/bot/utils/test_redis_cache.py
index 7405487ed..1b05ae350 100644
--- a/tests/bot/utils/test_redis_cache.py
+++ b/tests/bot/utils/test_redis_cache.py
@@ -215,3 +215,25 @@ class RedisCacheTests(unittest.IsolatedAsyncioTestCase):
await self.redis.set("stringthing", "stringthing")
with self.assertRaises(TypeError):
await self.redis.increment("stringthing")
+
+ async def test_exceptions_raised(self):
+ """Testing that the various RuntimeErrors are reachable."""
+ class MyCog:
+ cache = RedisCache()
+
+ def __init__(self):
+ self.other_cache = RedisCache()
+
+ cog = MyCog()
+
+ # Raises "No Bot instance"
+ with self.assertRaises(RuntimeError):
+ await cog.cache.get("john")
+
+ # Raises "RedisCache has no namespace"
+ with self.assertRaises(RuntimeError):
+ await cog.other_cache.get("was")
+
+ # Raises "You must access the RedisCache instance through the cog instance"
+ with self.assertRaises(RuntimeError):
+ await MyCog.cache.get("afraid")