-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_homework01.py
67 lines (48 loc) · 1.32 KB
/
test_homework01.py
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
from itertools import islice
import pytest
from homework01 import call_count, fac, fib, flatten, gcd
@pytest.mark.parametrize('a, b', [
(5, 120),
(7, 5040),
(8, 40320),
(9, 362880)
])
def test_fac(a, b):
assert fac(a) == b
@pytest.mark.parametrize('a, b, c', [
(1, 1, 1),
(2, 3, 1),
(2, 4, 2),
(3, 8, 1),
(6, 9, 3),
(54, 24, 6)
])
def test_gcd(a, b, c):
assert gcd(a, b) == c
def test_fib():
head = islice(fib(), 10)
assert list(head) == [1, 1, 2, 3, 5, 8, 13, 21, 34, 55]
@pytest.mark.parametrize('in_seq, out_seq', [
([], []),
([1, 2], [1, 2]),
([1, [2, [3]]], [1, 2, 3]),
([(1, 2), (3, 4)], [1, 2, 3, 4])
])
def test_flatten(in_seq, out_seq):
assert list(flatten(in_seq)) == list(out_seq)
def test_call_count():
@call_count
def test_fn(*args, **kwargs):
return locals()
assert test_fn.call_count == 0
args = (1, 2)
kwargs = {'a': 3}
res = test_fn(*args, **kwargs)
assert res == {'args': args, 'kwargs': kwargs},\
'Декоратор некорректно обрабатывает возвращаемое значение функции'
assert test_fn.call_count == 1
test_fn()
test_fn()
assert test_fn.call_count == 3
with pytest.raises(Exception):
test_fn.call_count = 100