assert_false_creator()   A
last analyzed

Complexity

Conditions 2

Size

Total Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
c 1
b 0
f 0
dl 0
loc 2
rs 10
1
import pytest
2
3
try:
4
    import django
5
except ImportError:
6
    django = None
7
else:
8
    from django.core.cache import cache
9
10
11
@pytest.mark.skipif("not django")
12
def test_django_works(redis_server):
13
    with cache.lock('whateva'):
14
        pass
15
16
17
@pytest.mark.skipif("not django")
18
def test_django_add_or_set_locked(redis_server):
19
    def creator_42():
20
        return 42
21
22
    def none_creator():
23
        return None
24
25
    def assert_false_creator():
26
        assert False
27
28
    assert cache.locked_get_or_set("foobar-aosl", creator_42) == 42
29
    assert cache.locked_get_or_set("foobar-aosl", assert_false_creator) == 42
30
31
    try:
32
        val = cache.locked_get_or_set("foobar-aosl2", none_creator)
33
    except ValueError:
34
        pass
35
    else:
36
        assert False
37
38
39
@pytest.mark.skipif("not django")
40
def test_reset_all(redis_server):
41
    lock1 = cache.lock("foobar1")
42
    lock2 = cache.lock("foobar2")
43
    lock1.acquire(blocking=False)
44
    lock2.acquire(blocking=False)
45
    cache.reset_all()
46
    lock1 = cache.lock("foobar1")
47
    lock2 = cache.lock("foobar2")
48
    lock1.acquire(blocking=False)
49
    lock2.acquire(blocking=False)
50
    lock1.release()
51
    lock2.release()
52