Fixed #20: I can parse simple concepts
This commit is contained in:
@@ -142,7 +142,7 @@ class TestDictionaryCache(BaseTest):
|
||||
assert cache.get("key") is NotFound
|
||||
assert cache._cache == {}
|
||||
|
||||
def test_auto_configure_retrieves_the_whole_remote_repository(self, sdp, context):
|
||||
def test_auto_configure_retrieves_the_whole_remote_repository(self, context, sdp):
|
||||
cache = DictionaryCache(sdp=sdp).auto_configure("test")
|
||||
with sdp.get_transaction(context.event) as transaction:
|
||||
transaction.add("test", "key1", "value1")
|
||||
@@ -153,7 +153,7 @@ class TestDictionaryCache(BaseTest):
|
||||
|
||||
assert cache.copy() == {'key1': 'value1', 'key2': 'value2'}
|
||||
|
||||
def test_we_do_no_go_twice_in_repo_when_not_found(self, sdp, context):
|
||||
def test_we_do_no_go_twice_in_repo_when_not_found(self, context, sdp):
|
||||
cache = DictionaryCache(sdp=sdp).auto_configure("test")
|
||||
|
||||
assert cache.get("key") is NotFound
|
||||
@@ -163,3 +163,61 @@ class TestDictionaryCache(BaseTest):
|
||||
transaction.add("test", "key", "value")
|
||||
|
||||
assert cache.get("key") is NotFound # the key was previously requested
|
||||
|
||||
def test_i_can_add_path(self):
|
||||
cache = DictionaryCache()
|
||||
|
||||
cache.add_path(["a", "b", "c"], "c_value")
|
||||
cache.add_path(["a", "b", "d", "e"], "e_value")
|
||||
|
||||
assert cache.copy() == {'a': {'b': {'c': {"#values#": ['c_value']},
|
||||
'd': {'e': {"#values#": ['e_value']}}}}}
|
||||
assert len(cache) == 2
|
||||
|
||||
def test_i_can_get_multiple_values_in_the_same_path(self):
|
||||
cache = DictionaryCache()
|
||||
|
||||
cache.add_path(["a", "b", "c"], "value1")
|
||||
cache.add_path(["a", "b", "c"], "value2")
|
||||
cache.add_path(["a", "b", "c", "d"], "value3")
|
||||
|
||||
assert cache.copy() == {'a': {'b': {'c': {'d': {'#values#': ['value3']},
|
||||
'#values#': ["value1", "value2"]}}}}
|
||||
assert len(cache) == 3
|
||||
|
||||
def test_i_can_remove_path(self):
|
||||
cache = DictionaryCache()
|
||||
|
||||
cache.add_path(["a", "b", "c"], "value1")
|
||||
cache.add_path(["a", "b", "c"], "value2")
|
||||
|
||||
cache.remove_path(["a", "b", "c"], "value1")
|
||||
assert cache.copy() == {'a': {'b': {'c': {"#values#": ['value2']}}}}
|
||||
assert len(cache) == 1
|
||||
|
||||
cache.remove_path(["a", "b", "c"], "value2")
|
||||
assert cache.copy() == {}
|
||||
assert len(cache) == 0
|
||||
|
||||
def test_i_can_remove_when_not_exist(self):
|
||||
# remove an entry that does not exist does not cause error
|
||||
|
||||
cache = DictionaryCache()
|
||||
|
||||
cache.add_path(["a", "b", "c"], "value1")
|
||||
cache.add_path(["a", "b", "c"], "value2")
|
||||
|
||||
cache.remove_path(["a", "b", "c"], "value3")
|
||||
cache.remove_path(["a", "b"], "value1")
|
||||
|
||||
assert cache.copy() == {'a': {'b': {'c': {"#values#": ['value1', 'value2']}}}}
|
||||
assert len(cache) == 2
|
||||
|
||||
def test_i_can_get_from_path(self):
|
||||
cache = DictionaryCache()
|
||||
|
||||
cache.add_path(["a", "b", "c"], "value1")
|
||||
cache.add_path(["a", "b", "c"], "value2")
|
||||
|
||||
assert cache.get_from_path(["a", "b"]) is NotFound
|
||||
assert cache.get_from_path(["a", "b", "c"]) == ["value1", "value2"]
|
||||
|
||||
Reference in New Issue
Block a user