2020-01-25 14:20:25 +01:00
|
|
|
import unittest
|
|
|
|
|
|
|
|
import util.store
|
|
|
|
|
2020-05-03 11:15:52 +02:00
|
|
|
|
2020-02-08 13:45:52 +01:00
|
|
|
class store(unittest.TestCase):
|
2020-01-25 14:20:25 +01:00
|
|
|
def setUp(self):
|
|
|
|
self.store = util.store.Store()
|
|
|
|
|
|
|
|
self.unusedKey = "someRandomUnusedKey"
|
|
|
|
self.someKey = "someRandomKey"
|
|
|
|
self.someOtherKey = "anotherRandomKey"
|
|
|
|
self.someValue = "someRandomValue"
|
|
|
|
self.someOtherValue = "anotherRandomValue"
|
|
|
|
|
|
|
|
def test_get_of_unset_key(self):
|
2020-05-03 11:15:52 +02:00
|
|
|
self.assertEqual(
|
|
|
|
None, self.store.get(self.unusedKey), "default value expected to be None"
|
|
|
|
)
|
|
|
|
self.assertEqual(
|
|
|
|
self.someValue,
|
|
|
|
self.store.get(self.unusedKey, self.someValue),
|
|
|
|
"wrong user-provided default value returned",
|
|
|
|
)
|
2020-01-25 14:20:25 +01:00
|
|
|
|
|
|
|
def test_get_of_set_key(self):
|
|
|
|
self.assertNotEqual(self.someValue, None)
|
|
|
|
|
|
|
|
self.store.set(self.someKey, self.someValue)
|
2020-05-03 11:15:52 +02:00
|
|
|
self.assertEqual(
|
|
|
|
self.someValue,
|
|
|
|
self.store.get(self.someKey),
|
|
|
|
"unexpected value for existing key",
|
|
|
|
)
|
2020-01-25 14:20:25 +01:00
|
|
|
|
|
|
|
def test_overwrite_set(self):
|
|
|
|
self.assertNotEqual(self.someValue, None)
|
|
|
|
self.assertNotEqual(self.someOtherValue, self.someValue)
|
|
|
|
|
|
|
|
self.store.set(self.someKey, self.someValue)
|
|
|
|
self.store.set(self.someKey, self.someOtherValue)
|
2020-05-03 11:15:52 +02:00
|
|
|
self.assertEqual(
|
|
|
|
self.someOtherValue,
|
|
|
|
self.store.get(self.someKey),
|
|
|
|
"unexpected value for existing key",
|
|
|
|
)
|
2020-01-25 14:20:25 +01:00
|
|
|
|
|
|
|
def test_unused_keys(self):
|
|
|
|
self.assertNotEqual(self.someKey, self.someOtherKey)
|
|
|
|
|
|
|
|
self.store.set(self.someKey, self.someValue)
|
|
|
|
self.store.set(self.someOtherKey, self.someOtherValue)
|
|
|
|
|
2020-05-03 11:15:52 +02:00
|
|
|
self.assertEqual(
|
|
|
|
sorted(self.store.unused_keys()), sorted([self.someKey, self.someOtherKey])
|
|
|
|
)
|
2020-01-25 14:20:25 +01:00
|
|
|
|
|
|
|
self.store.get(self.someKey)
|
|
|
|
self.assertEqual(self.store.unused_keys(), [self.someOtherKey])
|
|
|
|
|
2020-05-03 11:15:52 +02:00
|
|
|
|
2020-01-25 14:20:25 +01:00
|
|
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|