File: test_null_backend.py

package info (click to toggle)
python-dogpile.cache 1.3.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 772 kB
  • sloc: python: 5,462; makefile: 155; sh: 104
file content (76 lines) | stat: -rw-r--r-- 1,922 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import itertools

from dogpile.cache.api import NO_VALUE
from dogpile.testing import eq_
from dogpile.testing.fixtures import _GenericBackendFixture


class NullBackendTest(_GenericBackendFixture):
    backend = "dogpile.cache.null"

    def test_get(self):
        reg = self._region()

        eq_(reg.get("some key"), NO_VALUE)

    def test_set(self):
        reg = self._region()
        reg.set("some key", "some value")
        eq_(reg.get("some key"), NO_VALUE)

    def test_delete(self):
        reg = self._region()
        reg.delete("some key")
        eq_(reg.get("some key"), NO_VALUE)

    def test_get_multi(self):
        reg = self._region()

        eq_(reg.get_multi(["a", "b", "c"]), [NO_VALUE, NO_VALUE, NO_VALUE])

    def test_set_multi(self):
        reg = self._region()
        reg.set_multi({"a": 1, "b": 2, "c": 3})
        eq_(reg.get_multi(["a", "b", "c"]), [NO_VALUE, NO_VALUE, NO_VALUE])

    def test_delete_multi(self):
        reg = self._region()
        reg.delete_multi(["a", "b", "c"])
        eq_(reg.get_multi(["a", "b", "c"]), [NO_VALUE, NO_VALUE, NO_VALUE])

    def test_decorator(self):
        reg = self._region()

        counter = itertools.count(1)

        @reg.cache_on_arguments()
        def go(a, b):
            val = next(counter)
            return val, a, b

        eq_(go(1, 2), (1, 1, 2))
        eq_(go(1, 2), (2, 1, 2))
        eq_(go(1, 3), (3, 1, 3))

    def test_mutex(self):
        backend = self._backend()
        mutex = backend.get_mutex("foo")

        ac = mutex.acquire()
        assert ac
        mutex.release()

        ac2 = mutex.acquire(False)
        assert ac2
        mutex.release()

    def test_mutex_doesnt_actually_lock(self):
        backend = self._backend()
        mutex = backend.get_mutex("foo")

        ac = mutex.acquire()
        assert ac

        ac2 = mutex.acquire(False)
        assert ac2
        mutex.release()