aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorGravatar Leon Sandøy <[email protected]>2020-05-23 15:17:57 +0200
committerGravatar Leon Sandøy <[email protected]>2020-05-23 15:17:57 +0200
commit5120717a47c07812d1631cf0905ff3062e139487 (patch)
tree9da658952b14728a682be4b824a3940d95f8078d /tests
parentDon't rely on HDEL ignoring keys for .pop (diff)
DRY approach to typestring prefix resolution
Thanks to @kwzrd for this idea, basically we're making a constant with the typestring prefixes and iterating that in all our converters. These converter functions will also now raise TypeErrors if we try to convert something that isn't in this constants list. I've also added a new test that tests this functionality.
Diffstat (limited to 'tests')
-rw-r--r--tests/bot/utils/test_redis_cache.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/tests/bot/utils/test_redis_cache.py b/tests/bot/utils/test_redis_cache.py
index 2ce57499a..150195726 100644
--- a/tests/bot/utils/test_redis_cache.py
+++ b/tests/bot/utils/test_redis_cache.py
@@ -152,3 +152,24 @@ class RedisCacheTests(unittest.IsolatedAsyncioTestCase):
"mega": "hungry, though",
}
self.assertDictEqual(await self.redis.to_dict(), result)
+
+ def test_typestring_conversion(self):
+ """Test the typestring-related helper functions."""
+ conversion_tests = (
+ (12, "i|12"),
+ (12.4, "f|12.4"),
+ ("cowabunga", "s|cowabunga"),
+ )
+
+ # Test conversion to typestring
+ for _input, expected in conversion_tests:
+ self.assertEqual(self.redis._to_typestring(_input), expected)
+
+ # Test conversion from typestrings
+ for _input, expected in conversion_tests:
+ self.assertEqual(self.redis._from_typestring(expected), _input)
+
+ # Test that exceptions are raised on invalid input
+ with self.assertRaises(TypeError):
+ self.redis._to_typestring(["internet"])
+ self.redis._from_typestring("o|firedog")