Python functools._CacheInfo() Examples

The following are code examples for showing how to use functools._CacheInfo(). They are from open source Python projects. You can vote up the examples you like or vote down the ones you don't like.

Example 1
Project: Blockly-rduino-communication   Author: technologiescollege   File: test_functools.py    GNU General Public License v3.0 5 votes vote down vote up
def test_lru_with_maxsize_none(self):
        @functools.lru_cache(maxsize=None)
        def fib(n):
            if n < 2:
                return n
            return fib(n-1) + fib(n-2)
        self.assertEqual([fib(n) for n in range(16)],
            [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610])
        self.assertEqual(fib.cache_info(),
            functools._CacheInfo(hits=28, misses=16, maxsize=None, currsize=16))
        fib.cache_clear()
        self.assertEqual(fib.cache_info(),
            functools._CacheInfo(hits=0, misses=0, maxsize=None, currsize=0)) 
Example 2
Project: Blockly-rduino-communication   Author: technologiescollege   File: test_functools.py    GNU General Public License v3.0 5 votes vote down vote up
def test_lru_with_keyword_args(self):
        @functools.lru_cache()
        def fib(n):
            if n < 2:
                return n
            return fib(n=n-1) + fib(n=n-2)
        self.assertEqual(
            [fib(n=number) for number in range(16)],
            [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610]
        )
        self.assertEqual(fib.cache_info(),
            functools._CacheInfo(hits=28, misses=16, maxsize=128, currsize=16))
        fib.cache_clear()
        self.assertEqual(fib.cache_info(),
            functools._CacheInfo(hits=0, misses=0, maxsize=128, currsize=0)) 
Example 3
Project: Blockly-rduino-communication   Author: technologiescollege   File: test_functools.py    GNU General Public License v3.0 5 votes vote down vote up
def test_lru_with_keyword_args_maxsize_none(self):
        @functools.lru_cache(maxsize=None)
        def fib(n):
            if n < 2:
                return n
            return fib(n=n-1) + fib(n=n-2)
        self.assertEqual([fib(n=number) for number in range(16)],
            [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610])
        self.assertEqual(fib.cache_info(),
            functools._CacheInfo(hits=28, misses=16, maxsize=None, currsize=16))
        fib.cache_clear()
        self.assertEqual(fib.cache_info(),
            functools._CacheInfo(hits=0, misses=0, maxsize=None, currsize=0)) 
Example 4
Project: bitlyshortener   Author: impredicative   File: shortener.py    GNU Affero General Public License v3.0 5 votes vote down vote up
def cache_info(self) -> Dict[str, _CacheInfo]:
        source = self._long_url_to_int_id
        return {source.__qualname__: source.cache_info()}  # type: ignore 
Example 5
Project: pennylane   Author: XanaduAI   File: test_utils.py    Apache License 2.0 5 votes vote down vote up
def test_cache_usage(self, depth):
        """Test that the right number of cachings have been executed after clearing the cache"""
        pu.pauli_eigs.cache_clear()
        pu.pauli_eigs(depth)
        total_runs = sum([2**x for x in range(depth)])
        assert functools._CacheInfo(depth - 1, depth, 128, depth)== pu.pauli_eigs.cache_info()