def test_inherited_cache_must_come_from_uncut_subsystem(redis_cache): s = examples.basic_subsystem() cut_s = Subsystem(s.network, s.state, s.node_indices, cut=models.Cut((0, 2), (1, ))) with pytest.raises(ValueError): cache.MICECache(s, cut_s._mice_cache)
def test_redis_cache_sharing_between_processes(s): def _set_val(s): # Generate key *in the subprocess* with the-process native hash c = cache.MICECache(s) key = c.key(Direction.CAUSE, (0, )) c.set(key, 'result') p = multiprocessing.Process(target=_set_val, args=[s]) p.start() p.join() # Check value in this process c = cache.MICECache(s) key = c.key(Direction.CAUSE, (0, )) assert c.get(key) == 'result'
def test_mice_cache_respects_cache_memory_limits(): s = examples.basic_subsystem() c = cache.MICECache(s) mice = mock.Mock(phi=1) # dummy MICE c.set(c.key(Direction.CAUSE, ()), mice) assert c.size() == 0
def test_use_dict_mice_cache(s): c = cache.MICECache(s) assert isinstance(c, cache.DictMICECache)
def _set_val(s): # Generate key *in the subprocess* with the-process native hash c = cache.MICECache(s) key = c.key(Direction.CAUSE, (0, )) c.set(key, 'result')
def test_use_redis_mice_cache(s): c = cache.MICECache(s) assert isinstance(c, cache.RedisMICECache)