def test_storage_nesting(): storage = Storage('/tmp/thebot.storage') storage.clear() first = storage.with_prefix('first:') second = storage.with_prefix('second:') eq_([], storage.keys()) first['blah'] = 'minor' second['one'] = {'some': 'dict'} eq_(['first:blah', 'second:one'], sorted(storage.keys())) eq_(['first:blah'], sorted(first.keys())) eq_(['second:one'], sorted(second.keys())) eq_('minor', first['blah']) assert_raises(KeyError, lambda: second['blah']) first.clear() eq_(['second:one'], sorted(storage.keys()))
def test_storage_with_prefix_keeps_global_objects(): storage = Storage('/tmp/thebot.storage', global_objects=dict(some='value')) prefixed = storage.with_prefix('nested:') eq_(storage.global_objects, prefixed.global_objects)