Passed
Branch master (19896e)
by Guibert
53s
created

tests.test_utils_run   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 68 %

Importance

Changes 0
Metric Value
wmc 3
eloc 18
dl 17
loc 25
rs 10
c 0
b 0
f 0

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
from contextvars import ContextVar
2
3
from curio import Kernel
4
5
from async_btree import run
6
7
8
def test_run_curio(kernel):
9
    counter = ContextVar("counter", default=5)
10
11
    async def reset_counter():
12
        if counter.get() == 5:
13
            counter.set(0)
14
            return 0
15
        return -1
16
17
    with Kernel() as k:
18
        assert run(k, reset_counter) == 0
19
        assert run(k, reset_counter) == 0
20
        assert counter.get() == 5
21
22
    assert kernel.run(reset_counter) == 0
23
    assert kernel.run(reset_counter) == -1
24
    assert counter.get() == 0
25