Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion powersimdata/utility/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def put(self, key, obj):
:param tuple key: a tuple used to lookup the cached value
:param Any obj: the object to cache
"""
self._cache[key] = obj
self._cache[key] = copy.deepcopy(obj)

def get(self, key):
"""Retrieve the value associated with key if it exists.
Expand Down
11 changes: 11 additions & 0 deletions powersimdata/utility/tests/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,17 @@ def test_mem_cache_get_returns_copy():
assert id(cache.get(key)) != id(obj)


def test_mem_cache_put_version_never_changes():
cache = MemoryCache()
key = cache_key("foo", 4)
obj = {"key1": "value1"}
cache.put(key, obj)
obj["key2"] = "value2"
assert "key1" in cache.get(key)
assert "key2" not in cache.get(key)
assert "key2" in obj


def test_copy_command():
expected = r"\cp -p source dest"
command = CommandBuilder.copy("source", "dest")
Expand Down