MCPcopy Index your code
hub / github.com/SourceCode-AI/aura / test_ast_cache

Function test_ast_cache

tests/test_cache.py:277–302  ·  view source on GitHub ↗
(ast_compile_mock, patterns_hash_mock, mock_cache)

Source from the content-addressed store, hash-verified

275@mock.patch("aura.cache.ASTPatternCache.get_patterns_hash", return_value="sig1")
276@mock.patch("aura.cache.ASTPatternCache._compile_all", return_value=[])
277def test_ast_cache(ast_compile_mock, patterns_hash_mock, mock_cache):
278 # Reset the cache status
279 cache.ASTPatternCache._AST_PATTERN_CACHE = None
280
281 assert [] == cache.ASTPatternCache.proxy()
282 assert ast_compile_mock.called is True
283 ast_compile_mock.reset_mock()
284
285 assert [] == cache.ASTPatternCache.proxy()
286 assert ast_compile_mock.called is False
287
288 cache_items = tuple(cache.CacheItem.iter_items())
289 assert len(cache_items) == 1
290 assert cache_items[0].metadata["type"] == "ast_patterns"
291
292 # Test that cache is invalidated if config hash changes
293 patterns_hash_mock.return_value = "sig2"
294 ast_compile_mock.return_value = ["changed"]
295
296 assert ["changed"] == cache.ASTPatternCache.proxy()
297
298 # Now there will be two items, the old ast patterns and new ones
299 assert len(tuple(cache.CacheItem.iter_items())) == 2
300
301 cache.CacheItem.cleanup()
302 assert len(tuple(cache.CacheItem.iter_items())) == 0
303
304
305@responses.activate

Callers

nothing calls this directly

Calls 3

iter_itemsMethod · 0.80
proxyMethod · 0.45
cleanupMethod · 0.45

Tested by

no test coverage detected