Ejemplo n.º 1
0
    def test_07b_delete_memoized_verhash(self):
        @self.memoizer.memoize(5)
        def big_foo(a, b):
            return a+b+random.randrange(0, 100000)

        result = big_foo(5, 2)
        result2 = big_foo(5, 3)

        time.sleep(1)

        assert big_foo(5, 2) == result
        assert big_foo(5, 2) == result
        assert big_foo(5, 3) != result
        assert big_foo(5, 3) == result2

        self.memoizer.delete_memoized_verhash(big_foo)

        _fname, _fname_instance = function_namespace(big_foo)
        version_key = self.memoizer._memvname(_fname)
        assert self.memoizer.get(version_key) is None

        assert big_foo(5, 2) != result
        assert big_foo(5, 3) != result2

        assert self.memoizer.get(version_key) is not None
Ejemplo n.º 2
0
    def test_07b_delete_memoized_verhash(self):
        @self.memoizer.memoize(5)
        def big_foo(a, b):
            return a + b + random.randrange(0, 100000)

        result = big_foo(5, 2)
        result2 = big_foo(5, 3)

        assert big_foo(5, 2) == result
        assert big_foo(5, 2) == result
        assert big_foo(5, 3) != result
        assert big_foo(5, 3) == result2

        self.memoizer.delete_memoized_verhash(big_foo)

        _fname, _fname_instance = function_namespace(big_foo)
        version_key = self.memoizer._memvname(_fname)
        assert (self.memoizer.get(version_key) is
                self.memoizer.default_cache_value)

        assert big_foo(5, 2) != result
        assert big_foo(5, 3) != result2

        assert (self.memoizer.get(version_key)
                is not self.memoizer.default_cache_value)
Ejemplo n.º 3
0
    def test_26_delete_memoized_verhash_backend_error(self, memoizer_delete):
        logging.basicConfig()

        # disable logger (to avoid cluttering test output)
        logging.disable(logging.ERROR)

        memoizer = Memoizer()

        @memoizer.memoize()
        def f():
            return random.randrange(0, 100000)

        _fname, _ = function_namespace(f)
        version_key = self.memoizer._memvname(_fname)

        result = f()

        assert f() == result
        assert memoizer.get(version_key) is not memoizer.default_cache_value

        memoizer.delete_memoized_verhash(f)

        memoizer_delete.assert_called_with(version_key)

        assert f() == result
        assert memoizer.get(version_key) is not memoizer.default_cache_value

        # re-enable logger
        logging.disable(logging.NOTSET)
Ejemplo n.º 4
0
    def test_31_update_memoized_backend_error(self, memoizer_set):

        logging.basicConfig()

        # disable logger (to avoid cluttering test output)
        logging.disable(logging.ERROR)

        memoizer = Memoizer()

        @memoizer.memoize()
        def f():
            return random.randrange(0, 100000)

        old_value = self.memoizer.update_memoized(f)
        fname, instance_fname = function_namespace(f, args=[])
        version_key = self.memoizer._memvname(fname)
        version_val = self.memoizer.get(version_key)
        memoizer_set.assert_called_with(
            version_key,
            version_val,
            timeout=f.cache_timeout
        )

        memoizer_set.reset_mock()

        new_value = self.memoizer.update_memoized(f)
        memoizer_set.assert_called_with(
            version_key,
            version_val,
            timeout=f.cache_timeout
        )

        assert new_value != old_value

        # re-enable logger
        logging.disable(logging.NOTSET)