(ast_compile_mock, patterns_hash_mock, mock_cache)
| 275 | @mock.patch("aura.cache.ASTPatternCache.get_patterns_hash", return_value="sig1") |
| 276 | @mock.patch("aura.cache.ASTPatternCache._compile_all", return_value=[]) |
| 277 | def 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 |
nothing calls this directly
no test coverage detected